Skip to content

Commit fe2b165

Browse files
committed
fix(sync-from-node): use branch name instead of unreleased version from staging
Staging branches bump node_version.h ahead of actual releases, so parsing it produced bogus versions like v25.8.2 (not yet released). Now uses the branch name (e.g. v25.x-staging) for non-release refs and skips README version rewrite for staging syncs.
1 parent 5442738 commit fe2b165

1 file changed

Lines changed: 35 additions & 19 deletions

File tree

scripts/sync-from-node.ts

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -346,24 +346,34 @@ async function main() {
346346
nodeCommitSha = commitData.sha; // Full SHA for file fetching
347347
}
348348

349-
// Get Node.js version from src/node_version.h using the commit SHA for consistency
350-
const versionRef = nodeCommitSha || args.branch;
351-
const versionUrl = `https://raw.githubusercontent.com/${args.repo}/${versionRef}/src/node_version.h`;
352-
const versionResponse = await fetch(versionUrl);
353-
if (versionResponse.ok) {
354-
const versionContent = await versionResponse.text();
355-
const majorMatch = versionContent.match(
356-
/#define NODE_MAJOR_VERSION (\d+)/,
357-
);
358-
const minorMatch = versionContent.match(
359-
/#define NODE_MINOR_VERSION (\d+)/,
360-
);
361-
const patchMatch = versionContent.match(
362-
/#define NODE_PATCH_VERSION (\d+)/,
363-
);
349+
// Only parse node_version.h for release tags (e.g., v25.8.1), not staging
350+
// branches — staging branches have version numbers bumped ahead of the
351+
// actual release, so the parsed version would be misleading.
352+
const isReleaseTag = /^v\d+\.\d+\.\d+$/.test(args.branch);
364353

365-
if (majorMatch && minorMatch && patchMatch) {
366-
nodeVersion = `v${majorMatch[1]}.${minorMatch[1]}.${patchMatch[1]}`;
354+
if (isReleaseTag) {
355+
nodeVersion = args.branch;
356+
} else {
357+
const versionRef = nodeCommitSha || args.branch;
358+
const versionUrl = `https://raw.githubusercontent.com/${args.repo}/${versionRef}/src/node_version.h`;
359+
const versionResponse = await fetch(versionUrl);
360+
if (versionResponse.ok) {
361+
const versionContent = await versionResponse.text();
362+
const majorMatch = versionContent.match(
363+
/#define NODE_MAJOR_VERSION (\d+)/,
364+
);
365+
const minorMatch = versionContent.match(
366+
/#define NODE_MINOR_VERSION (\d+)/,
367+
);
368+
const patchMatch = versionContent.match(
369+
/#define NODE_PATCH_VERSION (\d+)/,
370+
);
371+
372+
if (majorMatch && minorMatch && patchMatch) {
373+
// Use the branch name, not the (potentially unreleased) version
374+
// from the header. The commit SHA suffix provides traceability.
375+
nodeVersion = args.branch;
376+
}
367377
}
368378
}
369379
} catch (err: any) {
@@ -439,8 +449,10 @@ async function main() {
439449

440450
// Note: SQLite version update removed since we sync SQLite files from SQLite.org, not Node.js
441451

442-
// Update README.md with the Node.js version
443-
if (nodeVersion) {
452+
// Update README.md with the Node.js version (only for release tags,
453+
// not staging branches where the version would be misleading)
454+
const isReleaseTag = /^v\d+\.\d+\.\d+$/.test(nodeVersion || "");
455+
if (nodeVersion && isReleaseTag) {
444456
try {
445457
const readmePath = path.join(packageRoot, "README.md");
446458
let readme = fs.readFileSync(readmePath, "utf8");
@@ -459,6 +471,10 @@ async function main() {
459471
} catch (err: any) {
460472
console.error("Failed to update README.md:", err.message);
461473
}
474+
} else if (nodeVersion) {
475+
console.log(
476+
`Skipping README.md version update (synced from ${nodeVersion}, not a release tag)`,
477+
);
462478
}
463479

464480
// Update sync cache with the current SHA

0 commit comments

Comments
 (0)