Release Process #23
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
| name: Release Process | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| type: | |
| type: choice | |
| description: Choose release type | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| default: patch | |
| beta: | |
| type: boolean | |
| description: Prerelease | |
| default: false | |
| pull_request: | |
| types: [closed] | |
| branches: | |
| - main | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| issues: write | |
| jobs: | |
| # This job prepares a release PR | |
| prepare-release: | |
| if: github.event_name == 'workflow_dispatch' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: git config | |
| run: | | |
| git config user.name "${GITHUB_ACTOR}" | |
| git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" | |
| - name: Setup node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: npm | |
| - run: npm ci | |
| # Prepare the version change but don't push anything yet | |
| - name: Prepare release changes | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| TYPE_ARG: ${{ inputs.type }} | |
| BETA_ARG: ${{ inputs.beta == true && '--preRelease=beta' || '' }} | |
| run: | | |
| # Only prepare the version changes without git operations | |
| npm run release -- $TYPE_ARG --ci --verbose --no-git.push --no-git.commit --no-git.tag --no-github --no-npm $BETA_ARG | |
| # Get the version that was set | |
| - name: Get version | |
| id: package-version | |
| uses: martinbeentjes/npm-get-version-action@main | |
| # Create a branch with the changes and push it | |
| - name: Create and push branch | |
| run: | | |
| # Get the new version that was prepared but not committed | |
| NEW_VERSION=$(node -p "require('./package.json').version") | |
| echo "New version is: $NEW_VERSION" | |
| # Create a new branch using the NEW_VERSION, not steps.package-version.outputs.current-version | |
| BRANCH_NAME="release-v$NEW_VERSION" | |
| git checkout -b $BRANCH_NAME | |
| # Add the changes | |
| git add . | |
| git commit -m "chore(release): prepare release v$NEW_VERSION" | |
| git push origin $BRANCH_NAME | |
| # Output the PR creation URL to the logs | |
| echo "::notice::✅ Branch created and pushed: $BRANCH_NAME" | |
| echo "::notice::⚠️ You must manually create a PR from this branch at this URL:" | |
| echo "::notice::➡️ https://github.com/${{ github.repository }}/compare/main...$BRANCH_NAME?expand=1" | |
| echo "::notice::📝 Important: Add the 'release' label to your PR for the release workflow to run when merged" | |
| # Also output to step summary for better visibility | |
| echo "# Release Branch Created" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "The release branch has been created and pushed as: \`$BRANCH_NAME\`" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### Next Steps" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "1. [Create a pull request](https://github.com/${{ github.repository }}/compare/main...$BRANCH_NAME?expand=1) from this branch" >> $GITHUB_STEP_SUMMARY | |
| echo "2. Add the 'release' label to your PR" >> $GITHUB_STEP_SUMMARY | |
| echo "3. Get the PR reviewed and merged" >> $GITHUB_STEP_SUMMARY | |
| echo "4. Once merged, the release will automatically be published" >> $GITHUB_STEP_SUMMARY | |
| # This job performs the actual release after a PR has been merged | |
| publish-release: | |
| if: github.event_name == 'pull_request' && github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'release') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: git config | |
| run: | | |
| git config user.name "${GITHUB_ACTOR}" | |
| git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" | |
| - name: Setup node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: npm | |
| registry-url: 'https://registry.npmjs.org' | |
| - run: npm ci | |
| # Create the tag and GitHub release | |
| - name: Create GitHub release tag | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| # Create a tag for the version | |
| VERSION=$(node -p "require('./package.json').version") | |
| git tag -a "v$VERSION" -m "Release v$VERSION" | |
| git push origin "v$VERSION" | |
| # Extract changelog entries for this version | |
| CHANGELOG_ENTRY=$(awk "/## \\[$VERSION\\]/,/## \\[/ { if (!/## \\[$VERSION\\]/ && /## \\[/) exit; print }" CHANGELOG.md) | |
| # Create GitHub release | |
| gh release create "v$VERSION" --title "v$VERSION" --notes "$CHANGELOG_ENTRY" | |
| # Publish to npm | |
| - name: Publish to npm | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| run: | | |
| # Publish the package to npm | |
| npm publish --access public |