Skip to content

Commit

Permalink
feat(misc): validate input
Browse files Browse the repository at this point in the history
  • Loading branch information
mandarini committed Mar 1, 2024
1 parent 1947dc5 commit 72e587f
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions scripts/nx-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,10 @@ function parseArgs() {
// Get the current short git sha
const gitSha = execSync('git rev-parse --short HEAD').toString().trim();

if (version.startsWith('pr-')) {
return `0.0.0-${version}-${YYYYMMDD}-${gitSha}`;
if (version.startsWith('pr-') && validFormatForPRrelease(version)) {
return `0.0.0-${validFormatForPRrelease(
version
)}-${YYYYMMDD}-${gitSha}`;
}

const currentLatestVersion = execSync('npm view nx@latest version')
Expand Down Expand Up @@ -389,3 +391,22 @@ function determineDistTag(

return distTag;
}

function validFormatForPRrelease(input: string): string | undefined {
// Check that format is pr-<number>
const regex = /^pr-(\d+)$/;
const match = input.match(regex);

if (match) {
return input;
} else {
// If the input has a # (eg. pr-#1234), remove it and try again
const fixedInput = input.replace(/#/, '');
const matchFixed = fixedInput.match(regex);
if (matchFixed) {
return fixedInput;
} else {
return undefined;
}
}
}

0 comments on commit 72e587f

Please sign in to comment.