Skip to content

Commit

Permalink
fix(): generate changelog before publish
Browse files Browse the repository at this point in the history
  • Loading branch information
newtonnthiga committed Oct 15, 2024
1 parent 0b27fbb commit d93bcf8
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 59 deletions.
59 changes: 0 additions & 59 deletions .github/workflows/changelog.yml

This file was deleted.

51 changes: 51 additions & 0 deletions .github/workflows/npm_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,57 @@ on:
- "v*" # Triggers when a tag starting with 'v' is pushed

jobs:
changelog:
runs-on: ubuntu-latest

steps:
# Step 1: Checkout the repository with full history
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Ensure full commit history is fetched, including tags

# Step 2: Find the branch associated with the commit
- name: Determine the branch
id: extract_branch
run: |
# Try to find the branch based on commit history
BRANCH=$(git for-each-ref --format='%(refname:short)' $(git rev-parse --verify HEAD) | grep 'heads/' | head -n 1 | sed 's|heads/||')
echo "Branch: $BRANCH"
if [ -z "$BRANCH" ]; then
echo "No branch found, defaulting to 'main'"
BRANCH="main" # Fallback to 'main' if no branch is found
fi
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
# Step 3: Set up Node.js environment to install conventional-changelog
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"

# Step 4: Install conventional-changelog-cli
- name: Install conventional-changelog-cli
run: |
npm install -g conventional-changelog-cli
# Step 5: Generate changelog
- name: Generate changelog
run: |
conventional-changelog -p angular -i CHANGELOG.md -s -r 0
# Step 6: Commit and push the changelog to the determined branch
- name: Commit and push changelog
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add CHANGELOG.md
git commit -m "chore: update changelog for ${GITHUB_REF#refs/tags/}"
# Push to the determined branch
git push origin HEAD:${{ steps.extract_branch.outputs.branch }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish:
runs-on: ubuntu-latest

Expand Down
1 change: 1 addition & 0 deletions build_npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ await build({
postBuild() {
Deno.copyFileSync("LICENSE", "npm/LICENSE");
Deno.copyFileSync("README.md", "npm/README.md");
Deno.copyFileSync("CHANGELOG.md", "npm/CHANGELOG.md");
},
});

0 comments on commit d93bcf8

Please sign in to comment.