diff --git a/scripts/bump-oss-version.js b/scripts/bump-oss-version.js index 274dacd9394b6c..a376a52036c074 100755 --- a/scripts/bump-oss-version.js +++ b/scripts/bump-oss-version.js @@ -34,6 +34,11 @@ let argv = yargs .option('v', { alias: 'to-version', type: 'string', + }) + .option('l', { + alias: 'latest', + type: 'boolean', + default: false, }).argv; const nightlyBuild = argv.nightly; @@ -212,8 +217,9 @@ if (!nightlyBuild) { let remote = argv.remote; exec(`git push ${remote} v${version}`); - // Tag latest if doing stable release - if (prerelease == null) { + // Tag latest if doing stable release. + // This will also tag npm release as `latest` + if (prerelease == null && argv.latest) { exec('git tag -d latest'); exec(`git push ${remote} :latest`); exec('git tag latest'); diff --git a/scripts/publish-npm.js b/scripts/publish-npm.js index ad11638ed3a403..bfd325d2c4bf84 100644 --- a/scripts/publish-npm.js +++ b/scripts/publish-npm.js @@ -87,9 +87,11 @@ const rawVersion = buildTag; let version, + major, + minor, prerelease = null; try { - ({version, prerelease} = parseVersion(rawVersion)); + ({version, major, minor, prerelease} = parseVersion(rawVersion)); } catch (e) { echo(e.message); exit(1); @@ -154,12 +156,24 @@ if (dryRunBuild) { exit(0); } +// Running to see if this commit has been git tagged as `latest` +const latestCommit = exec("git rev-list -n 1 'latest'", { + silent: true, +}).stdout.replace('\n', ''); +const isLatest = currentCommit === latestCommit; + +const releaseBranch = `${major}.${minor}-stable`; + // Set the right tag for nightly and prerelease builds +// If a release is not git-tagged as `latest` we use `releaseBranch` to prevent +// npm from overriding the current `latest` version tag, which it will do if no tag is set. const tagFlag = nightlyBuild ? '--tag nightly' : prerelease != null ? '--tag next' - : ''; + : isLatest + ? '--tag latest' + : `--tag ${releaseBranch}`; // use otp from envvars if available const otpFlag = otp ? `--otp ${otp}` : '';