Skip to content

Commit bd5a6b5

Browse files
tool: add release-bot.yml (#355)
tool: add release-bot.yml chore: bump version to 0.0.4-beta.2 chore: bump version to 0.0.4-beta.2 chore: bump version to 0.0.4-beta.2
1 parent 3295bb4 commit bd5a6b5

File tree

12 files changed

+89
-16
lines changed

12 files changed

+89
-16
lines changed

.github/build_plan.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
matrix_file=./.github/build_matrix.json
44

5-
should_publish=$([ $IS_NEW_RELEASE = true ])
5+
should_publish=false
6+
if [ $IS_NEW_RELEASE = true ]; then
7+
should_publish=true
8+
fi
69

710
if [ $IS_MERGED_PR = true ] && [ $IS_BETA_BRANCH = true ]; then
811
should_publish=true

.github/workflows/build.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ on:
1313
release:
1414
types: [released, prereleased]
1515

16+
concurrency:
17+
group: ${{ github.workflow }}-${{ github.ref }}
18+
cancel-in-progress: true
19+
1620
env:
1721
# Planning Inputs
1822
IS_RELEASE_BRANCH: ${{ contains(github.ref, 'heads/release') }}

.github/workflows/release-bot.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Release Bot
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, closed]
6+
branches: [main, stable]
7+
release:
8+
types: [released, prereleased]
9+
10+
jobs:
11+
sync-version:
12+
if: startsWith(github.head_ref, 'releases/')
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: pnpm/action-setup@v4
17+
with:
18+
version: 7.32.4
19+
20+
- name: Sync Version
21+
run: |
22+
pnpm install --dir cli
23+
./run sync-version --commit-and-push
24+
25+
run-publish-action:
26+
if: startsWith(github.head_ref, 'releases/') || github.event_name == 'release'
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: statsig-io/statsig-publish-sdk-action@main
30+
with:
31+
kong-private-key: ${{ secrets.KONG_GH_APP_PRIVATE_KEY }}

cli/src/commands/bump-version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class BumpVersion extends CommandBase {
7777

7878
printConclusion('Succesfully Bumped Root Version');
7979

80-
SyncVersion.sync();
80+
await SyncVersion.sync();
8181

8282
Log.title('Commit and Push Changes');
8383

cli/src/commands/sync-version.ts

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { BASE_DIR, getRootedPath } from '@/utils/file_utils.js';
2-
import { Log, printTitle } from '@/utils/teminal_utils.js';
2+
import { commitAndPushChanges } from '@/utils/git_utils.js';
3+
import { SemVer } from '@/utils/semver.js';
4+
import { Log } from '@/utils/teminal_utils.js';
35
import { getRootVersion } from '@/utils/toml_utils.js';
46
import chalk from 'chalk';
57
import { execSync } from 'child_process';
@@ -13,29 +15,37 @@ export class SyncVersion extends CommandBase {
1315
super(import.meta.url);
1416

1517
this.description('Sync the version across all relevant files');
18+
19+
this.option('--commit-and-push', 'Commit and push the changes', false);
1620
}
1721

18-
override async run() {
19-
SyncVersion.sync();
22+
override async run(options: { commitAndPush: boolean }) {
23+
SyncVersion.sync(options);
2024
}
2125

22-
static sync() {
26+
static async sync(options?: { commitAndPush: boolean }) {
2327
Log.title('Syncing Version');
2428

2529
Log.stepBegin('Getting root version');
26-
const version = getRootVersion().toString();
27-
Log.stepEnd(`Root Version: ${version}`);
28-
29-
updateStatsigMetadataVersion(version);
30-
updateNodePackageJsonVersions(version);
31-
updateJavaGradleVersion(version);
32-
updateStatsigGrpcDepVersion(version);
33-
updatePhpComposerVersion(version);
30+
const version = getRootVersion();
31+
const versionString = version.toString();
32+
Log.stepEnd(`Root Version: ${versionString}`);
33+
34+
updateStatsigMetadataVersion(versionString);
35+
updateNodePackageJsonVersions(versionString);
36+
updateJavaGradleVersion(versionString);
37+
updateStatsigGrpcDepVersion(versionString);
38+
updatePhpComposerVersion(versionString);
39+
3440
Log.stepBegin('Verifying Cargo Change');
3541
execSync('cargo check', { cwd: BASE_DIR });
3642
Log.stepEnd('Cargo Change Verified');
3743

38-
Log.conclusion(`All Versions Updated to: ${version}`);
44+
if (options?.commitAndPush) {
45+
await tryCommitAndPushChanges(version);
46+
}
47+
48+
Log.conclusion(`All Versions Updated to: ${versionString}`);
3949
}
4050
}
4151

@@ -136,3 +146,26 @@ function updatePhpComposerVersion(version: string) {
136146

137147
Log.stepEnd(`Updated Version: ${chalk.strikethrough(was)} -> ${version}`);
138148
}
149+
150+
async function tryCommitAndPushChanges(version: SemVer) {
151+
Log.stepBegin('Commit and Push Changes');
152+
153+
const { success, error } = await commitAndPushChanges(
154+
'.',
155+
`chore: bump version to ${version.toString()}`,
156+
'origin',
157+
'main',
158+
version.toBranch(),
159+
true /* shouldPushChanges */,
160+
);
161+
162+
if (success) {
163+
Log.stepEnd('Successfully Committed and Pushed');
164+
} else if (error instanceof Error && error.name === 'NoChangesError') {
165+
Log.stepEnd('No Changes to Commit');
166+
} else {
167+
Log.stepEnd(`Failed to Commit and Push Changes`, 'failure');
168+
169+
throw error;
170+
}
171+
}

cli/src/utils/git_utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ export async function commitAndPushChanges(
7070

7171
const status = await git.status();
7272
if (!status.isClean()) {
73-
throw new Error('There are unstaged changes');
73+
const noChangeError = new Error('There are unstaged changes');
74+
noChangeError.name = 'NoChangesError';
75+
throw noChangeError;
7476
}
7577

7678
if (shouldPushChanges) {

0 commit comments

Comments
 (0)