From 71ad41b4fcd9603619632cb8f23395a8a9298049 Mon Sep 17 00:00:00 2001 From: Azgaar Date: Sat, 7 Mar 2026 16:59:08 +0100 Subject: [PATCH] chore: enhance version bump process with base version check --- .github/workflows/bump-version.yml | 12 ++++++++++- scripts/bump-version.js | 32 +++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/.github/workflows/bump-version.yml b/.github/workflows/bump-version.yml index de50d24c..8d5c8508 100644 --- a/.github/workflows/bump-version.yml +++ b/.github/workflows/bump-version.yml @@ -42,8 +42,18 @@ jobs: echo "type=patch" >> "$GITHUB_OUTPUT" fi + - name: Extract base version (master before this PR merged) + id: base + run: | + BASE=$(git show HEAD~1:public/versioning.js \ + | grep -oP 'const VERSION = "\K[\d.]+') + echo "version=$BASE" >> "$GITHUB_OUTPUT" + echo "Base version on master before merge: $BASE" + - name: Run version bump script - run: node scripts/bump-version.js ${{ steps.bump.outputs.type }} + run: | + node scripts/bump-version.js ${{ steps.bump.outputs.type }} \ + --base-version ${{ steps.base.outputs.version }} - name: Commit and push bump run: | diff --git a/scripts/bump-version.js b/scripts/bump-version.js index af4c35a3..e9859e82 100644 --- a/scripts/bump-version.js +++ b/scripts/bump-version.js @@ -61,6 +61,17 @@ function escapeRegExp(str) { return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); } +/** Returns true if versionA is strictly greater than versionB (semver). */ +function isVersionGreater(versionA, versionB) { + const a = versionA.split(".").map(Number); + const b = versionB.split(".").map(Number); + for (let i = 0; i < 3; i++) { + if (a[i] > b[i]) return true; + if (a[i] < b[i]) return false; + } + return false; // equal +} + /** * Returns public/*.js paths (relative to repo root) that have changed. * Checks (in order, deduplicating): @@ -180,13 +191,32 @@ function promptBumpType(currentVersion) { // --------------------------------------------------------------------------- async function main() { - const args = process.argv.slice(2).map(a => a.toLowerCase()); + const argv = process.argv.slice(2); + const args = argv.map(a => a.toLowerCase()); const dry = args.includes("--dry-run"); + // --base-version X.Y.Z — version on master before this PR was merged. + // When provided, the script checks whether the developer already bumped + // the version manually in their branch. If so, the increment is skipped + // and only the ?v= hashes in index.html are refreshed. + const baseVersionFlagIdx = argv.findIndex(a => a === "--base-version"); + const baseVersion = baseVersionFlagIdx !== -1 ? argv[baseVersionFlagIdx + 1] : null; + if (dry) console.log("\n[bump-version] DRY RUN — no files will be changed\n"); const currentVersion = parseCurrentVersion(); + if (baseVersion && isVersionGreater(currentVersion, baseVersion)) { + // Developer already bumped the version manually in their branch. + console.log( + `\n[bump-version] Version already updated manually: ${baseVersion} → ${currentVersion} (base was ${baseVersion})\n` + ); + console.log(" Skipping version increment — updating ?v= hashes only.\n"); + updateIndexHtmlHashes(currentVersion, dry); + console.log(`\n[bump-version] ${dry ? "(dry run) " : ""}done.\n`); + return; + } + // Determine bump type: CLI arg → stdin prompt → default patch let bumpType; if (args.includes("major")) bumpType = "major";