Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.

Commit 67bb5ab

Browse files
ymc9claude
andauthored
feat: split bump-version into bump-patch and bump-minor commands (#538)
- Updated GitHub Actions workflow to accept version_type input (patch/minor) - Modified bump-version.ts script to support both patch and minor version increments - Patch: increments patch version (e.g., 3.0.5 → 3.0.6) - Minor: increments minor version and resets patch to 0 (e.g., 3.0.5 → 3.1.0) - Replaced single bump-version command with two separate commands: - bump-patch: triggers workflow with version_type=patch - bump-minor: triggers workflow with version_type=minor 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent b83ed8d commit 67bb5ab

3 files changed

Lines changed: 31 additions & 9 deletions

File tree

.github/workflows/bump-version.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ name: Bump Version
22

33
on:
44
workflow_dispatch:
5+
inputs:
6+
version_type:
7+
description: 'Version type to bump'
8+
required: true
9+
type: choice
10+
options:
11+
- patch
12+
- minor
513

614
permissions:
715
contents: write
@@ -34,7 +42,7 @@ jobs:
3442

3543
- name: Bump version
3644
id: bump
37-
run: npx tsx scripts/bump-version.ts
45+
run: npx tsx scripts/bump-version.ts ${{ inputs.version_type }}
3846

3947
- name: Create PR
4048
uses: peter-evans/create-pull-request@v7

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
1717
"pr": "gh pr create --fill-first --base dev",
1818
"merge-main": "gh pr create --title \"merge dev to main\" --body \"\" --base main --head dev",
19-
"bump-version": "gh workflow run .github/workflows/bump-version.yml --ref dev",
19+
"bump-patch": "gh workflow run .github/workflows/bump-version.yml --ref dev -f version_type=patch",
20+
"bump-minor": "gh workflow run .github/workflows/bump-version.yml --ref dev -f version_type=minor",
2021
"publish-all": "pnpm --filter \"./packages/**\" -r publish --access public",
2122
"publish-preview": "pnpm --filter \"./packages/**\" -r publish --force --registry https://preview.registry.zenstack.dev/",
2223
"unpublish-preview": "pnpm --filter \"./packages/**\" -r --shell-mode exec -- npm unpublish -f --registry https://preview.registry.zenstack.dev/ \"\\$PNPM_PACKAGE_NAME\""

scripts/bump-version.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,26 @@ function getWorkspacePackageJsonFiles(workspaceFile: string): string[] {
3232
return result;
3333
}
3434

35-
function incrementVersion(version: string): string {
35+
function incrementVersion(version: string, type: 'patch' | 'minor' = 'patch'): string {
3636
const parts = version.split('.');
37-
const last = parts.length - 1;
38-
const lastNum = parseInt(parts[last], 10);
39-
if (isNaN(lastNum)) throw new Error(`Invalid version: ${version}`);
40-
parts[last] = (lastNum + 1).toString();
41-
return parts.join('.');
37+
if (parts.length !== 3) throw new Error(`Invalid version format: ${version}`);
38+
39+
const [major, minor, patch] = parts.map(p => parseInt(p, 10));
40+
if (isNaN(major) || isNaN(minor) || isNaN(patch)) {
41+
throw new Error(`Invalid version: ${version}`);
42+
}
43+
44+
if (type === 'minor') {
45+
return `${major}.${minor + 1}.0`;
46+
} else {
47+
return `${major}.${minor}.${patch + 1}`;
48+
}
49+
}
50+
51+
// get version type from command line argument
52+
const versionType = process.argv[2] as 'patch' | 'minor' | undefined;
53+
if (versionType && versionType !== 'patch' && versionType !== 'minor') {
54+
throw new Error(`Invalid version type: ${versionType}. Expected 'patch' or 'minor'.`);
4255
}
4356

4457
// find all package.json files in the workspace
@@ -50,7 +63,7 @@ const rootPackageJson = path.resolve(_dirname, '../package.json');
5063
const rootPkg = JSON.parse(fs.readFileSync(rootPackageJson, 'utf8')) as { version?: string };
5164
if (!rootPkg.version) throw new Error('No "version" key found in package.json');
5265
const rootVersion = rootPkg.version;
53-
const newVersion = incrementVersion(rootVersion);
66+
const newVersion = incrementVersion(rootVersion, versionType || 'patch');
5467

5568
for (const file of packageFiles) {
5669
const content = fs.readFileSync(file, 'utf8');

0 commit comments

Comments
 (0)