From 0347c78b64c352bae9838b483fcd0dfbf2643504 Mon Sep 17 00:00:00 2001 From: Omni Date: Wed, 6 May 2026 02:00:20 +0000 Subject: [PATCH] Allow exact release version override --- .github/workflows/release.yml | 15 ++++++++-- scripts/bump-version.js | 56 ++++++++++++++++++++++++++++++----- 2 files changed, 62 insertions(+), 9 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5163ba7..f6f0a7c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,6 +12,10 @@ on: - patch - minor - major + target_version: + description: 'Optional exact version override (for example, 1.2.1). If set, version_type is ignored.' + required: false + type: string jobs: release: @@ -36,8 +40,15 @@ jobs: - name: Bump version id: bump + env: + VERSION_TYPE: ${{ github.event.inputs.version_type }} + TARGET_VERSION: ${{ github.event.inputs.target_version }} run: | - node scripts/bump-version.js ${{ github.event.inputs.version_type }} > bump_output.txt + if [ -n "$TARGET_VERSION" ]; then + node scripts/bump-version.js "$TARGET_VERSION" > bump_output.txt + else + node scripts/bump-version.js "$VERSION_TYPE" > bump_output.txt + fi cat bump_output.txt NEW_VERSION=$(grep "NEW_VERSION=" bump_output.txt | cut -d'=' -f2) OLD_VERSION=$(grep "OLD_VERSION=" bump_output.txt | cut -d'=' -f2) @@ -67,7 +78,7 @@ jobs: run: | git config --local user.email "github-actions[bot]@users.noreply.github.com" git config --local user.name "github-actions[bot]" - git add manifest.template.json package.json + git add manifest.template.json package.json package-lock.json git commit -m "chore: release version ${{ steps.bump.outputs.new_version }}" git tag -a "v${{ steps.bump.outputs.new_version }}" -m "Release version ${{ steps.bump.outputs.new_version }}" git push origin main diff --git a/scripts/bump-version.js b/scripts/bump-version.js index 0062460..9c1aefe 100644 --- a/scripts/bump-version.js +++ b/scripts/bump-version.js @@ -8,11 +8,15 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); const rootDir = join(__dirname, '..'); -// Get version type from command line args (patch, minor, major) -const versionType = process.argv[2] || 'patch'; +// Get version type or exact target version from command line args. +// Supported values: patch, minor, major, or an exact Chrome extension version +// such as 1.2.1. +const versionInput = process.argv[2] || 'patch'; -if (!['patch', 'minor', 'major'].includes(versionType)) { - console.error('Usage: node bump-version.js [patch|minor|major]'); +const VERSION_PATTERN = /^\d+\.\d+\.\d+$/; + +if (!['patch', 'minor', 'major'].includes(versionInput) && !VERSION_PATTERN.test(versionInput)) { + console.error('Usage: node bump-version.js [patch|minor|major|x.y.z]'); process.exit(1); } @@ -37,19 +41,57 @@ function bumpVersion(version, type) { return parts.join('.'); } +function compareVersions(a, b) { + const aParts = a.split('.').map(Number); + const bParts = b.split('.').map(Number); + + for (let i = 0; i < 3; i++) { + if (aParts[i] !== bParts[i]) { + return aParts[i] - bParts[i]; + } + } + + return 0; +} + +function writeJson(path, data) { + writeFileSync(path, JSON.stringify(data, null, 2) + '\n'); +} + // Update manifest.template.json const manifestPath = join(rootDir, 'manifest.template.json'); const manifest = JSON.parse(readFileSync(manifestPath, 'utf-8')); const oldVersion = manifest.version; -const newVersion = bumpVersion(oldVersion, versionType); +const newVersion = VERSION_PATTERN.test(versionInput) ? versionInput : bumpVersion(oldVersion, versionInput); + +if (compareVersions(newVersion, oldVersion) <= 0) { + console.error(`Error: new version (${newVersion}) must be greater than current version (${oldVersion})`); + process.exit(1); +} + manifest.version = newVersion; -writeFileSync(manifestPath, JSON.stringify(manifest, null, 2) + '\n'); +writeJson(manifestPath, manifest); // Update package.json const packagePath = join(rootDir, 'package.json'); const packageJson = JSON.parse(readFileSync(packagePath, 'utf-8')); packageJson.version = newVersion; -writeFileSync(packagePath, JSON.stringify(packageJson, null, 2) + '\n'); +writeJson(packagePath, packageJson); + +// Update package-lock.json if present so release commits keep npm metadata in sync. +const packageLockPath = join(rootDir, 'package-lock.json'); +try { + const packageLockJson = JSON.parse(readFileSync(packageLockPath, 'utf-8')); + packageLockJson.version = newVersion; + if (packageLockJson.packages?.['']) { + packageLockJson.packages[''].version = newVersion; + } + writeJson(packageLockPath, packageLockJson); +} catch (error) { + if (error.code !== 'ENOENT') { + throw error; + } +} console.log(`Version bumped from ${oldVersion} to ${newVersion}`); console.log(`NEW_VERSION=${newVersion}`);