diff --git a/.github/workflows/bump-version.yml b/.github/workflows/bump-version.yml index 9decd064..88b371c1 100644 --- a/.github/workflows/bump-version.yml +++ b/.github/workflows/bump-version.yml @@ -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 diff --git a/scripts/bump-version.ts b/scripts/bump-version.ts index 717072e9..6538df32 100644 --- a/scripts/bump-version.ts +++ b/scripts/bump-version.ts @@ -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); } @@ -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}`);