Skip to content

Commit

Permalink
chore(release): fix tagging behavior for prod (#4257)
Browse files Browse the repository at this point in the history
this commit fixes a regression introduced in #4235.
the commit made the assumption that the npm tag will always be present: d19538e#diff-a8c342d5def4847ce523d42113bc62856f35e802a444ec746839c39018f62017L180-R229.
when in fact that is not the case. an npm tag is assumed to be the
'latest' when it is empty. with this commit, the precedence of npm tags
is updated to prefer specified tags, a valid npm tag, then null
(previously a valid npm tag, a specified tag, then 'UNKNOWN') was
preferred). this allows for a specified tag to continue to take priority
over a 'latest' tag, while reintroducing 'null' for the latest tag.
  • Loading branch information
rwaskiewicz authored Apr 14, 2023
1 parent 4e588c9 commit 6c5c984
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
8 changes: 4 additions & 4 deletions scripts/release-prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export async function promptRelease(opts: BuildOptions): Promise<NormalizedRelea
name: 'confirm',
message: (answers: any) => {
const tagToUse = determineAnsweredTagToUse(answers);
const tagPart = ` and tag this release in npm as ${color.yellow(tagToUse)}`;
const tagPart = tagToUse ? ` and tag this release in npm as ${color.yellow(tagToUse)}` : '';
return `Will publish ${opts.vermoji} ${color.yellow(opts.version)}${tagPart}. Continue?`;
},
},
Expand Down Expand Up @@ -144,8 +144,8 @@ export async function promptRelease(opts: BuildOptions): Promise<NormalizedRelea
* answers is to be used.
*
* @param answers user provided answers to pick from
* @returns the tag to use. defaults to 'UNKNOWN' if the tag cannot be determined.
* @returns the tag to use. defaults to `null` if no tag was specified
*/
export function determineAnsweredTagToUse(answers: ReleasePromptAnswers): string {
return answers.tag ? answers.tag : answers.specifiedTag ? answers.specifiedTag : 'UNKNOWN';
export function determineAnsweredTagToUse(answers: ReleasePromptAnswers): string | null {
return answers.specifiedTag || answers.tag || null;
}
12 changes: 7 additions & 5 deletions scripts/test/release-prompts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import { determineAnsweredTagToUse, ReleasePromptAnswers } from '../release-prom

describe('determineAnsweredTagToUse', () => {
it.each<[ReleasePromptAnswers, string]>([
[{ tag: '1.0.0', specifiedTag: '2.0.0', confirm: true, otp: '' }, '1.0.0'],
[{ tag: '1.0.0', specifiedTag: '2.0.0', confirm: true, otp: '' }, '2.0.0'],
[{ tag: '1.0.0', confirm: true, otp: '' }, '1.0.0'],
[{ specifiedTag: '2.0.0', confirm: true, otp: '' }, '2.0.0'],
[{ tag: '', specifiedTag: '', confirm: true, otp: '' }, 'UNKNOWN'],
[{ tag: '', confirm: true, otp: '' }, 'UNKNOWN'],
[{ specifiedTag: '', confirm: true, otp: '' }, 'UNKNOWN'],
[{ confirm: true, otp: '' }, 'UNKNOWN'],
[{ tag: undefined, specifiedTag: '2.0.0', confirm: true, otp: '' }, '2.0.0'],
[{ tag: null, specifiedTag: '2.0.0', confirm: true, otp: '' }, '2.0.0'],
[{ tag: '', specifiedTag: '', confirm: true, otp: '' }, null],
[{ tag: '', confirm: true, otp: '' }, null],
[{ specifiedTag: '', confirm: true, otp: '' }, null],
[{ confirm: true, otp: '' }, null],
])('%s returns "%s"', (answers, expected) => {
expect(determineAnsweredTagToUse(answers)).toBe(expected);
});
Expand Down

0 comments on commit 6c5c984

Please sign in to comment.