Skip to content

Commit 641ba1a

Browse files
committed
auto bump version
1 parent 61ff118 commit 641ba1a

File tree

1 file changed

+50
-10
lines changed

1 file changed

+50
-10
lines changed

.github/workflows/bump-version.yml

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,40 @@
1-
# .github/workflows/bump-version.yml
2-
name: Bump version
3-
4-
on:
1+
name: Auto Bump Version
2+
'on':
53
pull_request:
64
branches:
75
- main
86
- develop
97
- test_bump_version_script
108
types:
9+
- opened
10+
- synchronize
1111
- labeled
12-
12+
permissions:
13+
contents: write
14+
pull-requests: write
1315
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"
1425
version-bump:
1526
if: github.event.label.name == 'ready-to-merge'
1627
runs-on: ubuntu-latest
17-
1828
steps:
1929
- name: Checkout source branch
2030
uses: actions/checkout@v4
2131
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 }}'
2534
- name: Use Node.js version from .nvmrc
2635
uses: actions/setup-node@v4
2736
with:
2837
node-version-file: .nvmrc
29-
3038
- name: Run bump-version script
3139
run: |
3240
BASE_BRANCH="${{ github.event.pull_request.base.ref }}"
@@ -50,3 +58,35 @@ jobs:
5058
else
5159
echo "Base branch is not main/develop — skipping version bump"
5260
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

Comments
 (0)