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
7 changes: 4 additions & 3 deletions .github/workflows/bump-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ jobs:
run: pnpm install --frozen-lockfile

- name: Bump version
run: pnpm run bump-version
id: bump
run: pnpm run bump-version >> "$GITHUB_OUTPUT"

- name: Create PR
uses: peter-evans/create-pull-request@v7
with:
commit-message: 'chore: bump version'
title: '[CI] Bump version'
commit-message: 'chore: bump version ${{ steps.bump.outputs.new_version }}'
title: '[CI] Bump version ${{ steps.bump.outputs.new_version }}'
body: Automated changes for bumping version
branch: chore/ci-bump-version
branch-suffix: timestamp
19 changes: 15 additions & 4 deletions scripts/bump-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function getWorkspacePackageJsonFiles(workspaceFile: string): string[] {
cwd: rootDir,
absolute: true,
});
matches.forEach((f) => files.add(f));
matches.filter((f) => !f.includes('node_modules')).forEach((f) => files.add(f));
}
return Array.from(files);
}
Expand All @@ -28,16 +28,27 @@ function incrementVersion(version: string): string {
return parts.join('.');
}

// find all package.json files in the workspace
const workspaceFile = path.resolve(__dirname, '../pnpm-workspace.yaml');
const packageFiles = getWorkspacePackageJsonFiles(workspaceFile);

// get version from root package.json
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);

for (const file of packageFiles) {
const content = fs.readFileSync(file, 'utf8');
const pkg = JSON.parse(content) as { version?: string };
if (pkg.version) {
const oldVersion = pkg.version;
pkg.version = incrementVersion(pkg.version);
fs.writeFileSync(file, JSON.stringify(pkg, null, 2) + '\n');
console.log(`Updated ${file}: ${oldVersion} -> ${pkg.version}`);
const newVersion = incrementVersion(pkg.version);
// do a string replace from oldVersion to newVersion
const newContent = content.replace(`"version": "${oldVersion}"`, `"version": "${newVersion}"`);
fs.writeFileSync(file, newContent);
}
}

console.log(`new_version=${newVersion}`);