chore(release): script to align workspace on new semconv package version (#4937)

This commit is contained in:
Trent Mick 2024-08-21 10:44:06 -07:00 committed by GitHub
parent f2a6bcc204
commit 7aff06d793
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 798 additions and 983 deletions

1687
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -43,8 +43,8 @@
"prepare_release:sdk:patch": "npm run _check:no_changes && npm run _backup:package-json && npm run _lerna:remove_api && npm run _lerna:remove_semconv && npm run _lerna:version_patch && npm run _restore:package-json && npm run _changelog:prepare_experimental && npm run _changelog:prepare_stable",
"prepare_release:sdk:minor": "npm run _check:no_changes && npm run _backup:package-json && npm run _lerna:remove_api && npm run _lerna:remove_semconv && npm run _lerna:version_minor && npm run _restore:package-json && npm run _changelog:prepare_experimental && npm run _changelog:prepare_stable",
"comment_prepare_4": "echo semconv preparation scripts only prepare semconv package",
"prepare_release:semconv:patch": "npm run _check:no_changes && npm run _backup:package-json && npm run _lerna:remove_everything_except_semconv && npm run _lerna:version_patch && npm run _restore:package-json && npm run _changelog:prepare_semconv",
"prepare_release:semconv:minor": "npm run _check:no_changes && npm run _backup:package-json && npm run _lerna:remove_everything_except_semconv && npm run _lerna:version_minor && npm run _restore:package-json && npm run _changelog:prepare_semconv",
"prepare_release:semconv:patch": "npm run _check:no_changes && npm run _backup:package-json && npm run _lerna:remove_everything_except_semconv && npm run _lerna:version_patch && npm run _restore:package-json && node ./scripts/align-semconv-deps.js && npm run _changelog:prepare_semconv",
"prepare_release:semconv:minor": "npm run _check:no_changes && npm run _backup:package-json && npm run _lerna:remove_everything_except_semconv && npm run _lerna:version_minor && npm run _restore:package-json && node ./scripts/align-semconv-deps.js && npm run _changelog:prepare_semconv",
"prepare_release:all:minor": "npm run _check:no_changes && npm run _backup:package-json && npm run _lerna:remove_api && npm run _lerna:remove_semconv && npm run _lerna:version_minor && cd api/ && npm version minor && cd .. && lerna run align-api-deps && npm run _restore:package-json && npm run _changelog:prepare_all",
"release:publish": "lerna publish --concurrency 1 from-package --no-push --no-private --no-git-tag-version --no-verify-access",
"comment_internal": "echo scripts below this line are for internal use",
@ -98,6 +98,7 @@
"eslint-plugin-node": "11.1.0",
"eslint-plugin-prettier": "5.0.1",
"gh-pages": "6.0.0",
"glob": "^10.4.5",
"karma": "6.4.4",
"karma-chrome-launcher": "3.1.0",
"karma-coverage": "2.2.1",

89
scripts/align-semconv-deps.js Executable file
View File

@ -0,0 +1,89 @@
#!/usr/bin/env node
/**
* This updates the `@opentelemetry/semantic-conventions` dep (or devDep)
* in every "package.json" in the workspace to match the version in
* "<root>/semantic-conventions/package.json"
*
* This should be run from the repository root.
*/
const fs = require('fs');
const path = require('path');
const globSync = require('glob').sync;
const {spawnSync} = require('child_process');
const TOP = path.resolve(__dirname, '..');
function getAllWorkspaceDirs() {
const pj = JSON.parse(
fs.readFileSync(path.join(TOP, 'package.json'), 'utf8')
);
return pj.workspaces
.map((wsGlob) => globSync(path.join(wsGlob, 'package.json')))
.flat()
.map(path.dirname);
}
function alignSemconvDeps({dryRun}){
const semconvVer = JSON.parse(fs.readFileSync(path.join(TOP, 'semantic-conventions', 'package.json'))).version;
const wsDirs = getAllWorkspaceDirs();
// Find all workspaces that have a dep or devDep on semconv that needs updating.
const targetWsDirs = wsDirs
.filter(wsDir => {
const pj = JSON.parse(fs.readFileSync(path.join(wsDir, 'package.json')));
const depRange = pj.dependencies && pj.dependencies['@opentelemetry/semantic-conventions'];
const devDepRange = pj.devDependencies && pj.devDependencies['@opentelemetry/semantic-conventions'];
if (depRange && devDepRange) {
throw new Error(`why does "${wsDir}/package.json" have a dep *and* devDep on the semconv package?`);
} else if (!depRange && !devDepRange) {
return false;
} else {
const currDepRange = depRange || devDepRange;
if (currDepRange === semconvVer) {
return false;
}
return true;
}
});
if (targetWsDirs.length === 0) {
console.log(`All workspace packages are already aligned to @opentelemetry/semantic-conventions@${semconvVer}.`);
return;
}
// Do the updates.
console.log(`Updating semconv dep in ${targetWsDirs.length} workspace dirs:`);
targetWsDirs.forEach(wsDir => {
const argv = ['npm', 'install', '--save-exact', '@opentelemetry/semantic-conventions@' + semconvVer];
console.log(` $ cd ${wsDir} && ${argv.join(' ')}`);
if (!dryRun) {
// For a reason I don't understand, this npm install needs to be run
// **twice**. The first time partially updates the package-lock. The
// second time updates the local package.json and fully updates the
// package-lock. See notes about "twice" at https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1917#issue-2109198809
// for somethign similar.
for (let i = 0; i < 2; i++) {
const p = spawnSync(argv[0], argv.slice(1), {
cwd: wsDir,
encoding: 'utf8',
});
if (p.error) {
throw p.error;
} else if (p.status !== 0) {
const err = Error(`'npm install' failed (status=${p.status})`);
err.cwd = wsDir;
err.argv = argv;
err.process = p;
throw err;
}
}
}
});
}
function main() {
alignSemconvDeps({dryRun: false});
}
main();