[Main] Add automated ability to reset the npm latest tag to a specific build (#2127)

- Related to #2126
This commit is contained in:
Nev 2023-08-10 16:52:47 -07:00 коммит произвёл GitHub
Родитель f45ad22208
Коммит 0e06711932
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 120 добавлений и 3 удалений

Просмотреть файл

@ -29,7 +29,8 @@
"ai-min": "node common/scripts/install-run-rush.js ai-min",
"ai-restore": "node common/scripts/install-run-rush.js ai-restore",
"npm-pack": "node common/scripts/install-run-rush.js npm-pack --verbose",
"npm-publish": "node ./tools/release-tools/npm_publish.js"
"npm-publish": "node ./tools/release-tools/npm_publish.js",
"npm-set-latest": "node ./tools/release-tools/npm_set_latest.js"
},
"repository": {
"type": "git",

Просмотреть файл

@ -106,7 +106,7 @@ if (parseArgs()) {
throw new Error("!!! NPM Package not found [" + npmPackageName + "]");
}
console.log(`npm pacakage present ${npmPackageName}`);
console.log(`npm package present ${npmPackageName}`);
let npmCmd = `npm publish ${npmPackageName} --access public ${dryRun}`;
console.log(`Running: \"${npmCmd}\"`);
child_process.execSync(npmCmd);

Просмотреть файл

@ -0,0 +1,107 @@
const fs = require("fs");
const child_process = require("child_process");
const packageGroupDef = "./tools/release-tools/package_groups.json";
let packageGroup;
let isTest = false;
function showHelp() {
var scriptParts;
var scriptName = process.argv[1];
if (scriptName.indexOf("\\") !== -1) {
scriptParts = scriptName.split("\\");
scriptName = scriptParts[scriptParts.length - 1];
} else if (scriptName.indexOf("/") !== -1) {
scriptParts = scriptName.split("/");
scriptName = scriptParts[scriptParts.length - 1];
}
console.log("");
console.log(scriptName + " <group> ");
console.log("--------------------------");
console.log(" <group> - Identifies the group to publish, identifies folders");
}
function parseArgs() {
if (process.argv.length < 2) {
console.error("!!! Invalid number of arguments -- " + process.argv.length);
return false;
}
let idx = 2;
while (idx < process.argv.length) {
let theArg = process.argv[idx];
if (theArg.startsWith("-")) {
if (theArg === "-test") {
isTest = true;
} else {
console.error("!!! Unknown switch [" + theArg + "] detected");
return false;
}
} else if (!packageGroup) {
packageGroup = theArg;
} else {
console.error("!!! Invalid Argument [" + theArg + "] detected");
return false;
}
idx++;
}
return true;
}
function removeTrailingComma(text) {
return text.replace(/,(\s*[}\],])/g, "$1");
}
function removeComments(text) {
return text.replace(/^\s*\/\/\s.*$/gm, "");
}
function getPackageJson(packageJsonFile) {
var packageText = removeTrailingComma(fs.readFileSync(packageJsonFile, "utf-8"));
return JSON.parse(packageText);
}
function getGroupProjects() {
if (!fs.existsSync(packageGroupDef)) {
console.error("!!! Unable to locate package group definitions [" + packageGroupDef + "]");
throw new Error("!!! Unable to locate package group definitions.");
}
var groupText = removeComments(removeTrailingComma(fs.readFileSync(packageGroupDef, "utf-8")));
let groupJson = JSON.parse(groupText);
return groupJson[packageGroup] || [];
}
if (parseArgs()) {
var packages = getGroupProjects();
console.log(`Set latest tag [${packageGroup}] packages => ${packages.length}`);
packages.forEach((packageRoot) => {
let packageJsonFile = packageRoot + "/package.json";
if (!fs.existsSync(packageJsonFile)) {
console.error("!!! Source package.json doesn't exist [" + packageJsonFile + "]");
throw new Error("!!! Source package.json doesn't exist [" + packageJsonFile + "]");
}
let packageJson = getPackageJson(packageJsonFile);
console.log("\n\n##################################################################");
console.log("Setting latest tag - " + packageJson.name);
console.log("##################################################################");
let npmCmd = `npm dist-tag add ${packageJson.name}@${packageJson.version} latest`;
console.log(`Running: \"${npmCmd}\"`);
if (!isTest) {
child_process.execSync(npmCmd);
}
});
} else {
showHelp();
process.exit(1);
}

Просмотреть файл

@ -393,6 +393,7 @@ function shouldProcess(name) {
function updatePublishConfig(package, newVersion) {
let details = getVersionDetails(newVersion);
let majorVersion = package.version.split(".")[0];
if (!details.type || details.type === "release") {
if (package.publishConfig && package.publishConfig.tag) {
@ -405,9 +406,17 @@ function updatePublishConfig(package, newVersion) {
}
// Set the publishing tag
if (details.type === "nightly" || details.type === "dev" || details.type === "beta" || details.type === "alpha") {
console.log(` Type - [${details.type}] - ${majorVersion}`);
package.publishConfig.tag = details.type + (majorVersion !== "0" ? majorVersion : "");
} else {
console.log(` Type - [${details.type}]`);
package.publishConfig.tag = details.type;
}
console.log(` Tag - [${package.publishConfig.tag}]`);
}
if (package.publishConfig && Object.keys(package.publishConfig).length === 0) {
// Nothing left so remove it
delete package.publishConfig;