fix(release): add groupPreVersionCommand to schema, improve logging (#28087)

This commit is contained in:
James Henry 2024-09-25 14:51:10 +04:00 committed by GitHub
parent 4fa50ad238
commit 619dbe7316
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 44 additions and 28 deletions

View File

@ -106,7 +106,9 @@ describe('nx release pre-version command', () => {
// command should succeed because the pre-version command will build the package
const result4 = runCLI(`release patch -d -g ${groupName} --first-release`);
expect(result4).toContain('NX Executing pre-version command');
expect(result4).toContain(
`NX Executing release group pre-version command for "${groupName}"`
);
updateJson(`nx.json`, (json) => {
json.release = {

View File

@ -152,25 +152,7 @@
]
},
"version": {
"allOf": [
{
"$ref": "#/definitions/NxReleaseVersionConfiguration"
},
{
"allOf": [
{
"not": {
"required": ["git"]
}
},
{
"not": {
"required": ["preVersionCommand"]
}
}
]
}
]
"$ref": "#/definitions/NxReleaseGroupVersionConfiguration"
},
"changelog": {
"oneOf": [
@ -675,10 +657,33 @@
},
"preVersionCommand": {
"type": "string",
"description": "A command to run after validation of nx release configuration, but before versioning begins. Used for preparing build artifacts. If --dry-run is passed, the command is still executed, but with the NX_DRY_RUN environment variable set to 'true'."
"description": "A command to run after validation of nx release configuration, but before versioning begins. Useful for preparing build artifacts. If --dry-run is passed, the command is still executed, but with the NX_DRY_RUN environment variable set to 'true'."
}
},
"additionalProperties": false
},
"NxReleaseGroupVersionConfiguration": {
"type": "object",
"properties": {
"conventionalCommits": {
"type": "boolean",
"description": "Shorthand for enabling the current version of projects to be resolved from git tags, and the next version to be determined by analyzing commit messages according to the Conventional Commits specification.",
"default": false
},
"generator": {
"type": "string"
},
"generatorOptions": {
"type": "object",
"additionalProperties": true
},
"groupPreVersionCommand": {
"type": "string",
"description": "A command to run after validation of nx release configuration AND after the release.version.preVersionCommand (if any), but before versioning begins for this specific group. Useful for preparing build artifacts for the group. If --dry-run is passed, the command is still executed, but with the NX_DRY_RUN environment variable set to 'true'."
}
},
"additionalProperties": false
},
"NxReleaseChangelogConfiguration": {
"type": "object",
"properties": {

View File

@ -383,10 +383,14 @@ export function createAPI(overrideReleaseConfig: NxReleaseConfiguration) {
for (const releaseGroup of releaseGroups) {
const releaseGroupName = releaseGroup.name;
runPreVersionCommand(releaseGroup.version.groupPreVersionCommand, {
runPreVersionCommand(
releaseGroup.version.groupPreVersionCommand,
{
dryRun: args.dryRun,
verbose: args.verbose,
});
},
releaseGroup
);
const projectBatches = batchProjectsByGeneratorConfig(
projectGraph,
@ -727,13 +731,18 @@ function resolveGeneratorData({
}
function runPreVersionCommand(
preVersionCommand: string,
{ dryRun, verbose }: { dryRun: boolean; verbose: boolean }
{ dryRun, verbose }: { dryRun: boolean; verbose: boolean },
releaseGroup?: ReleaseGroupWithName
) {
if (!preVersionCommand) {
return;
}
output.logSingleLine(`Executing pre-version command`);
output.logSingleLine(
releaseGroup
? `Executing release group pre-version command for "${releaseGroup.name}"`
: `Executing pre-version command`
);
if (verbose) {
console.log(`Executing the following pre-version command:`);
console.log(preVersionCommand);