From 619dbe7316cb4c5531640c0211a07470ba7aeb7b Mon Sep 17 00:00:00 2001 From: James Henry Date: Wed, 25 Sep 2024 14:51:10 +0400 Subject: [PATCH] fix(release): add groupPreVersionCommand to schema, improve logging (#28087) --- e2e/release/src/pre-version-command.test.ts | 4 +- packages/nx/schemas/nx-schema.json | 47 ++++++++++--------- .../nx/src/command-line/release/version.ts | 21 ++++++--- 3 files changed, 44 insertions(+), 28 deletions(-) diff --git a/e2e/release/src/pre-version-command.test.ts b/e2e/release/src/pre-version-command.test.ts index 5dbab07f15..bb66ebb963 100644 --- a/e2e/release/src/pre-version-command.test.ts +++ b/e2e/release/src/pre-version-command.test.ts @@ -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 = { diff --git a/packages/nx/schemas/nx-schema.json b/packages/nx/schemas/nx-schema.json index 60f55e9e93..e75da1a5f6 100644 --- a/packages/nx/schemas/nx-schema.json +++ b/packages/nx/schemas/nx-schema.json @@ -152,25 +152,7 @@ ] }, "version": { - "allOf": [ - { - "$ref": "#/definitions/NxReleaseVersionConfiguration" - }, - { - "allOf": [ - { - "not": { - "required": ["git"] - } - }, - { - "not": { - "required": ["preVersionCommand"] - } - } - ] - } - ] + "$ref": "#/definitions/NxReleaseGroupVersionConfiguration" }, "changelog": { "oneOf": [ @@ -675,9 +657,32 @@ }, "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", diff --git a/packages/nx/src/command-line/release/version.ts b/packages/nx/src/command-line/release/version.ts index 8aac3764b3..e93015cbd3 100644 --- a/packages/nx/src/command-line/release/version.ts +++ b/packages/nx/src/command-line/release/version.ts @@ -383,10 +383,14 @@ export function createAPI(overrideReleaseConfig: NxReleaseConfiguration) { for (const releaseGroup of releaseGroups) { const releaseGroupName = releaseGroup.name; - runPreVersionCommand(releaseGroup.version.groupPreVersionCommand, { - dryRun: args.dryRun, - verbose: args.verbose, - }); + 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);