diff --git a/packages/atomic-angular/projects/atomic-angular/project.json b/packages/atomic-angular/projects/atomic-angular/project.json index 4dc3e293a1c..cb7e638b35e 100644 --- a/packages/atomic-angular/projects/atomic-angular/project.json +++ b/packages/atomic-angular/projects/atomic-angular/project.json @@ -9,7 +9,7 @@ "outputs": [], "executor": "nx:run-commands", "options": { - "command": "node ../../../../scripts/deploy/update-npm-tag.mjs v2-latest", + "command": "npm run-script -w=@coveo/release promote-npm-prod", "cwd": "packages/atomic-angular/projects/atomic-angular" } } diff --git a/packages/atomic-hosted-page/package.json b/packages/atomic-hosted-page/package.json index 6ad4353f2e9..35a282020fd 100644 --- a/packages/atomic-hosted-page/package.json +++ b/packages/atomic-hosted-page/package.json @@ -27,7 +27,7 @@ "validate:definitions": "tsc --noEmit --esModuleInterop --skipLibCheck ./dist/types/components.d.ts", "publish:npm": "npm run-script -w=@coveo/release npm-publish", "publish:bump": "npm run-script -w=@coveo/release bump", - "promote:npm:latest": "node ../../scripts/deploy/update-npm-tag.mjs v2-latest" + "promote:npm:latest": "npm run-script -w=@coveo/release promote-npm-prod" }, "dependencies": { "@coveo/bueno": "0.46.3", diff --git a/packages/atomic-react/package.json b/packages/atomic-react/package.json index 13d1d80131a..93b7eee9fbd 100644 --- a/packages/atomic-react/package.json +++ b/packages/atomic-react/package.json @@ -17,7 +17,7 @@ "build:bundles": "concurrently \"npm run build:bundles:esm\" \"npm run build:bundles:cjs\" \"npm run build:bundles:iife\"", "publish:npm": "npm run-script -w=@coveo/release npm-publish", "publish:bump": "npm run-script -w=@coveo/release bump", - "promote:npm:latest": "node ../../scripts/deploy/update-npm-tag.mjs v2-latest", + "promote:npm:latest": "npm run-script -w=@coveo/release promote-npm-prod", "build:assets": "ncp ../atomic/dist/atomic/assets dist/assets && ncp ../atomic/dist/atomic/lang dist/lang " }, "main": "./dist/cjs/index.js", diff --git a/packages/atomic/package.json b/packages/atomic/package.json index 98931f0b9fa..14ebb1c5e5c 100644 --- a/packages/atomic/package.json +++ b/packages/atomic/package.json @@ -43,7 +43,7 @@ "e2e:insight:watch": "cypress open --config-file cypress-insight-panel.config.ts --browser chrome", "publish:npm": "npm run-script -w=@coveo/release npm-publish", "publish:bump": "npm run-script -w=@coveo/release bump", - "promote:npm:latest": "node ../../scripts/deploy/update-npm-tag.mjs v2-latest", + "promote:npm:latest": "npm run-script -w=@coveo/release promote-npm-prod", "validate:definitions": "tsc --noEmit --esModuleInterop --skipLibCheck ./dist/types/components.d.ts" }, "dependencies": { diff --git a/packages/bueno/package.json b/packages/bueno/package.json index 2c3a1243891..6714ba6ad7a 100644 --- a/packages/bueno/package.json +++ b/packages/bueno/package.json @@ -27,7 +27,7 @@ "test:watch": "jest --watch --colors --no-cache", "publish:npm": "npm run-script -w=@coveo/release npm-publish", "publish:bump": "npm run-script -w=@coveo/release bump", - "promote:npm:latest": "node ../../scripts/deploy/update-npm-tag.mjs v2-latest" + "promote:npm:latest": "npm run-script -w=@coveo/release promote-npm-prod" }, "devDependencies": { "@coveo/release": "1.0.0", diff --git a/packages/headless-react/package.json b/packages/headless-react/package.json index 9106f5c47e8..79a17f6b1e8 100644 --- a/packages/headless-react/package.json +++ b/packages/headless-react/package.json @@ -30,7 +30,7 @@ "lint": "eslint .; publint", "publish:npm": "npm run-script -w=@coveo/release npm-publish", "publish:bump": "npm run-script -w=@coveo/release bump", - "promote:npm:latest": "node ../../scripts/deploy/update-npm-tag.mjs v2-latest" + "promote:npm:latest": "npm run-script -w=@coveo/release promote-npm-prod" }, "dependencies": { "@coveo/headless": "2.80.3" diff --git a/packages/headless/package.json b/packages/headless/package.json index c18193a8ba2..cabffddab17 100644 --- a/packages/headless/package.json +++ b/packages/headless/package.json @@ -39,7 +39,7 @@ "test:integration": "jest --testPathPattern=src/integration-tests", "publish:npm": "npm run-script -w=@coveo/release npm-publish", "publish:bump": "npm run-script -w=@coveo/release bump", - "promote:npm:latest": "node ../../scripts/deploy/update-npm-tag.mjs v2-latest", + "promote:npm:latest": "npm run-script -w=@coveo/release promote-npm-prod", "build:doc": "npm run build:doc:extract && npm run build:doc:parse", "build:doc:extract": "node ./scripts/extract-documentation.mjs", "build:doc:parse": "ts-node --project ./doc-parser/tsconfig.build.json ./doc-parser/doc-parser.ts" diff --git a/packages/quantic/package.json b/packages/quantic/package.json index 277e260c40d..9351064cb33 100644 --- a/packages/quantic/package.json +++ b/packages/quantic/package.json @@ -40,7 +40,7 @@ "promote:sfdx:ci": "npm run publish:sfdx -- --promote --ci", "publish:npm": "npm run-script -w=@coveo/release npm-publish", "publish:bump": "npm run-script -w=@coveo/release bump", - "promote:npm:latest": "node ../../scripts/deploy/update-npm-tag.mjs v2-latest", + "promote:npm:latest": "npm run-script -w=@coveo/release promote-npm-prod", "preinstall": "node scripts/npm/check-sfdx-project.js", "postinstall": "node scripts/npm/setup-quantic.js" }, diff --git a/scripts/deploy/update-npm-tag.mjs b/scripts/deploy/update-npm-tag.mjs deleted file mode 100644 index 50738107cd8..00000000000 --- a/scripts/deploy/update-npm-tag.mjs +++ /dev/null @@ -1,49 +0,0 @@ -import {execute} from '../exec.mjs'; -import {getPackageManifestFromPackagePath} from '../packages.mjs'; - -const pkg = getPackageManifestFromPackagePath(process.cwd()); - -async function updateNpmTag(packageName, version) { - const tag = process.argv[2]; - const latestVersion = await getLatestVersion(packageName); - - if (!isGreaterThanLatestVersion(version, latestVersion)) { - console.log( - `skipping tag update for ${packageName} because version "${version}" is not greater than latest version "${latestVersion}".` - ); - return; - } - - console.log(`updating ${packageName}@${version} to ${tag}.`); - await execute('npm', ['dist-tag', 'add', `${packageName}@${version}`, tag]); -} - -async function getLatestVersion(packageName) { - const res = await execute('npm', ['view', packageName, 'version']); - return res.trim(); -} - -function isGreaterThanLatestVersion(version, latestVersion) { - const candidate = parseVersion(version); - const latest = parseVersion(latestVersion); - - return isCandidateGreaterThanLatestVersion(candidate, latest, 0); -} - -function parseVersion(version) { - return version.split('.').map((num) => parseInt(num, 10)); -} - -function isCandidateGreaterThanLatestVersion(candidate, latest, i) { - if (i >= candidate.length) { - return false; - } - - if (candidate[i] === latest[i]) { - return isCandidateGreaterThanLatestVersion(candidate, latest, i + 1); - } - - return candidate[i] > latest[i]; -} - -updateNpmTag(pkg.name, pkg.version); diff --git a/utils/release/common/constants.mjs b/utils/release/common/constants.mjs index 7757693463e..66a334baf66 100644 --- a/utils/release/common/constants.mjs +++ b/utils/release/common/constants.mjs @@ -21,5 +21,6 @@ export const RELEASER_AUTH_SECRETS = { installationId: process.env.RELEASER_INSTALLATION_ID, }; +export const NPM_LATEST_TAG = 'v2-latest'; export const NPM_BETA_TAG = 'v2-beta'; export const NPM_ALPHA_TAG = 'v2-alpha'; diff --git a/utils/release/package.json b/utils/release/package.json index 6ce5cb75b02..2ff3e68154e 100644 --- a/utils/release/package.json +++ b/utils/release/package.json @@ -22,6 +22,7 @@ "typescript": "5.4.5" }, "scripts": { + "promote-npm-prod": "./promote-npm-tag-to-latest.mjs", "git-lock": "./git-lock.mjs", "bump": "./bump-package.mjs", "npm-publish": "./npm-publish-package.mjs", diff --git a/utils/release/promote-npm-tag-to-latest.mjs b/utils/release/promote-npm-tag-to-latest.mjs new file mode 100755 index 00000000000..3e33bfa26d8 --- /dev/null +++ b/utils/release/promote-npm-tag-to-latest.mjs @@ -0,0 +1,25 @@ +#!/usr/bin/env node +import {describeNpmTag, npmSetTag} from '@coveo/semantic-monorepo-tools'; +import {readFileSync} from 'node:fs'; +import {gt} from 'semver'; +import {NPM_LATEST_TAG} from './common/constants.mjs'; + +if (!process.env.INIT_CWD) { + throw new Error('Should be called using npm run-script'); +} +process.chdir(process.env.INIT_CWD); + +const {name, version} = JSON.parse( + readFileSync('package.json', {encoding: 'utf-8'}) +); + +const publishedVersion = await describeNpmTag(name, NPM_LATEST_TAG); + +if (gt(publishedVersion, version)) { + console.log( + `skipping tag update for ${name} because version "${version}" is not greater than latest version "${publishedVersion}".` + ); + process.exit(1); +} + +await npmSetTag(name, version, NPM_LATEST_TAG);