|
1 |
| -# .github/workflows/bump-version.yml |
2 |
| -name: Bump version |
3 |
| - |
4 |
| -on: |
| 1 | +name: Auto Bump Version |
| 2 | +'on': |
5 | 3 | pull_request:
|
6 | 4 | branches:
|
7 | 5 | - main
|
8 | 6 | - develop
|
9 | 7 | - test_bump_version_script
|
10 | 8 | types:
|
| 9 | + - opened |
| 10 | + - synchronize |
11 | 11 | - labeled
|
12 |
| - |
| 12 | +permissions: |
| 13 | + contents: write |
| 14 | + pull-requests: write |
13 | 15 | jobs:
|
| 16 | + pr-helper: |
| 17 | + if: github.event.action == 'opened' || github.event.action == 'synchronize' |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - name: Comment instructions for merging |
| 21 | + uses: actions/github-script@v7 |
| 22 | + with: |
| 23 | + github-token: '${{ secrets.GITHUB_TOKEN }}' |
| 24 | + script: "const message = `\n\U0001F44B Hi @${{ github.event.pull_request.user.login }}!\n\n To finalize this PR, please add the \\`ready-to-merge\\` label.\n\n This will trigger an automatic version bump and merge the PR \U0001F680.`;\n\ngithub.rest.issues.createComment({\n issue_number: context.issue.number,\n owner: context.repo.owner,\n repo: context.repo.repo,\n body: message\n});\n" |
14 | 25 | version-bump:
|
15 | 26 | if: github.event.label.name == 'ready-to-merge'
|
16 | 27 | runs-on: ubuntu-latest
|
17 |
| - |
18 | 28 | steps:
|
19 | 29 | - name: Checkout source branch
|
20 | 30 | uses: actions/checkout@v4
|
21 | 31 | with:
|
22 |
| - ref: ${{ github.event.pull_request.head.ref }} |
23 |
| - token: ${{ secrets.GITHUB_TOKEN }} |
24 |
| - |
| 32 | + ref: '${{ github.event.pull_request.head.ref }}' |
| 33 | + token: '${{ secrets.GITHUB_TOKEN }}' |
25 | 34 | - name: Use Node.js version from .nvmrc
|
26 | 35 | uses: actions/setup-node@v4
|
27 | 36 | with:
|
28 | 37 | node-version-file: .nvmrc
|
29 |
| - |
30 | 38 | - name: Run bump-version script
|
31 | 39 | run: |
|
32 | 40 | BASE_BRANCH="${{ github.event.pull_request.base.ref }}"
|
|
50 | 58 | else
|
51 | 59 | echo "Base branch is not main/develop — skipping version bump"
|
52 | 60 | fi
|
| 61 | + - name: Remove 'ready-to-merge' label |
| 62 | + uses: actions-ecosystem/action-remove-labels@v1 |
| 63 | + with: |
| 64 | + github_token: '${{ secrets.GITHUB_TOKEN }}' |
| 65 | + labels: ready-to-merge |
| 66 | + - name: Merge the pull request |
| 67 | + uses: actions/github-script@v7 |
| 68 | + with: |
| 69 | + github-token: '${{ secrets.GITHUB_TOKEN }}' |
| 70 | + script: | |
| 71 | + const pr = await github.rest.pulls.get({ |
| 72 | + owner: context.repo.owner, |
| 73 | + repo: context.repo.repo, |
| 74 | + pull_number: context.issue.number, |
| 75 | + }); |
| 76 | +
|
| 77 | + const mergeable = pr.data.mergeable; |
| 78 | + const mergeable_state = pr.data.mergeable_state; |
| 79 | +
|
| 80 | + if (mergeable && mergeable_state === "clean") { |
| 81 | + await github.rest.pulls.merge({ |
| 82 | + owner: context.repo.owner, |
| 83 | + repo: context.repo.repo, |
| 84 | + pull_number: context.issue.number, |
| 85 | + merge_method: "merge", // safest GitHub default |
| 86 | + commit_title: pr.data.title, |
| 87 | + commit_message: pr.data.body || "", // optional, follows GitHub UI behavior |
| 88 | + sha: pr.data.head.sha |
| 89 | + }); |
| 90 | + } else { |
| 91 | + core.setFailed(`PR is not in a mergeable state: ${mergeable_state}`); |
| 92 | + } |
0 commit comments