From 580b696345158876525a4c6818539fc3ca973638 Mon Sep 17 00:00:00 2001 From: JamesHenry Date: Tue, 24 Sep 2024 22:10:13 +0400 Subject: [PATCH 1/3] fix(release): add groupPreVersionCommand to schema, improve logging --- packages/nx/schemas/nx-schema.json | 47 ++++++++++--------- .../nx/src/command-line/release/version.ts | 21 ++++++--- 2 files changed, 41 insertions(+), 27 deletions(-) diff --git a/packages/nx/schemas/nx-schema.json b/packages/nx/schemas/nx-schema.json index 60f55e9e9312f..e75da1a5f6718 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 8aac3764b3778..e93015cbd3217 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); From 26362e4c9e64e7aa067e27c54fbd988a03a71135 Mon Sep 17 00:00:00 2001 From: JamesHenry Date: Tue, 24 Sep 2024 23:15:46 +0400 Subject: [PATCH 2/3] chore(release): update e2e --- e2e/release/src/pre-version-command.test.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/e2e/release/src/pre-version-command.test.ts b/e2e/release/src/pre-version-command.test.ts index 5dbab07f15768..fe6bd8b66e2bb 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 = { From 6a09f7b72b207cdfe6395bc295445fd364fe9acb Mon Sep 17 00:00:00 2001 From: JamesHenry Date: Wed, 25 Sep 2024 01:06:17 +0400 Subject: [PATCH 3/3] chore(release): add missing quotes --- e2e/release/src/pre-version-command.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/release/src/pre-version-command.test.ts b/e2e/release/src/pre-version-command.test.ts index fe6bd8b66e2bb..bb66ebb963b62 100644 --- a/e2e/release/src/pre-version-command.test.ts +++ b/e2e/release/src/pre-version-command.test.ts @@ -107,7 +107,7 @@ describe('nx release pre-version command', () => { const result4 = runCLI(`release patch -d -g ${groupName} --first-release`); expect(result4).toContain( - `NX Executing release group pre-version command for ${groupName}` + `NX Executing release group pre-version command for "${groupName}"` ); updateJson(`nx.json`, (json) => {