chore: add changelog template and update changelog generation in auto… #11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # .github/workflows/auto-release.yml | |
| name: Auto Release | |
| on: | |
| push: | |
| branches: [main] | |
| permissions: | |
| contents: write | |
| packages: write | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v2 | |
| with: | |
| version: 9 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "18" | |
| cache: "pnpm" | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Run tests | |
| run: pnpm test | |
| - name: Run linter | |
| run: pnpm run lint || echo "No lint script" | |
| - name: Build package | |
| run: pnpm run build | |
| - name: Check package | |
| run: pnpm pack && rm -f *.tgz | |
| auto-release: | |
| needs: test | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| fetch-depth: 0 | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v2 | |
| with: | |
| version: 9 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "18" | |
| registry-url: "https://registry.npmjs.org" | |
| cache: "pnpm" | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Build package | |
| run: pnpm run build | |
| - name: Configure Git | |
| run: | | |
| git config --local user.email "action@github.com" | |
| git config --local user.name "GitHub Action" | |
| - name: Check if release is needed | |
| id: check_release | |
| run: | | |
| # Get the version from the merged package.json | |
| CURRENT_VERSION=$(node -p "require('./package.json').version") | |
| echo "Version in package.json is $CURRENT_VERSION" | |
| # Check if a git tag for this version already exists | |
| if git rev-parse "v$CURRENT_VERSION" >/dev/null 2>&1; then | |
| echo "Tag v$CURRENT_VERSION already exists. Skipping release." | |
| echo "skip=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "Tag v$CURRENT_VERSION does not exist. Proceeding with release." | |
| echo "skip=false" >> $GITHUB_OUTPUT | |
| echo "VERSION=$CURRENT_VERSION" >> $GITHUB_ENV | |
| fi | |
| - name: Create and push tag | |
| if: steps.check_release.outputs.skip == 'false' | |
| run: | | |
| git tag v${{ env.VERSION }} | |
| git push origin v${{ env.VERSION }} | |
| echo "Created and pushed tag v${{ env.VERSION }}" | |
| - name: Generate changelog and update file | |
| if: steps.check_release.outputs.skip == 'false' | |
| run: | | |
| # Install changelog generator | |
| npm install -g auto-changelog | |
| # Generate changelog content using the custom template | |
| auto-changelog --stdout --commit-limit false -u --template ".github/changelog-template.hbs" --starting-version ${{ env.VERSION }} --issue-url "https://github.com/canadianeagle/vite-plugin-component-debugger/issues/{id}" > new-changelog-entry.md | |
| # Prepare the new changelog entry | |
| # The output from auto-changelog includes the version header, so we can use it directly | |
| # Read the existing changelog | |
| EXISTING_CHANGELOG=$(cat changelog.md) | |
| # Create the new changelog content | |
| # The header is already in new-changelog-entry.md | |
| # We need to remove the old header from the existing changelog | |
| # This is a simple way to do it, might need adjustment based on your changelog format | |
| UPDATED_CHANGELOG=$(echo -e "$(cat new-changelog-entry.md)\n\n$(echo "$EXISTING_CHANGELOG" | sed '1,7d')") | |
| # Write the updated changelog | |
| echo "$UPDATED_CHANGELOG" > changelog.md | |
| # Also create release notes for the GitHub Release | |
| cp changelog.md release-notes.md | |
| # Commit the updated changelog | |
| git add changelog.md | |
| git commit -m "chore: update changelog for v${{ env.VERSION }} [skip ci]" | |
| git push origin main | |
| - name: Create GitHub Release | |
| if: steps.check_release.outputs.skip == 'false' | |
| id: create_release | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: v${{ env.VERSION }} | |
| release_name: v${{ env.VERSION }} | |
| body_path: release-notes.md | |
| draft: false | |
| prerelease: false | |
| - name: Publish to NPM | |
| if: steps.check_release.outputs.skip == 'false' | |
| run: pnpm publish --access public --no-git-checks | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Success notification | |
| if: steps.check_release.outputs.skip == 'false' | |
| run: | | |
| echo "🎉 Successfully released v${{ env.VERSION }}" | |
| echo "📦 NPM: https://www.npmjs.com/package/vite-plugin-component-debugger" | |
| echo "🏷️ GitHub: ${{ steps.create_release.outputs.html_url }}" |