chore: enhance version bump process with base version check

This commit is contained in:
Azgaar 2026-03-07 16:59:08 +01:00
parent 274e992799
commit 71ad41b4fc
2 changed files with 42 additions and 2 deletions

View file

@ -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: |

View file

@ -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";