Skip to content

Commit 3e84cfb

Browse files
committed
ci: add bump_version bot
1 parent fcb3e17 commit 3e84cfb

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// import { URL } from "url";
2+
// import { readFileSync, writeFileSync } from "fs";
3+
4+
// const versionFilePath = new URL(
5+
// "../../common/version/version.go",
6+
// import.meta.url
7+
// ).pathname;
8+
9+
// const versionFileContent = readFileSync(versionFilePath, { encoding: "utf-8" });
10+
11+
// const currentVersion = versionFileContent.match(
12+
// /var tag = "(?<version>v(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+))"/
13+
// );
14+
15+
// try {
16+
// parseInt(currentVersion.groups.major);
17+
// parseInt(currentVersion.groups.minor);
18+
// parseInt(currentVersion.groups.patch);
19+
// } catch (err) {
20+
// console.error(new Error("Failed to parse version in version.go file"));
21+
// throw err;
22+
// }
23+
24+
// // prettier-ignore
25+
// const newVersion = `v${currentVersion.groups.major}.${currentVersion.groups.minor}.${parseInt(currentVersion.groups.patch) + 1}`;
26+
27+
// console.log(
28+
// `Bump version from ${currentVersion.groups.version} to ${newVersion}`
29+
// );
30+
31+
// writeFileSync(
32+
// versionFilePath,
33+
// versionFileContent.replace(
34+
// `var tag = "${currentVersion.groups.version}"`,
35+
// `var tag = "${newVersion}"`
36+
// )
37+
// );

.github/workflows/bump_version.yml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Bump version
2+
3+
on:
4+
pull_request:
5+
branches: [ develop ]
6+
types:
7+
- opened
8+
- reopened
9+
- synchronize
10+
- ready_for_review
11+
- labeled
12+
13+
jobs:
14+
try-to-bump:
15+
if: contains(github.event.pull_request.labels.*.name, 'bump-version')
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v3
20+
with:
21+
ref: ${{ github.head_ref }}
22+
- name: check diff
23+
id: check_diff
24+
run: |
25+
set -euo pipefail
26+
27+
# fetch develop branch so that we can diff against later
28+
git fetch origin develop
29+
30+
echo 'checking verion changes in diff...'
31+
32+
# check if version changed in version.go
33+
# note: the grep will fail if use \d instead of [0-9]
34+
git diff HEAD..origin/develop --text --no-ext-diff --unified=0 --no-prefix params/version.go | grep -E '^\+VersionPatch = "v[0-9]+"$' && true
35+
36+
exit_code=$?
37+
38+
# auto bump if version is not bumped manually
39+
echo '> require auto version bump?'
40+
41+
if [ $exit_code -eq 0 ]; then
42+
echo '> no, already bumped'
43+
echo "result=no-bump" >> "$GITHUB_OUTPUT"
44+
else
45+
echo '> yes'
46+
echo "result=bump" >> "$GITHUB_OUTPUT"
47+
fi
48+
- name: Install Node.js 16
49+
if: steps.check_diff.outputs.result == 'bump'
50+
uses: actions/setup-node@v3
51+
with:
52+
node-version: 16
53+
- name: bump version in params/version.go
54+
if: steps.check_diff.outputs.result == 'bump'
55+
run: node .github/scripts/bump_version_dot_go.mjs
56+
57+
# Commits made by this Action do not trigger new Workflow runs
58+
- uses: stefanzweifel/git-auto-commit-action@3ea6ae190baf489ba007f7c92608f33ce20ef04a
59+
if: steps.check_diff.outputs.result == 'bump'
60+
with:
61+
skip_fetch: true # already did fetch in check diff
62+
file_pattern: "params/version.go"
63+
commit_message: "chore: auto version bump [bot]"

0 commit comments

Comments
 (0)