From d254b0d1d585f553da206b96d0af4a11dea96541 Mon Sep 17 00:00:00 2001 From: Jonathan Gelin Date: Sun, 8 Sep 2024 15:48:09 +0200 Subject: [PATCH] feat(release): Allow preVersionCommand By Group --- .../nx-release/build-before-versioning.md | 2 + e2e/release/src/pre-version-command.test.ts | 77 ++++++ .../release/config/config.spec.ts | 240 ++++++++++++++++++ .../src/command-line/release/config/config.ts | 2 +- .../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 | 12 +- 8 files changed, 355 insertions(+), 7 deletions(-) diff --git a/docs/shared/recipes/nx-release/build-before-versioning.md b/docs/shared/recipes/nx-release/build-before-versioning.md index acb28411b5a67b..5bbca35f963bfa 100644 --- a/docs/shared/recipes/nx-release/build-before-versioning.md +++ b/docs/shared/recipes/nx-release/build-before-versioning.md @@ -13,3 +13,5 @@ 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 also leverage `preVersionCommand` and it will be executed before the versioning step for that release group. diff --git a/e2e/release/src/pre-version-command.test.ts b/e2e/release/src/pre-version-command.test.ts index cada8beda6ae81..95a579f955d546 100644 --- a/e2e/release/src/pre-version-command.test.ts +++ b/e2e/release/src/pre-version-command.test.ts @@ -114,4 +114,81 @@ describe('nx release pre-version command', () => { ); expect(result4).toContain('echo "error" && exit 1'); }); + + it('should run pre-version command before group versioning step', async () => { + updateJson(`nx.json`, (json) => { + delete json.release; + return json; + }); + const result1 = runCLI('release patch -d --first-release', { + silenceError: true, + }); + + // command should fail because @nx/js:library configures the packageRoot to be dist/{project-name}, which doesn't exist yet + expect(result1).toContain( + `NX The project "${pkg1}" does not have a package.json available at dist/${pkg1}/package.json.` + ); + + updateJson(`nx.json`, (json) => { + json.release = { + groups: { + 'group-1': { + projects: [pkg1], + version: { + preVersionCommand: `nx run-many -t build -p ${pkg1}`, + }, + }, + }, + }; + return json; + }); + + // command should succeed because the pre-version command will build the package + const result2 = runCLI('release patch -d -g group-1 --first-release'); + + expect(result2).toContain('NX Executing pre-version command'); + + const result3 = runCLI( + 'release patch -d -g group-1 --first-release --verbose' + ); + + expect(result3).toContain('NX Executing pre-version command'); + expect(result3).toContain('Executing the following pre-version command:'); + expect(result3).toContain(`nx run-many -t build -p ${pkg1}`); + expect(result3).toContain(`NX Running target build for project ${pkg1}:`); + + updateJson(`nx.json`, (json) => { + json.release = { + groups: { + 'group-1': { + projects: [pkg1], + version: { + preVersionCommand: `echo "error" && exit 1`, + }, + }, + }, + }; + return json; + }); + + // command should fail because the pre-version command will fail + const result4 = runCLI('release patch -d -g group-1 --first-release', { + silenceError: true, + }); + expect(result4).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'); + + const result5 = runCLI( + 'release patch -d -g group-1 --first-release --verbose', + { + silenceError: true, + } + ); + expect(result5).toContain( + 'NX The pre-version command failed. See the full output above.' + ); + expect(result4).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 8190d1bf37fe54..eb127131742f16 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": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -449,6 +450,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -627,6 +629,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -836,6 +839,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -1029,6 +1033,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -1230,6 +1235,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -1432,6 +1438,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -1614,6 +1621,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -1795,6 +1803,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -1978,6 +1987,7 @@ describe('createNxReleaseConfig()', () => { "generatorOptions": { "optionsOverride": "something", }, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -1992,6 +2002,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@custom/generator-alternative", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -2184,6 +2195,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -2370,6 +2382,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -2395,6 +2408,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -2579,6 +2593,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -2766,6 +2781,7 @@ describe('createNxReleaseConfig()', () => { "generatorOptions": { "foo": "bar", }, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -2949,6 +2965,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -3133,6 +3150,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -3313,6 +3331,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "nx run-many -t build", }, "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: { + preVersionCommand: '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": {}, + "preVersionCommand": "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": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -3691,6 +3895,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -3893,6 +4098,7 @@ describe('createNxReleaseConfig()', () => { "currentVersionResolver": "git-tag", "specifierSource": "conventional-commits", }, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -4065,6 +4271,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -4278,6 +4485,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -4481,6 +4689,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -4662,6 +4871,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -4843,6 +5053,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -5022,6 +5233,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -5237,6 +5449,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -5428,6 +5641,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -5622,6 +5836,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -5817,6 +6032,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -6015,6 +6231,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -6234,6 +6451,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -6248,6 +6466,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -6273,6 +6492,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -6486,6 +6706,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -6859,6 +7080,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -7219,6 +7441,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -7234,6 +7457,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -7402,6 +7626,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -7590,6 +7815,7 @@ describe('createNxReleaseConfig()', () => { "currentVersionResolver": "git-tag", "specifierSource": "conventional-commits", }, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -7777,6 +8003,7 @@ describe('createNxReleaseConfig()', () => { "currentVersionResolver": "registry", "specifierSource": "prompt", }, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -7963,6 +8190,7 @@ describe('createNxReleaseConfig()', () => { "currentVersionResolver": "git-tag", "specifierSource": "conventional-commits", }, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -8152,6 +8380,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -8342,6 +8571,7 @@ describe('createNxReleaseConfig()', () => { "someUnrelatedOption": "foobar", "specifierSource": "conventional-commits", }, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -8571,6 +8801,7 @@ describe('createNxReleaseConfig()', () => { "generatorOptions": { "specifierSource": "version-plans", }, + "preVersionCommand": "", }, "versionPlans": true, }, @@ -8758,6 +8989,7 @@ describe('createNxReleaseConfig()', () => { "generatorOptions": { "specifierSource": "version-plans", }, + "preVersionCommand": "", }, "versionPlans": { "ignorePatternsForPlanCheck": [ @@ -8949,6 +9181,7 @@ describe('createNxReleaseConfig()', () => { "generatorOptions": { "specifierSource": "version-plans", }, + "preVersionCommand": "", }, "versionPlans": true, }, @@ -8963,6 +9196,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -9144,6 +9378,7 @@ describe('createNxReleaseConfig()', () => { "generatorOptions": { "specifierSource": "version-plans", }, + "preVersionCommand": "", }, "versionPlans": { "ignorePatternsForPlanCheck": [ @@ -9162,6 +9397,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -9341,6 +9577,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -9357,6 +9594,7 @@ describe('createNxReleaseConfig()', () => { "generatorOptions": { "specifierSource": "version-plans", }, + "preVersionCommand": "", }, "versionPlans": true, }, @@ -9540,6 +9778,7 @@ describe('createNxReleaseConfig()', () => { "conventionalCommits": false, "generator": "@nx/js:release-version", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -9556,6 +9795,7 @@ describe('createNxReleaseConfig()', () => { "generatorOptions": { "specifierSource": "version-plans", }, + "preVersionCommand": "", }, "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 7c2918067c1fc4..939c20ffaf4538 100644 --- a/packages/nx/src/command-line/release/config/config.ts +++ b/packages/nx/src/command-line/release/config/config.ts @@ -273,6 +273,7 @@ export async function createNxReleaseConfig( conventionalCommits: false, generator: '@nx/js:release-version', generatorOptions: {}, + preVersionCommand: '', }, changelog: { createRelease: false, @@ -357,7 +358,6 @@ export async function createNxReleaseConfig( // these options are not supported at the group level, only the root/command level const rootVersionWithoutGlobalOptions = { ...rootVersionConfig }; delete rootVersionWithoutGlobalOptions.git; - delete rootVersionWithoutGlobalOptions.preVersionCommand; // Apply conventionalCommits shorthand to the final group defaults if explicitly configured in the original user config if (userConfig.version?.conventionalCommits === true) { 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 5a44c384e0ca34..bf87d62394aa19 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: {}, + preVersionCommand: '', }, releaseTagPattern: '', versionPlans: false, @@ -130,6 +131,7 @@ describe('filterReleaseGroups()', () => { conventionalCommits: false, generator: '', generatorOptions: {}, + preVersionCommand: '', }, releaseTagPattern: '', versionPlans: false, @@ -142,6 +144,7 @@ describe('filterReleaseGroups()', () => { conventionalCommits: false, generator: '', generatorOptions: {}, + preVersionCommand: '', }, releaseTagPattern: '', versionPlans: false, @@ -165,6 +168,7 @@ describe('filterReleaseGroups()', () => { "conventionalCommits": false, "generator": "", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -181,6 +185,7 @@ describe('filterReleaseGroups()', () => { "conventionalCommits": false, "generator": "", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -201,6 +206,7 @@ describe('filterReleaseGroups()', () => { "conventionalCommits": false, "generator": "", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, } => Set { @@ -219,6 +225,7 @@ describe('filterReleaseGroups()', () => { "conventionalCommits": false, "generator": "", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, } => Set { @@ -238,6 +245,7 @@ describe('filterReleaseGroups()', () => { conventionalCommits: false, generator: '', generatorOptions: {}, + preVersionCommand: '', }, releaseTagPattern: '', versionPlans: false, @@ -265,6 +273,7 @@ describe('filterReleaseGroups()', () => { conventionalCommits: false, generator: '', generatorOptions: {}, + preVersionCommand: '', }, releaseTagPattern: '', versionPlans: false, @@ -277,6 +286,7 @@ describe('filterReleaseGroups()', () => { conventionalCommits: false, generator: '', generatorOptions: {}, + preVersionCommand: '', }, releaseTagPattern: '', versionPlans: false, @@ -305,6 +315,7 @@ describe('filterReleaseGroups()', () => { conventionalCommits: false, generator: '', generatorOptions: {}, + preVersionCommand: '', }, releaseTagPattern: '', versionPlans: false, @@ -317,6 +328,7 @@ describe('filterReleaseGroups()', () => { conventionalCommits: false, generator: '', generatorOptions: {}, + preVersionCommand: '', }, releaseTagPattern: '', versionPlans: false, @@ -340,6 +352,7 @@ describe('filterReleaseGroups()', () => { "conventionalCommits": false, "generator": "", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -360,6 +373,7 @@ describe('filterReleaseGroups()', () => { "conventionalCommits": false, "generator": "", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, } => Set { @@ -395,6 +409,7 @@ describe('filterReleaseGroups()', () => { conventionalCommits: false, generator: '', generatorOptions: {}, + preVersionCommand: '', }, releaseTagPattern: '', versionPlans: false, @@ -407,6 +422,7 @@ describe('filterReleaseGroups()', () => { conventionalCommits: false, generator: '', generatorOptions: {}, + preVersionCommand: '', }, releaseTagPattern: '', versionPlans: false, @@ -430,6 +446,7 @@ describe('filterReleaseGroups()', () => { "conventionalCommits": false, "generator": "", "generatorOptions": {}, + "preVersionCommand": "", }, "versionPlans": false, }, @@ -450,6 +467,7 @@ describe('filterReleaseGroups()', () => { "conventionalCommits": false, "generator": "", "generatorOptions": {}, + "preVersionCommand": "", }, "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 b1852c2ad824bb..86ef0ab15c7112 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: {}, + preVersionCommand: '', }, changelog: false, releaseTagPattern: '{projectName}-{version}', @@ -28,6 +29,7 @@ describe('shared', () => { conventionalCommits: false, generator: '@nx/js:version', generatorOptions: {}, + preVersionCommand: '', }, changelog: false, releaseTagPattern: '{projectName}-{version}', @@ -82,6 +84,7 @@ describe('shared', () => { conventionalCommits: false, generator: '@nx/js:version', generatorOptions: {}, + preVersionCommand: '', }, changelog: false, releaseTagPattern: '{projectName}-{version}', @@ -96,6 +99,7 @@ describe('shared', () => { conventionalCommits: false, generator: '@nx/js:version', generatorOptions: {}, + preVersionCommand: '', }, changelog: false, releaseTagPattern: '{projectName}-{version}', @@ -161,6 +165,7 @@ describe('shared', () => { specifierSource: 'conventional-commits', currentVersionResolver: 'git-tag', }, + preVersionCommand: '', }, changelog: { createRelease: 'github', diff --git a/packages/nx/src/command-line/release/version.ts b/packages/nx/src/command-line/release/version.ts index 07742a5dfcc574..6473cde2b4738b 100644 --- a/packages/nx/src/command-line/release/version.ts +++ b/packages/nx/src/command-line/release/version.ts @@ -375,6 +375,12 @@ export function createAPI(overrideReleaseConfig: NxReleaseConfiguration) { */ for (const releaseGroup of releaseGroups) { const releaseGroupName = releaseGroup.name; + + runPreVersionCommand(releaseGroup.version.preVersionCommand, { + 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 d91140661c33f2..ddcbf53abb284c 100644 --- a/packages/nx/src/config/nx-json.ts +++ b/packages/nx/src/config/nx-json.ts @@ -69,6 +69,12 @@ export interface NxReleaseVersionConfiguration { * If the user attempts to mix and match these options with the shorthand, we will provide a helpful error. */ conventionalCommits?: boolean; + /** + * 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'. + */ + preVersionCommand?: string; } export interface NxReleaseChangelogConfiguration { @@ -276,12 +282,6 @@ export interface NxReleaseConfiguration { * Enable or override configuration for git operations as part of the version subcommand */ git?: NxReleaseGitConfiguration; - /** - * 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'. - */ - preVersionCommand?: string; }; /** * Optionally override the git/release tag pattern to use. This field is the source of truth