fix(ci): prevent bad NPM releases and promote job crashes (#28147)

This commit is contained in:
Gal Zahavi
2026-06-25 11:22:56 -07:00
committed by GitHub
parent d845bc5d45
commit 3fbf93e26f
5 changed files with 65 additions and 19 deletions
+28 -3
View File
@@ -159,12 +159,37 @@ function detectRollbackAndGetBaseline({ args, npmDistTag } = {}) {
// Sort by semver to get a list from highest to lowest
matchingVersions.sort((a, b) => semver.rcompare(a, b));
// Find the highest non-deprecated version
// Find the highest non-deprecated version with a git tag
let highestExistingVersion = '';
for (const version of matchingVersions) {
if (!isVersionDeprecated({ version, args })) {
highestExistingVersion = version;
break; // Found the one we want
try {
// Only consider versions that have a corresponding git tag.
// This prevents picking up versions that were published to NPM but failed before the github release/tag.
let tagExists = false;
try {
execSync(`git rev-parse v${version}^{commit} 2>/dev/null`);
tagExists = true;
} catch {
const remoteTag = execSync(
`git ls-remote --tags origin refs/tags/v${version} 2>/dev/null`,
)
.toString()
.trim();
if (remoteTag) {
tagExists = true;
}
}
if (!tagExists) {
throw new Error(`Tag v${version} not found`);
}
highestExistingVersion = version;
break; // Found the one we want
} catch {
console.error(
`Ignoring version ${version} because it lacks a git tag (likely a failed release).`,
);
}
} else {
console.error(`Ignoring deprecated version: ${version}`);
}