Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/workflows/bump-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ name: Bump Version

on:
workflow_dispatch:
inputs:
version_type:
description: 'Version type to bump'
required: true
type: choice
options:
- patch
- minor

permissions:
contents: write
Expand Down Expand Up @@ -34,7 +42,7 @@ jobs:

- name: Bump version
id: bump
run: npx tsx scripts/bump-version.ts
run: npx tsx scripts/bump-version.ts ${{ inputs.version_type }}

- name: Create PR
uses: peter-evans/create-pull-request@v7
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"pr": "gh pr create --fill-first --base dev",
"merge-main": "gh pr create --title \"merge dev to main\" --body \"\" --base main --head dev",
"bump-version": "gh workflow run .github/workflows/bump-version.yml --ref dev",
"bump-patch": "gh workflow run .github/workflows/bump-version.yml --ref dev -f version_type=patch",
"bump-minor": "gh workflow run .github/workflows/bump-version.yml --ref dev -f version_type=minor",
"publish-all": "pnpm --filter \"./packages/**\" -r publish --access public",
"publish-preview": "pnpm --filter \"./packages/**\" -r publish --force --registry https://preview.registry.zenstack.dev/",
"unpublish-preview": "pnpm --filter \"./packages/**\" -r --shell-mode exec -- npm unpublish -f --registry https://preview.registry.zenstack.dev/ \"\\$PNPM_PACKAGE_NAME\""
Expand Down
27 changes: 20 additions & 7 deletions scripts/bump-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,26 @@ function getWorkspacePackageJsonFiles(workspaceFile: string): string[] {
return result;
}

function incrementVersion(version: string): string {
function incrementVersion(version: string, type: 'patch' | 'minor' = 'patch'): string {
const parts = version.split('.');
const last = parts.length - 1;
const lastNum = parseInt(parts[last], 10);
if (isNaN(lastNum)) throw new Error(`Invalid version: ${version}`);
parts[last] = (lastNum + 1).toString();
return parts.join('.');
if (parts.length !== 3) throw new Error(`Invalid version format: ${version}`);

const [major, minor, patch] = parts.map(p => parseInt(p, 10));
if (isNaN(major) || isNaN(minor) || isNaN(patch)) {
throw new Error(`Invalid version: ${version}`);
}

if (type === 'minor') {
return `${major}.${minor + 1}.0`;
} else {
return `${major}.${minor}.${patch + 1}`;
}
}

// get version type from command line argument
const versionType = process.argv[2] as 'patch' | 'minor' | undefined;
if (versionType && versionType !== 'patch' && versionType !== 'minor') {
throw new Error(`Invalid version type: ${versionType}. Expected 'patch' or 'minor'.`);
}

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

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