Release step 1 - Bump version, create PR and draft release #17
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 and create PR | |
| 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 PR (${{ github.event.inputs.bump }})" | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - name: π₯ Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: π§° Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 18 | |
| - name: π’ Get current version | |
| id: get_version | |
| run: echo "version=$(node -p "require('./package.json').version")" >> "$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, run 'Release step 2' workflow to create a GitHub release." | |
| } > pr_body.txt | |
| body=$(cat pr_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 | |
| - name: π Create Pull Request | |
| uses: peter-evans/create-pull-request@v6 | |
| 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 |