fix(release): allow specifier override for version command when version plans are enabled (#27436)

This commit is contained in:
Austin Fahsl 2024-08-14 14:35:23 -04:00 committed by GitHub
parent c17969665c
commit 4d2793987c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 118 additions and 9 deletions

View File

@ -139,7 +139,7 @@ Here is another line in the message.
`git commit -m "chore: add version plans for fixed and independent groups"`
);
const result = runCLI('release --verbose', {
const result = runCLI('release --verbose --skip-publish', {
silenceError: true,
});
@ -597,7 +597,7 @@ Update packages in both groups with a mix #2
// dry-run should not remove the version plan
expect(exists(join(versionPlansDir, 'bump-mixed1.md'))).toBeTruthy();
const result2 = runCLI('release --verbose', {
const result2 = runCLI('release --verbose --skip-publish', {
silenceError: true,
});
@ -767,4 +767,92 @@ Update packages in both groups with a mix #2
expect(readdirSync(versionPlansDir)).toEqual([]);
});
it('version command should bypass version plans when a specifier is passed', async () => {
updateJson<NxJsonConfiguration>('nx.json', (nxJson) => {
nxJson.release = {
groups: {
'fixed-group': {
projects: [pkg1, pkg2],
releaseTagPattern: 'v{version}',
},
'independent-group': {
projects: [pkg3, pkg4, pkg5],
projectsRelationship: 'independent',
releaseTagPattern: '{projectName}@{version}',
},
},
version: {
generatorOptions: {
specifierSource: 'version-plans',
},
},
changelog: {
projectChangelogs: true,
},
versionPlans: true,
};
return nxJson;
});
runCLI(
'release plan minor -g fixed-group -m "Update the fixed packages with another minor release." --verbose',
{
silenceError: true,
}
);
runCLI(
'release plan minor -g independent-group -m "Update the independent packages with another minor release." --verbose',
{
silenceError: true,
}
);
const versionPlansDir = tmpProjPath('.nx/version-plans');
await runCommandAsync(`git add ${versionPlansDir}`);
await runCommandAsync(
`git commit -m "chore: add version plans for fixed and independent groups again"`
);
const releaseResult = runCLI('release major --verbose --skip-publish', {
silenceError: true,
});
expect(releaseResult).toContain(
`NX A specifier option cannot be provided when using version plans.`
);
expect(releaseResult).toContain(
`To override this behavior, use the Nx Release programmatic API directly (https://nx.dev/features/manage-releases#using-the-programmatic-api-for-nx-release).`
);
const versionResult = runCLI('release version major --verbose', {
silenceError: true,
});
expect(versionResult).toContain(
'Skipping version plan discovery as a specifier was provided'
);
expect(versionResult).toContain(
`${pkg1} 📄 Using the provided version specifier "major".`
);
expect(versionResult).toContain(
`${pkg2} 📄 Using the provided version specifier "major".`
);
expect(versionResult).toContain(
`${pkg3} 📄 Using the provided version specifier "major".`
);
expect(versionResult).toContain(
`${pkg4} 📄 Using the provided version specifier "major".`
);
expect(versionResult).toContain(
`${pkg5} 📄 Using the provided version specifier "major".`
);
expect(versionResult).toContain(
`git add ${pkg1}/package.json ${pkg2}/package.json ${pkg3}/package.json ${pkg4}/package.json ${pkg5}/package.json`
);
expect(readdirSync(versionPlansDir).length).toEqual(2);
});
});

View File

@ -81,6 +81,7 @@ export type PlanCheckOptions = BaseNxReleaseArgs & {
export type ReleaseOptions = NxReleaseArgs &
FirstReleaseArgs & {
specifier?: string;
yes?: boolean;
skipPublish?: boolean;
};

View File

@ -94,6 +94,18 @@ export function createAPI(overrideReleaseConfig: NxReleaseConfiguration) {
});
}
const rawVersionPlans = await readRawVersionPlans();
if (args.specifier && rawVersionPlans.length > 0) {
output.error({
title: `A specifier option cannot be provided when using version plans.`,
bodyLines: [
`To override this behavior, use the Nx Release programmatic API directly (https://nx.dev/features/manage-releases#using-the-programmatic-api-for-nx-release).`,
],
});
process.exit(1);
}
// These properties must never be undefined as this command should
// always explicitly override the git operations of the subcommands.
const shouldCommit = userProvidedReleaseConfig.git?.commit ?? true;
@ -134,7 +146,7 @@ export function createAPI(overrideReleaseConfig: NxReleaseConfiguration) {
output.error(filterError);
process.exit(1);
}
const rawVersionPlans = await readRawVersionPlans();
setResolvedVersionPlansOnGroups(
rawVersionPlans,
releaseGroups,

View File

@ -189,12 +189,20 @@ export function createAPI(overrideReleaseConfig: NxReleaseConfiguration) {
output.error(filterError);
process.exit(1);
}
const rawVersionPlans = await readRawVersionPlans();
setResolvedVersionPlansOnGroups(
rawVersionPlans,
releaseGroups,
Object.keys(projectGraph.nodes)
);
if (!args.specifier) {
const rawVersionPlans = await readRawVersionPlans();
setResolvedVersionPlansOnGroups(
rawVersionPlans,
releaseGroups,
Object.keys(projectGraph.nodes)
);
} else {
if (args.verbose && releaseGroups.some((g) => !!g.versionPlans)) {
console.log(
`Skipping version plan discovery as a specifier was provided`
);
}
}
if (args.deleteVersionPlans === undefined) {
// default to not delete version plans after versioning as they may be needed for changelog generation