Skip to content

Commit

Permalink
chore(repo): only valid latest publish when not local (#22131)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHenry committed Mar 4, 2024
1 parent 80ae397 commit 1d6e0f8
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions scripts/nx-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,6 @@ const VALID_AUTHORS_FOR_LATEST = [
});

const distTag = determineDistTag(options.version);
if (!distTag || distTag === 'latest') {
// We are only expecting latest releases to be performed within publish.yml on GitHub
const author = process.env.GITHUB_ACTOR ?? '';
if (!VALID_AUTHORS_FOR_LATEST.includes(author)) {
throw new Error(
`The GitHub user "${author}" is not allowed to publish to "latest". Please request one of the following users to carry out the release: ${VALID_AUTHORS_FOR_LATEST.join(
', '
)}`
);
}
}

if (options.dryRun) {
console.warn('Not Publishing because --dryRun was passed');
Expand Down Expand Up @@ -174,6 +163,18 @@ const VALID_AUTHORS_FOR_LATEST = [
}
}

if (!options.local && (!distTag || distTag === 'latest')) {
// We are only expecting non-local latest releases to be performed within publish.yml on GitHub
const author = process.env.GITHUB_ACTOR ?? '';
if (!VALID_AUTHORS_FOR_LATEST.includes(author)) {
throw new Error(
`The GitHub user "${author}" is not allowed to publish to "latest". Please request one of the following users to carry out the release: ${VALID_AUTHORS_FOR_LATEST.join(
', '
)}`
);
}
}

// Run with dynamic output-style so that we have more minimal logs by default but still always see errors
let publishCommand = `pnpm nx release publish --registry=${getRegistry()} --tag=${distTag} --output-style=dynamic --parallel=8`;
if (options.dryRun) {
Expand All @@ -184,17 +185,17 @@ const VALID_AUTHORS_FOR_LATEST = [
stdio: [0, 1, 2],
maxBuffer: LARGE_BUFFER,
});
}

let version;
if (['minor', 'major', 'patch'].includes(options.version)) {
version = execSync(`npm view nx@${distTag} version`).toString().trim();
} else {
version = options.version;
}
let version;
if (['minor', 'major', 'patch'].includes(options.version)) {
version = execSync(`npm view nx@${distTag} version`).toString().trim();
} else {
version = options.version;
}

console.log(chalk.green` > Published version: ` + version);
console.log(chalk.dim` Use: npx create-nx-workspace@${version}\n`);
console.log(chalk.green` > Published version: ` + version);
console.log(chalk.dim` Use: npx create-nx-workspace@${version}\n`);
}

process.exit(0);
})();
Expand Down

0 comments on commit 1d6e0f8

Please sign in to comment.