From f25c463395b2ffe7e824bf0fcd222d05bc90e3c5 Mon Sep 17 00:00:00 2001 From: Jonathan Gelin Date: Tue, 17 Sep 2024 12:23:08 +0200 Subject: [PATCH] feat(release): support groupPreVersionCommand for release groups (#27474) (cherry picked from commit 71fe65ffbda3a55a31c164566bc73604ec05d157) --- .../nx-release/build-before-versioning.md | 19 ++ e2e/release/src/pre-version-command.test.ts | 32 ++- .../release/config/config.spec.ts | 240 ++++++++++++++++++ .../src/command-line/release/config/config.ts | 10 +- .../config/filter-release-groups.spec.ts | 18 ++ .../command-line/release/utils/shared.spec.ts | 5 + .../nx/src/command-line/release/version.ts | 6 + packages/nx/src/config/nx-json.ts | 10 +- 8 files changed, 331 insertions(+), 9 deletions(-) diff --git a/docs/shared/recipes/nx-release/build-before-versioning.md b/docs/shared/recipes/nx-release/build-before-versioning.md index acb28411b5a67..307622e803a1b 100644 --- a/docs/shared/recipes/nx-release/build-before-versioning.md +++ b/docs/shared/recipes/nx-release/build-before-versioning.md @@ -13,3 +13,22 @@ In order to ensure that projects are built before the new version is applied to ``` This command will run the `build` target for all projects before the version step of Nx Release. Any command can be specified, including non-nx commands. This step is often required when [publishing from a custom dist directory](/recipes/nx-release/publish-custom-dist-directory), as the dist directory must be built before the version is applied to the dist directory's package manifest. + +When using release groups in which the member projects are versioned together, you can use `groupPreVersionCommand` and it will be executed before the versioning step for that release group. + +```json {% fileName="nx.json" %} +{ + "release": { + "groups": { + "my-group": { + "projects": ["my-lib-one", "my-lib-two"], + "version": { + "groupPreVersionCommand": "npx nx run-many -t build -p my-lib-one,my-lib-two" + } + } + } + } +} +``` + +The `groupPreVersionCommand` will run in addition to the global `preVersionCommand`. diff --git a/e2e/release/src/pre-version-command.test.ts b/e2e/release/src/pre-version-command.test.ts index cada8beda6ae8..5dbab07f15768 100644 --- a/e2e/release/src/pre-version-command.test.ts +++ b/e2e/release/src/pre-version-command.test.ts @@ -88,6 +88,26 @@ describe('nx release pre-version command', () => { expect(result3).toContain('nx run-many -t build'); expect(result3).toContain(`NX Running target build for project ${pkg1}:`); + const groupName = uniq('group-1'); + updateJson(`nx.json`, (json) => { + json.release = { + groups: { + [groupName]: { + projects: [pkg1], + version: { + groupPreVersionCommand: `nx run-many -t build -p ${pkg1}`, + }, + }, + }, + }; + return json; + }); + + // 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'); + updateJson(`nx.json`, (json) => { json.release = { version: { @@ -98,20 +118,20 @@ describe('nx release pre-version command', () => { }); // command should fail because the pre-version command will fail - const result4 = runCLI('release patch -d --first-release', { + const result5 = runCLI('release patch -d --first-release', { silenceError: true, }); - expect(result4).toContain( + expect(result5).toContain( 'NX The pre-version command failed. Retry with --verbose to see the full output of the pre-version command.' ); - expect(result4).toContain('echo "error" && exit 1'); + expect(result5).toContain('echo "error" && exit 1'); - const result5 = runCLI('release patch -d --first-release --verbose', { + const result6 = runCLI('release patch -d --first-release --verbose', { silenceError: true, }); - expect(result5).toContain( + expect(result6).toContain( 'NX The pre-version command failed. See the full output above.' ); - expect(result4).toContain('echo "error" && exit 1'); + expect(result6).toContain('echo "error" && exit 1'); }); }); diff --git a/packages/nx/src/command-line/release/config/config.spec.ts b/packages/nx/src/command-line/release/config/config.spec.ts index 8190d1bf37fe5..0551d5ada882e 100644 --- a/packages/nx/src/command-line/release/config/config.spec.ts +++ b/packages/nx/src/command-line/release/config/config.spec.ts @@ -274,6 +274,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -449,6 +450,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -627,6 +629,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -836,6 +839,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -1029,6 +1033,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -1230,6 +1235,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -1432,6 +1438,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -1614,6 +1621,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -1795,6 +1803,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -1978,6 +1987,7 @@ describe('createNxReleaseConfig()', () => { "generatorOptions": { "optionsOverride": "something", }, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -1992,6 +2002,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@custom/generator-alternative", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -2184,6 +2195,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -2370,6 +2382,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -2395,6 +2408,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -2579,6 +2593,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -2766,6 +2781,7 @@ describe('createNxReleaseConfig()', () => { "generatorOptions": { "foo": "bar", }, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -2949,6 +2965,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -3133,6 +3150,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -3313,6 +3331,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -3339,6 +3358,190 @@ describe('createNxReleaseConfig()', () => { } `); }); + + it('should allow configuration of preVersionCommand for a group', async () => { + const res = await createNxReleaseConfig(projectGraph, projectFileMap, { + groups: { + 'group-1': { + projects: ['lib-a'], + version: { + groupPreVersionCommand: 'nx run-many -t build -p lib-a', + }, + }, + }, + }); + expect(res).toMatchInlineSnapshot(` + { + "error": null, + "nxReleaseConfig": { + "changelog": { + "automaticFromRef": false, + "git": { + "commit": true, + "commitArgs": "", + "commitMessage": "chore(release): publish {version}", + "stageChanges": false, + "tag": true, + "tagArgs": "", + "tagMessage": "", + }, + "projectChangelogs": false, + "workspaceChangelog": { + "createRelease": false, + "entryWhenNoChanges": "This was a version bump only, there were no code changes.", + "file": "{workspaceRoot}/CHANGELOG.md", + "renderOptions": { + "authors": true, + "commitReferences": true, + "mapAuthorsToGitHubUsernames": true, + "versionTitleDate": true, + }, + "renderer": "/release/changelog-renderer", + }, + }, + "conventionalCommits": { + "types": { + "build": { + "changelog": { + "hidden": true, + "title": "📦 Build", + }, + "semverBump": "none", + }, + "chore": { + "changelog": { + "hidden": true, + "title": "🏡 Chore", + }, + "semverBump": "none", + }, + "ci": { + "changelog": { + "hidden": true, + "title": "🤖 CI", + }, + "semverBump": "none", + }, + "docs": { + "changelog": { + "hidden": true, + "title": "📖 Documentation", + }, + "semverBump": "none", + }, + "examples": { + "changelog": { + "hidden": true, + "title": "🏀 Examples", + }, + "semverBump": "none", + }, + "feat": { + "changelog": { + "hidden": false, + "title": "🚀 Features", + }, + "semverBump": "minor", + }, + "fix": { + "changelog": { + "hidden": false, + "title": "🩹 Fixes", + }, + "semverBump": "patch", + }, + "perf": { + "changelog": { + "hidden": false, + "title": "🔥 Performance", + }, + "semverBump": "none", + }, + "refactor": { + "changelog": { + "hidden": true, + "title": "💅 Refactors", + }, + "semverBump": "none", + }, + "revert": { + "changelog": { + "hidden": true, + "title": "⏪ Revert", + }, + "semverBump": "none", + }, + "style": { + "changelog": { + "hidden": true, + "title": "🎨 Styles", + }, + "semverBump": "none", + }, + "test": { + "changelog": { + "hidden": true, + "title": "✅ Tests", + }, + "semverBump": "none", + }, + "types": { + "changelog": { + "hidden": true, + "title": "🌊 Types", + }, + "semverBump": "none", + }, + }, + }, + "git": { + "commit": false, + "commitArgs": "", + "commitMessage": "chore(release): publish {version}", + "stageChanges": false, + "tag": false, + "tagArgs": "", + "tagMessage": "", + }, + "groups": { + "group-1": { + "changelog": false, + "projects": [ + "lib-a", + ], + "projectsRelationship": "fixed", + "releaseTagPattern": "v{version}", + "version": { + "conventionalCommits": false, + "generator": "@nx/js:release-version", + "generatorOptions": {}, + "groupPreVersionCommand": "nx run-many -t build -p lib-a", + }, + "versionPlans": false, + }, + }, + "projectsRelationship": "fixed", + "releaseTagPattern": "v{version}", + "version": { + "conventionalCommits": false, + "generator": "@nx/js:release-version", + "generatorOptions": {}, + "git": { + "commit": false, + "commitArgs": "", + "commitMessage": "chore(release): publish {version}", + "stageChanges": true, + "tag": false, + "tagArgs": "", + "tagMessage": "", + }, + "preVersionCommand": "", + }, + "versionPlans": false, + }, + } + `); + }); }); describe('user config -> top level projects', () => { @@ -3511,6 +3714,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -3691,6 +3895,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -3893,6 +4098,7 @@ describe('createNxReleaseConfig()', () => { "currentVersionResolver": "git-tag", "specifierSource": "conventional-commits", }, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -4065,6 +4271,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -4278,6 +4485,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -4481,6 +4689,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -4662,6 +4871,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -4843,6 +5053,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -5022,6 +5233,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -5237,6 +5449,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -5428,6 +5641,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -5622,6 +5836,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -5817,6 +6032,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -6015,6 +6231,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -6234,6 +6451,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -6248,6 +6466,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -6273,6 +6492,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -6486,6 +6706,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -6859,6 +7080,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -7219,6 +7441,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -7234,6 +7457,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -7402,6 +7626,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -7590,6 +7815,7 @@ describe('createNxReleaseConfig()', () => { "currentVersionResolver": "git-tag", "specifierSource": "conventional-commits", }, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -7777,6 +8003,7 @@ describe('createNxReleaseConfig()', () => { "currentVersionResolver": "registry", "specifierSource": "prompt", }, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -7963,6 +8190,7 @@ describe('createNxReleaseConfig()', () => { "currentVersionResolver": "git-tag", "specifierSource": "conventional-commits", }, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -8152,6 +8380,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -8342,6 +8571,7 @@ describe('createNxReleaseConfig()', () => { "someUnrelatedOption": "foobar", "specifierSource": "conventional-commits", }, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -8571,6 +8801,7 @@ describe('createNxReleaseConfig()', () => { "generatorOptions": { "specifierSource": "version-plans", }, + "groupPreVersionCommand": "", }, "versionPlans": true, }, @@ -8758,6 +8989,7 @@ describe('createNxReleaseConfig()', () => { "generatorOptions": { "specifierSource": "version-plans", }, + "groupPreVersionCommand": "", }, "versionPlans": { "ignorePatternsForPlanCheck": [ @@ -8949,6 +9181,7 @@ describe('createNxReleaseConfig()', () => { "generatorOptions": { "specifierSource": "version-plans", }, + "groupPreVersionCommand": "", }, "versionPlans": true, }, @@ -8963,6 +9196,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -9144,6 +9378,7 @@ describe('createNxReleaseConfig()', () => { "generatorOptions": { "specifierSource": "version-plans", }, + "groupPreVersionCommand": "", }, "versionPlans": { "ignorePatternsForPlanCheck": [ @@ -9162,6 +9397,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -9341,6 +9577,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -9357,6 +9594,7 @@ describe('createNxReleaseConfig()', () => { "generatorOptions": { "specifierSource": "version-plans", }, + "groupPreVersionCommand": "", }, "versionPlans": true, }, @@ -9540,6 +9778,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -9556,6 +9795,7 @@ describe('createNxReleaseConfig()', () => { "generatorOptions": { "specifierSource": "version-plans", }, + "groupPreVersionCommand": "", }, "versionPlans": { "ignorePatternsForPlanCheck": [ diff --git a/packages/nx/src/command-line/release/config/config.ts b/packages/nx/src/command-line/release/config/config.ts index cadbf45219d4c..076a77d330083 100644 --- a/packages/nx/src/command-line/release/config/config.ts +++ b/packages/nx/src/command-line/release/config/config.ts @@ -274,6 +274,7 @@ export async function createNxReleaseConfig( conventionalCommits: false, generator: '@nx/js:release-version', generatorOptions: {}, + groupPreVersionCommand: '', }, changelog: { createRelease: false, @@ -356,7 +357,9 @@ export async function createNxReleaseConfig( ); // these options are not supported at the group level, only the root/command level - const rootVersionWithoutGlobalOptions = { ...rootVersionConfig }; + const rootVersionWithoutGlobalOptions = { + ...rootVersionConfig, + }; delete rootVersionWithoutGlobalOptions.git; delete rootVersionWithoutGlobalOptions.preVersionCommand; @@ -497,7 +500,10 @@ export async function createNxReleaseConfig( projects: matchingProjects, version: deepMergeDefaults( // First apply any group level defaults, then apply actual root level config, then group level config - [GROUP_DEFAULTS.version, rootVersionWithoutGlobalOptions], + [ + GROUP_DEFAULTS.version, + { ...rootVersionWithoutGlobalOptions, groupPreVersionCommand: '' }, + ], releaseGroup.version ), // If the user has set any changelog config at all, including at the root level, then use one set of defaults, otherwise default to false for the whole feature diff --git a/packages/nx/src/command-line/release/config/filter-release-groups.spec.ts b/packages/nx/src/command-line/release/config/filter-release-groups.spec.ts index 5a44c384e0ca3..97d1a63669353 100644 --- a/packages/nx/src/command-line/release/config/filter-release-groups.spec.ts +++ b/packages/nx/src/command-line/release/config/filter-release-groups.spec.ts @@ -102,6 +102,7 @@ describe('filterReleaseGroups()', () => { conventionalCommits: false, generator: '', generatorOptions: {}, + groupPreVersionCommand: '', }, releaseTagPattern: '', versionPlans: false, @@ -130,6 +131,7 @@ describe('filterReleaseGroups()', () => { conventionalCommits: false, generator: '', generatorOptions: {}, + groupPreVersionCommand: '', }, releaseTagPattern: '', versionPlans: false, @@ -142,6 +144,7 @@ describe('filterReleaseGroups()', () => { conventionalCommits: false, generator: '', generatorOptions: {}, + groupPreVersionCommand: '', }, releaseTagPattern: '', versionPlans: false, @@ -165,6 +168,7 @@ describe('filterReleaseGroups()', () => { "conventionalCommits": false, "generator": "", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -181,6 +185,7 @@ describe('filterReleaseGroups()', () => { "conventionalCommits": false, "generator": "", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -201,6 +206,7 @@ describe('filterReleaseGroups()', () => { "conventionalCommits": false, "generator": "", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, } => Set { @@ -219,6 +225,7 @@ describe('filterReleaseGroups()', () => { "conventionalCommits": false, "generator": "", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, } => Set { @@ -238,6 +245,7 @@ describe('filterReleaseGroups()', () => { conventionalCommits: false, generator: '', generatorOptions: {}, + groupPreVersionCommand: '', }, releaseTagPattern: '', versionPlans: false, @@ -265,6 +273,7 @@ describe('filterReleaseGroups()', () => { conventionalCommits: false, generator: '', generatorOptions: {}, + groupPreVersionCommand: '', }, releaseTagPattern: '', versionPlans: false, @@ -277,6 +286,7 @@ describe('filterReleaseGroups()', () => { conventionalCommits: false, generator: '', generatorOptions: {}, + groupPreVersionCommand: '', }, releaseTagPattern: '', versionPlans: false, @@ -305,6 +315,7 @@ describe('filterReleaseGroups()', () => { conventionalCommits: false, generator: '', generatorOptions: {}, + groupPreVersionCommand: '', }, releaseTagPattern: '', versionPlans: false, @@ -317,6 +328,7 @@ describe('filterReleaseGroups()', () => { conventionalCommits: false, generator: '', generatorOptions: {}, + groupPreVersionCommand: '', }, releaseTagPattern: '', versionPlans: false, @@ -340,6 +352,7 @@ describe('filterReleaseGroups()', () => { "conventionalCommits": false, "generator": "", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -360,6 +373,7 @@ describe('filterReleaseGroups()', () => { "conventionalCommits": false, "generator": "", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, } => Set { @@ -395,6 +409,7 @@ describe('filterReleaseGroups()', () => { conventionalCommits: false, generator: '', generatorOptions: {}, + groupPreVersionCommand: '', }, releaseTagPattern: '', versionPlans: false, @@ -407,6 +422,7 @@ describe('filterReleaseGroups()', () => { conventionalCommits: false, generator: '', generatorOptions: {}, + groupPreVersionCommand: '', }, releaseTagPattern: '', versionPlans: false, @@ -430,6 +446,7 @@ describe('filterReleaseGroups()', () => { "conventionalCommits": false, "generator": "", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, }, @@ -450,6 +467,7 @@ describe('filterReleaseGroups()', () => { "conventionalCommits": false, "generator": "", "generatorOptions": {}, + "groupPreVersionCommand": "", }, "versionPlans": false, } => Set { diff --git a/packages/nx/src/command-line/release/utils/shared.spec.ts b/packages/nx/src/command-line/release/utils/shared.spec.ts index b1852c2ad824b..f95a12a5762b2 100644 --- a/packages/nx/src/command-line/release/utils/shared.spec.ts +++ b/packages/nx/src/command-line/release/utils/shared.spec.ts @@ -14,6 +14,7 @@ describe('shared', () => { conventionalCommits: false, generator: '@nx/js:version', generatorOptions: {}, + groupPreVersionCommand: '', }, changelog: false, releaseTagPattern: '{projectName}-{version}', @@ -28,6 +29,7 @@ describe('shared', () => { conventionalCommits: false, generator: '@nx/js:version', generatorOptions: {}, + groupPreVersionCommand: '', }, changelog: false, releaseTagPattern: '{projectName}-{version}', @@ -82,6 +84,7 @@ describe('shared', () => { conventionalCommits: false, generator: '@nx/js:version', generatorOptions: {}, + groupPreVersionCommand: '', }, changelog: false, releaseTagPattern: '{projectName}-{version}', @@ -96,6 +99,7 @@ describe('shared', () => { conventionalCommits: false, generator: '@nx/js:version', generatorOptions: {}, + groupPreVersionCommand: '', }, changelog: false, releaseTagPattern: '{projectName}-{version}', @@ -161,6 +165,7 @@ describe('shared', () => { specifierSource: 'conventional-commits', currentVersionResolver: 'git-tag', }, + groupPreVersionCommand: '', }, changelog: { createRelease: 'github', diff --git a/packages/nx/src/command-line/release/version.ts b/packages/nx/src/command-line/release/version.ts index e990727057c12..9c2f2e1b6d8ad 100644 --- a/packages/nx/src/command-line/release/version.ts +++ b/packages/nx/src/command-line/release/version.ts @@ -382,6 +382,12 @@ export function createAPI(overrideReleaseConfig: NxReleaseConfiguration) { */ for (const releaseGroup of releaseGroups) { const releaseGroupName = releaseGroup.name; + + runPreVersionCommand(releaseGroup.version.groupPreVersionCommand, { + dryRun: args.dryRun, + verbose: args.verbose, + }); + const projectBatches = batchProjectsByGeneratorConfig( projectGraph, releaseGroup, diff --git a/packages/nx/src/config/nx-json.ts b/packages/nx/src/config/nx-json.ts index 7aa0a244a16a1..16c5487f8b645 100644 --- a/packages/nx/src/config/nx-json.ts +++ b/packages/nx/src/config/nx-json.ts @@ -210,7 +210,15 @@ export interface NxReleaseConfiguration { * * NOTE: git configuration is not supported at the group level, only the root/command level */ - version?: NxReleaseVersionConfiguration; + version?: NxReleaseVersionConfiguration & { + /** + * 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'. + * It will run in addition to the global `preVersionCommand` + */ + groupPreVersionCommand?: string; + }; /** * Project changelogs are disabled by default. *