Release step 1 - Bump version, create PR and draft release #24
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 step 1 - Bump version, create PR and draft release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| bump: | |
| description: "Version bump type" | |
| required: true | |
| default: "minor" | |
| type: choice | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| jobs: | |
| create-release-pr: | |
| name: "π Create Release (${{ github.event.inputs.bump }})" | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - name: π₯ Checkout code | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: π§° Setup Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 24 | |
| - name: π’ Get current version and package info | |
| id: get_version | |
| run: | | |
| echo "version=$(node -p "require('./package.json').version")" >> "$GITHUB_OUTPUT" | |
| echo "package_name=$(node -p "require('./package.json').name")" >> "$GITHUB_OUTPUT" | |
| - name: β Calculate new version | |
| id: bump | |
| run: | | |
| current="${{ steps.get_version.outputs.version }}" | |
| bump="${{ github.event.inputs.bump }}" | |
| new=$(npx semver "$current" -i "$bump") | |
| echo "new_version=$new" >> "$GITHUB_OUTPUT" | |
| - name: π List commits since last tag | |
| id: commit_list | |
| run: | | |
| git fetch --tags | |
| last_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "") | |
| if [ -z "$last_tag" ]; then | |
| echo "No previous tags found" | |
| echo "last_tag=" >> "$GITHUB_OUTPUT" | |
| git log --pretty=format:"- %s (%h)" | head -n 20 | tee commits.txt | |
| else | |
| echo "last_tag=$last_tag" >> "$GITHUB_OUTPUT" | |
| git log "$last_tag"..HEAD --pretty=format:"- %s (%h)" | tee commits.txt | |
| fi | |
| - name: π’ Show summary in notices | |
| run: | | |
| echo "::notice title=Version::${{ steps.get_version.outputs.version }} β‘οΈ ${{ steps.bump.outputs.new_version }}" | |
| if [ -s commits.txt ]; then | |
| commits=$(head -n 10 commits.txt | tr '\n' '\r') | |
| echo "::notice title=Commits since ${{ steps.commit_list.outputs.last_tag }}::${commits}" | |
| fi | |
| - name: π§Ύ Write Markdown summary | |
| run: | | |
| { | |
| echo "## π’ Version" | |
| echo "**${{ steps.get_version.outputs.version }} β‘οΈ ${{ steps.bump.outputs.new_version }}**" | |
| echo "" | |
| echo "## π New commits" | |
| echo "" | |
| if [ -s commits.txt ]; then | |
| head -n 20 commits.txt | |
| else | |
| echo "No new commits" | |
| fi | |
| echo "" | |
| echo "## π Additional Information" | |
| echo "- Triggered by: ${{ github.actor }}" | |
| echo "- Branch: ${{ github.ref_name }}" | |
| } >> "$GITHUB_STEP_SUMMARY" | |
| - name: π Prepare PR body | |
| id: pr_body | |
| run: | | |
| { | |
| echo "## π Release v${{ steps.bump.outputs.new_version }}" | |
| echo "" | |
| echo "### Version Bump" | |
| echo "**${{ steps.get_version.outputs.version }} β‘οΈ ${{ steps.bump.outputs.new_version }}**" | |
| echo "" | |
| echo "### Commits included in this release" | |
| echo "" | |
| if [ -s commits.txt ]; then | |
| cat commits.txt | |
| else | |
| echo "No new commits" | |
| fi | |
| echo "" | |
| echo "### Additional Information" | |
| echo "- Triggered by: ${{ github.actor }}" | |
| echo "- Source branch: ${{ github.ref_name }}" | |
| echo "" | |
| echo "---" | |
| echo "" | |
| echo "**Note:** After merging this PR, publish the draft GitHub release to trigger NPM publishing." | |
| } > pr_body.txt | |
| body=$(cat pr_body.txt) | |
| echo "body<<EOF" >> $GITHUB_OUTPUT | |
| echo "$body" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: π¦ Prepare release notes | |
| id: release_notes | |
| run: | | |
| version="${{ steps.bump.outputs.new_version }}" | |
| package_name="${{ steps.get_version.outputs.package_name }}" | |
| { | |
| echo "## π¦ Release v$version" | |
| echo "" | |
| echo "This release is ready to be published to [npm](https://www.npmjs.com/package/$package_name)." | |
| echo "" | |
| echo "### π Changes in this release" | |
| echo "" | |
| if [ -s commits.txt ]; then | |
| cat commits.txt | |
| else | |
| echo "No new commits" | |
| fi | |
| echo "" | |
| echo "### π₯ Installation" | |
| echo "" | |
| echo "\`\`\`bash" | |
| echo "npm install $package_name@$version" | |
| echo "\`\`\`" | |
| echo "" | |
| echo "### π Next Steps" | |
| echo "" | |
| echo "1. Merge the release PR" | |
| echo "2. Publish this draft release to trigger NPM publishing" | |
| } > release_body.txt | |
| body=$(cat release_body.txt) | |
| echo "body<<EOF" >> $GITHUB_OUTPUT | |
| echo "$body" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: π Bump version | |
| run: npm version ${{ github.event.inputs.bump }} --no-git-tag-version | |
| - name: π§Ή Clean up temporary files | |
| run: rm -f commits.txt pr_body.txt release_body.txt | |
| - name: π Create Pull Request | |
| uses: peter-evans/create-pull-request@v8 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| commit-message: "chore: bump version to ${{ steps.bump.outputs.new_version }}" | |
| branch: release/v${{ steps.bump.outputs.new_version }} | |
| delete-branch: true | |
| title: "chore: release v${{ steps.bump.outputs.new_version }}" | |
| body: ${{ steps.pr_body.outputs.body }} | |
| base: main | |
| - name: π¦ Create draft GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ steps.bump.outputs.new_version }} | |
| name: v${{ steps.bump.outputs.new_version }} | |
| body: ${{ steps.release_notes.outputs.body }} | |
| draft: true | |
| prerelease: false | |
| target_commitish: main | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |