diff --git a/docs/generated/cli/release.md b/docs/generated/cli/release.md index 08343d1fb55fe..6f9512b98c014 100644 --- a/docs/generated/cli/release.md +++ b/docs/generated/cli/release.md @@ -64,6 +64,8 @@ nx release version [specifier] | `--git-commit` | boolean | Whether or not to automatically commit the changes made by this command. | | `--git-commit-args` | string | Additional arguments (added after the --message argument, which may or may not be customized with --git-commit-message) to pass to the `git commit` command invoked behind the scenes. | | `--git-commit-message` | string | Custom git commit message to use when committing the changes made by this command. {version} will be dynamically interpolated when performing fixed releases, interpolated tags will be appended to the commit body when performing independent releases. | +| `--git-push` | boolean | Whether or not to automatically push the changes made by this command to the remote git repository. | +| `--git-remote` | string | Alternate git remote to push commits and tags to (can be useful for testing). (Default: `origin`) | | `--git-tag` | boolean | Whether or not to automatically tag the changes made by this command. | | `--git-tag-args` | string | Additional arguments to pass to the `git tag` command invoked behind the scenes. | | `--git-tag-message` | string | Custom git tag message to use when tagging the changes made by this command. This defaults to be the same value as the tag itself. | @@ -90,7 +92,8 @@ nx release changelog [version] | `--git-commit` | boolean | Whether or not to automatically commit the changes made by this command. | | `--git-commit-args` | string | Additional arguments (added after the --message argument, which may or may not be customized with --git-commit-message) to pass to the `git commit` command invoked behind the scenes. | | `--git-commit-message` | string | Custom git commit message to use when committing the changes made by this command. {version} will be dynamically interpolated when performing fixed releases, interpolated tags will be appended to the commit body when performing independent releases. | -| `--git-remote` | string | Alternate git remote in the form {user}/{repo} on which to create the Github release (useful for testing). (Default: `origin`) | +| `--git-push` | boolean | Whether or not to automatically push the changes made by this command to the remote git repository. | +| `--git-remote` | string | Alternate git remote to push commits and tags to (can be useful for testing). (Default: `origin`) | | `--git-tag` | boolean | Whether or not to automatically tag the changes made by this command. | | `--git-tag-args` | string | Additional arguments to pass to the `git tag` command invoked behind the scenes. | | `--git-tag-message` | string | Custom git tag message to use when tagging the changes made by this command. This defaults to be the same value as the tag itself. | diff --git a/docs/generated/packages/nx/documents/release.md b/docs/generated/packages/nx/documents/release.md index 08343d1fb55fe..6f9512b98c014 100644 --- a/docs/generated/packages/nx/documents/release.md +++ b/docs/generated/packages/nx/documents/release.md @@ -64,6 +64,8 @@ nx release version [specifier] | `--git-commit` | boolean | Whether or not to automatically commit the changes made by this command. | | `--git-commit-args` | string | Additional arguments (added after the --message argument, which may or may not be customized with --git-commit-message) to pass to the `git commit` command invoked behind the scenes. | | `--git-commit-message` | string | Custom git commit message to use when committing the changes made by this command. {version} will be dynamically interpolated when performing fixed releases, interpolated tags will be appended to the commit body when performing independent releases. | +| `--git-push` | boolean | Whether or not to automatically push the changes made by this command to the remote git repository. | +| `--git-remote` | string | Alternate git remote to push commits and tags to (can be useful for testing). (Default: `origin`) | | `--git-tag` | boolean | Whether or not to automatically tag the changes made by this command. | | `--git-tag-args` | string | Additional arguments to pass to the `git tag` command invoked behind the scenes. | | `--git-tag-message` | string | Custom git tag message to use when tagging the changes made by this command. This defaults to be the same value as the tag itself. | @@ -90,7 +92,8 @@ nx release changelog [version] | `--git-commit` | boolean | Whether or not to automatically commit the changes made by this command. | | `--git-commit-args` | string | Additional arguments (added after the --message argument, which may or may not be customized with --git-commit-message) to pass to the `git commit` command invoked behind the scenes. | | `--git-commit-message` | string | Custom git commit message to use when committing the changes made by this command. {version} will be dynamically interpolated when performing fixed releases, interpolated tags will be appended to the commit body when performing independent releases. | -| `--git-remote` | string | Alternate git remote in the form {user}/{repo} on which to create the Github release (useful for testing). (Default: `origin`) | +| `--git-push` | boolean | Whether or not to automatically push the changes made by this command to the remote git repository. | +| `--git-remote` | string | Alternate git remote to push commits and tags to (can be useful for testing). (Default: `origin`) | | `--git-tag` | boolean | Whether or not to automatically tag the changes made by this command. | | `--git-tag-args` | string | Additional arguments to pass to the `git tag` command invoked behind the scenes. | | `--git-tag-message` | string | Custom git tag message to use when tagging the changes made by this command. This defaults to be the same value as the tag itself. | diff --git a/e2e/release/src/create-github-release.test.ts b/e2e/release/src/create-github-release.test.ts index c00c90c652686..9ee45a66b828c 100644 --- a/e2e/release/src/create-github-release.test.ts +++ b/e2e/release/src/create-github-release.test.ts @@ -114,7 +114,8 @@ describe('nx release create github release', () => { const result = runCLI('release patch -d --first-release --verbose'); expect( - result.match(new RegExp(`NX Pushing to git remote`, 'g')).length + result.match(new RegExp(`NX Pushing to git remote "origin"`, 'g')) + .length ).toEqual(1); expect( result.match(new RegExp(`NX Creating GitHub Release`, 'g')).length @@ -148,7 +149,8 @@ describe('nx release create github release', () => { const result = runCLI('release -d --first-release --verbose'); expect( - result.match(new RegExp(`NX Pushing to git remote`, 'g')).length + result.match(new RegExp(`NX Pushing to git remote "origin"`, 'g')) + .length ).toEqual(1); expect( result.match(new RegExp(`NX Creating GitHub Release`, 'g')).length diff --git a/e2e/release/src/release.test.ts b/e2e/release/src/release.test.ts index 8cb139a05d848..32f15e23daea1 100644 --- a/e2e/release/src/release.test.ts +++ b/e2e/release/src/release.test.ts @@ -697,7 +697,7 @@ describe('nx release', () => { NX Tagging commit with git - NX Pushing to git remote + NX Pushing to git remote "origin" NX Creating GitHub Release diff --git a/packages/nx/src/command-line/release/changelog.ts b/packages/nx/src/command-line/release/changelog.ts index 2c38293e6af3b..7a12605dcca37 100644 --- a/packages/nx/src/command-line/release/changelog.ts +++ b/packages/nx/src/command-line/release/changelog.ts @@ -394,21 +394,7 @@ export function createAPI(overrideReleaseConfig: NxReleaseConfiguration) { args.createRelease ) ) { - let hasPushed = false; - postGitTasks.push(async (latestCommit) => { - if (!hasPushed) { - output.logSingleLine(`Pushing to git remote`); - - // Before we can create/update the release we need to ensure the commit exists on the remote - await gitPush({ - gitRemote: args.gitRemote, - dryRun: args.dryRun, - verbose: args.verbose, - }); - hasPushed = true; - } - output.logSingleLine(`Creating GitHub Release`); await createOrUpdateGithubRelease( @@ -617,7 +603,6 @@ export function createAPI(overrideReleaseConfig: NxReleaseConfiguration) { projectToAdditionalDependencyBumps, }); - let hasPushed = false; for (const [projectName, projectChangelog] of Object.entries( projectChangelogs )) { @@ -629,18 +614,6 @@ export function createAPI(overrideReleaseConfig: NxReleaseConfiguration) { ) ) { postGitTasks.push(async (latestCommit) => { - if (!hasPushed) { - output.logSingleLine(`Pushing to git remote`); - - // Before we can create/update the release we need to ensure the commit exists on the remote - await gitPush({ - gitRemote: args.gitRemote, - dryRun: args.dryRun, - verbose: args.verbose, - }); - hasPushed = true; - } - output.logSingleLine(`Creating GitHub Release`); await createOrUpdateGithubRelease( @@ -770,7 +743,6 @@ export function createAPI(overrideReleaseConfig: NxReleaseConfiguration) { projectToAdditionalDependencyBumps, }); - let hasPushed = false; for (const [projectName, projectChangelog] of Object.entries( projectChangelogs )) { @@ -782,18 +754,6 @@ export function createAPI(overrideReleaseConfig: NxReleaseConfiguration) { ) ) { postGitTasks.push(async (latestCommit) => { - if (!hasPushed) { - output.logSingleLine(`Pushing to git remote`); - - // Before we can create/update the release we need to ensure the commit exists on the remote - await gitPush({ - gitRemote: args.gitRemote, - dryRun: args.dryRun, - verbose: args.verbose, - }); - hasPushed = true; - } - output.logSingleLine(`Creating GitHub Release`); await createOrUpdateGithubRelease( @@ -1014,6 +974,15 @@ async function applyChangesAndExit( } } + if (args.gitPush ?? nxReleaseConfig.changelog.git.push) { + output.logSingleLine(`Pushing to git remote "${args.gitRemote}"`); + await gitPush({ + gitRemote: args.gitRemote, + dryRun: args.dryRun, + verbose: args.verbose, + }); + } + // Run any post-git tasks in series for (const postGitTask of postGitTasks) { await postGitTask(latestCommit); diff --git a/packages/nx/src/command-line/release/command-object.ts b/packages/nx/src/command-line/release/command-object.ts index f142fdab854c6..57f4e4016138c 100644 --- a/packages/nx/src/command-line/release/command-object.ts +++ b/packages/nx/src/command-line/release/command-object.ts @@ -25,7 +25,7 @@ export interface NxReleaseArgs extends BaseNxReleaseArgs { dryRun?: boolean; } -interface GitCommitAndTagOptions { +interface GitOptions { stageChanges?: boolean; gitCommit?: boolean; gitCommitMessage?: string; @@ -33,10 +33,12 @@ interface GitCommitAndTagOptions { gitTag?: boolean; gitTagMessage?: string; gitTagArgs?: string | string[]; + gitPush?: boolean; + gitRemote?: string; } export type VersionOptions = NxReleaseArgs & - GitCommitAndTagOptions & + GitOptions & VersionPlanArgs & FirstReleaseArgs & { specifier?: string; @@ -46,7 +48,7 @@ export type VersionOptions = NxReleaseArgs & }; export type ChangelogOptions = NxReleaseArgs & - GitCommitAndTagOptions & + GitOptions & VersionPlanArgs & FirstReleaseArgs & { // version and/or versionData must be set @@ -55,7 +57,6 @@ export type ChangelogOptions = NxReleaseArgs & to?: string; from?: string; interactive?: string; - gitRemote?: string; createRelease?: false | 'github'; }; @@ -222,7 +223,7 @@ const versionCommand: CommandModule = { 'Create a version and release for one or more applications and libraries.', builder: (yargs) => withFirstReleaseOptions( - withGitCommitAndGitTagOptions( + withGitOptions( yargs .positional('specifier', { type: 'string', @@ -260,7 +261,7 @@ const changelogCommand: CommandModule = { 'Generate a changelog for one or more projects, and optionally push to Github.', builder: (yargs) => withFirstReleaseOptions( - withGitCommitAndGitTagOptions( + withGitOptions( yargs // Disable default meaning of yargs version for this command .version(false) @@ -287,12 +288,6 @@ const changelogCommand: CommandModule = { 'Interactively modify changelog markdown contents in your code editor before applying the changes. You can set it to be interactive for all changelogs, or only the workspace level, or only the project level.', choices: ['all', 'workspace', 'projects'], }) - .option('git-remote', { - type: 'string', - description: - 'Alternate git remote in the form {user}/{repo} on which to create the Github release (useful for testing).', - default: 'origin', - }) .check((argv) => { if (!argv.version) { throw new Error( @@ -415,9 +410,7 @@ function coerceParallelOption(args: any) { }; } -function withGitCommitAndGitTagOptions( - yargs: Argv -): Argv { +function withGitOptions(yargs: Argv): Argv { return yargs .option('git-commit', { describe: @@ -453,6 +446,17 @@ function withGitCommitAndGitTagOptions( describe: 'Whether or not to stage the changes made by this command. Always treated as true if git-commit is true.', type: 'boolean', + }) + .option('git-push', { + describe: + 'Whether or not to automatically push the changes made by this command to the remote git repository.', + type: 'boolean', + }) + .option('git-remote', { + type: 'string', + description: + 'Alternate git remote to push commits and tags to (can be useful for testing).', + default: 'origin', }); } 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 7c75ef51d7373..4216e0349caeb 100644 --- a/packages/nx/src/command-line/release/config/config.spec.ts +++ b/packages/nx/src/command-line/release/config/config.spec.ts @@ -137,6 +137,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -255,6 +256,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -289,6 +291,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -313,6 +316,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -431,6 +435,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -465,6 +470,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -492,6 +498,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -610,6 +617,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -644,6 +652,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -702,6 +711,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -820,6 +830,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -854,6 +865,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -896,6 +908,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -1014,6 +1027,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -1048,6 +1062,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -1099,6 +1114,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -1217,6 +1233,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -1250,6 +1267,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -1300,6 +1318,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -1418,6 +1437,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -1453,6 +1473,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -1486,6 +1507,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -1604,6 +1626,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -1636,6 +1659,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -1667,6 +1691,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -1785,6 +1810,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -1818,6 +1844,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -1861,6 +1888,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -1968,6 +1996,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -2017,6 +2046,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -2049,6 +2079,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -2167,6 +2198,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -2210,6 +2242,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -2247,6 +2280,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -2354,6 +2388,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -2423,6 +2458,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -2457,6 +2493,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -2564,6 +2601,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -2608,6 +2646,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -2642,6 +2681,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -2760,6 +2800,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -2798,6 +2839,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -2828,6 +2870,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "--no-verify", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -2946,6 +2989,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "--no-verify", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -2980,6 +3024,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "--no-verify", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -3013,6 +3058,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -3131,6 +3177,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -3165,6 +3212,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "--no-verify", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": true, "tagArgs": "", @@ -3194,6 +3242,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -3312,6 +3361,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -3346,6 +3396,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -3380,6 +3431,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -3498,6 +3550,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -3530,6 +3583,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -3579,6 +3633,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -3697,6 +3752,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -3729,6 +3785,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -3758,6 +3815,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -3876,6 +3934,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -3910,6 +3969,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -3949,6 +4009,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -4067,6 +4128,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -4113,6 +4175,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -4145,6 +4208,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -4252,6 +4316,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -4286,6 +4351,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -4326,6 +4392,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -4455,6 +4522,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -4500,6 +4568,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -4530,6 +4599,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -4659,6 +4729,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -4704,6 +4775,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -4734,6 +4806,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -4852,6 +4925,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -4886,6 +4960,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -4920,6 +4995,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": true, "stageChanges": false, "tag": true, "tagArgs": "", @@ -5042,6 +5118,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -5076,6 +5153,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -5111,6 +5189,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": true, "stageChanges": false, "tag": true, "tagArgs": "", @@ -5233,6 +5312,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -5267,6 +5347,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -5364,6 +5445,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": true, "stageChanges": false, "tag": true, "tagArgs": "", @@ -5486,6 +5568,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -5535,6 +5618,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -5571,6 +5655,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": true, "stageChanges": false, "tag": true, "tagArgs": "", @@ -5693,6 +5778,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -5742,6 +5828,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -5816,6 +5903,134 @@ describe('createNxReleaseConfig()', () => { } `); }); + + it('should return an error if createRelease is enabled but git push is explicitly disabled', async () => { + const res = await createNxReleaseConfig(projectGraph, projectFileMap, { + changelog: { + workspaceChangelog: { + createRelease: 'github', + }, + }, + git: { + push: false, + }, + }); + expect(res.error).toMatchInlineSnapshot(` + { + "code": "GIT_PUSH_FALSE_WITH_CREATE_RELEASE", + "data": {}, + } + `); + + const res2 = await createNxReleaseConfig(projectGraph, projectFileMap, { + changelog: { + git: { + push: false, + }, + workspaceChangelog: { + createRelease: 'github', + }, + }, + }); + expect(res2.error).toMatchInlineSnapshot(` + { + "code": "GIT_PUSH_FALSE_WITH_CREATE_RELEASE", + "data": {}, + } + `); + + const res3 = await createNxReleaseConfig(projectGraph, projectFileMap, { + changelog: { + projectChangelogs: { + createRelease: 'github', + }, + }, + git: { + push: false, + }, + }); + expect(res3.error).toMatchInlineSnapshot(` + { + "code": "GIT_PUSH_FALSE_WITH_CREATE_RELEASE", + "data": {}, + } + `); + + const res4 = await createNxReleaseConfig(projectGraph, projectFileMap, { + changelog: { + git: { + push: false, + }, + projectChangelogs: { + createRelease: 'github', + }, + }, + }); + expect(res4.error).toMatchInlineSnapshot(` + { + "code": "GIT_PUSH_FALSE_WITH_CREATE_RELEASE", + "data": {}, + } + `); + + const res5 = await createNxReleaseConfig(projectGraph, projectFileMap, { + changelog: { + workspaceChangelog: { + createRelease: 'github', + }, + }, + version: { + git: { + push: false, + }, + }, + }); + expect(res5.error).toMatchInlineSnapshot(` + { + "code": "GIT_PUSH_FALSE_WITH_CREATE_RELEASE", + "data": {}, + } + `); + + const res6 = await createNxReleaseConfig(projectGraph, projectFileMap, { + changelog: { + projectChangelogs: { + createRelease: 'github', + }, + }, + version: { + git: { + push: false, + }, + }, + }); + expect(res6.error).toMatchInlineSnapshot(` + { + "code": "GIT_PUSH_FALSE_WITH_CREATE_RELEASE", + "data": {}, + } + `); + + const res7 = await createNxReleaseConfig(projectGraph, projectFileMap, { + groups: { + 'group-1': { + projects: ['lib-a'], + changelog: { + createRelease: 'github', + }, + }, + }, + git: { + push: false, + }, + }); + expect(res7.error).toMatchInlineSnapshot(` + { + "code": "GIT_PUSH_FALSE_WITH_CREATE_RELEASE", + "data": {}, + } + `); + }); }); describe('user config -> top level conventional commits configuration', () => { @@ -5834,6 +6049,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -5952,6 +6168,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -5986,6 +6203,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -6014,6 +6232,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -6132,6 +6351,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -6166,6 +6386,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -6216,6 +6437,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -6348,6 +6570,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -6382,6 +6605,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -6415,6 +6639,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -6540,6 +6765,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -6574,6 +6800,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -6610,6 +6837,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -6735,6 +6963,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -6769,6 +6998,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -6806,6 +7036,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -6931,6 +7162,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -6965,6 +7197,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -7005,6 +7238,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -7130,6 +7364,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -7164,6 +7399,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -7223,6 +7459,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": true, "stageChanges": false, "tag": true, "tagArgs": "", @@ -7341,6 +7578,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -7429,6 +7667,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -7471,6 +7710,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": true, "stageChanges": false, "tag": true, "tagArgs": "", @@ -7608,6 +7848,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -7655,6 +7896,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -7713,6 +7955,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": true, "stageChanges": false, "tag": true, "tagArgs": "", @@ -7831,6 +8074,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -7878,6 +8122,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -7917,6 +8162,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": true, "stageChanges": false, "tag": true, "tagArgs": "", @@ -8035,6 +8281,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -8082,6 +8329,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -8354,6 +8602,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -8472,6 +8721,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -8506,6 +8756,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -8728,6 +8979,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -8835,6 +9087,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -8883,6 +9136,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -8912,6 +9166,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -9019,6 +9274,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -9052,6 +9308,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -9086,6 +9343,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -9204,6 +9462,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -9244,6 +9503,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -9274,6 +9534,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -9392,6 +9653,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -9432,6 +9694,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -9461,6 +9724,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -9579,6 +9843,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -9619,6 +9884,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -9656,6 +9922,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -9774,6 +10041,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -9809,6 +10077,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -9841,6 +10110,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -9959,6 +10229,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -10001,6 +10272,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -10073,6 +10345,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -10191,6 +10464,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -10229,6 +10503,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -10261,6 +10536,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -10379,6 +10655,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -10421,6 +10698,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -10466,6 +10744,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -10573,6 +10852,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -10622,6 +10902,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -10663,6 +10944,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -10770,6 +11052,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -10823,6 +11106,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -10864,6 +11148,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -10971,6 +11256,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -11022,6 +11308,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", @@ -11065,6 +11352,7 @@ describe('createNxReleaseConfig()', () => { "commit": true, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": true, "tagArgs": "", @@ -11172,6 +11460,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": false, "tag": false, "tagArgs": "", @@ -11227,6 +11516,7 @@ describe('createNxReleaseConfig()', () => { "commit": false, "commitArgs": "", "commitMessage": "chore(release): publish {version}", + "push": false, "stageChanges": true, "tag": false, "tagArgs": "", diff --git a/packages/nx/src/command-line/release/config/config.ts b/packages/nx/src/command-line/release/config/config.ts index 8bf907ddd31b4..282809be33fc8 100644 --- a/packages/nx/src/command-line/release/config/config.ts +++ b/packages/nx/src/command-line/release/config/config.ts @@ -110,7 +110,8 @@ export interface CreateNxReleaseConfigError { | 'CANNOT_RESOLVE_CHANGELOG_RENDERER' | 'INVALID_CHANGELOG_CREATE_RELEASE_PROVIDER' | 'INVALID_CHANGELOG_CREATE_RELEASE_HOSTNAME' - | 'INVALID_CHANGELOG_CREATE_RELEASE_API_BASE_URL'; + | 'INVALID_CHANGELOG_CREATE_RELEASE_API_BASE_URL' + | 'GIT_PUSH_FALSE_WITH_CREATE_RELEASE'; data: Record; } @@ -161,20 +162,66 @@ export async function createNxReleaseConfig( tagMessage: '', tagArgs: '', stageChanges: false, + push: false, }; const versionGitDefaults = { ...gitDefaults, stageChanges: true, }; + + const isObjectWithCreateReleaseEnabled = (data: unknown) => + typeof data === 'object' && + data !== null && + 'createRelease' in data && + (typeof data.createRelease === 'string' || + (typeof data.createRelease === 'object' && data.createRelease !== null)); + + const isCreateReleaseEnabledAtTheRoot = isObjectWithCreateReleaseEnabled( + userConfig.changelog?.workspaceChangelog + ); + + const isCreateReleaseEnabledForProjectChangelogs = + // At the root + isObjectWithCreateReleaseEnabled(userConfig.changelog?.projectChangelogs) || + // Or any release group + Object.values(userConfig.groups ?? {}).some((group) => + isObjectWithCreateReleaseEnabled(group.changelog) + ); + + const isGitPushExplicitlyDisabled = + userConfig.git?.push === false || + userConfig.changelog?.git?.push === false || + userConfig.version?.git?.push === false; + + if ( + isGitPushExplicitlyDisabled && + (isCreateReleaseEnabledAtTheRoot || + isCreateReleaseEnabledForProjectChangelogs) + ) { + return { + error: { + code: 'GIT_PUSH_FALSE_WITH_CREATE_RELEASE', + data: {}, + }, + nxReleaseConfig: null, + }; + } + const changelogGitDefaults = { ...gitDefaults, commit: true, tag: true, + push: + // We have to perform a git push in order to create a release + isCreateReleaseEnabledAtTheRoot || + isCreateReleaseEnabledForProjectChangelogs + ? true + : false, }; const defaultFixedReleaseTagPattern = 'v{version}'; /** - * TODO: in v20, make it so that this pattern is used by default when any custom groups are used + * TODO(v21): in v21, make it so that this pattern is used by default when any custom groups are used */ const defaultFixedGroupReleaseTagPattern = '{releaseGroupName}-v{version}'; const defaultIndependentReleaseTagPattern = '{projectName}@{version}'; @@ -820,6 +867,19 @@ export async function handleNxReleaseConfigError( }); } break; + case 'GIT_PUSH_FALSE_WITH_CREATE_RELEASE': + { + const nxJsonMessage = await resolveNxJsonConfigErrorMessage([ + 'release', + 'changelog', + 'git', + ]); + output.error({ + title: `The git configuration for createRelease is invalid. Please ensure that git.push is enabled when createRelease is configured:`, + bodyLines: [nxJsonMessage], + }); + } + break; default: throw new Error(`Unhandled error code: ${error.code}`); } 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 12d0ec341e7b6..c95f8ac695cd3 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 @@ -20,6 +20,7 @@ describe('filterReleaseGroups()', () => { tagMessage: '', tagArgs: '', stageChanges: false, + push: false, }, workspaceChangelog: false, projectChangelogs: false, @@ -37,6 +38,7 @@ describe('filterReleaseGroups()', () => { tag: false, tagMessage: '', tagArgs: '', + push: false, }, preVersionCommand: '', }, @@ -49,6 +51,7 @@ describe('filterReleaseGroups()', () => { tagMessage: '', tagArgs: '', stageChanges: false, + push: false, }, conventionalCommits: DEFAULT_CONVENTIONAL_COMMITS_CONFIG, versionPlans: false, diff --git a/packages/nx/src/command-line/release/release.ts b/packages/nx/src/command-line/release/release.ts index 064cc46b8804e..f5e63992efe0e 100644 --- a/packages/nx/src/command-line/release/release.ts +++ b/packages/nx/src/command-line/release/release.ts @@ -90,6 +90,21 @@ export function createAPI(overrideReleaseConfig: NxReleaseConfiguration) { }); } + const { + error: filterError, + releaseGroups, + releaseGroupToFilteredProjects, + } = filterReleaseGroups( + projectGraph, + nxReleaseConfig, + args.projects, + args.groups + ); + if (filterError) { + output.error(filterError); + process.exit(1); + } + const rawVersionPlans = await readRawVersionPlans(); if (args.specifier && rawVersionPlans.length > 0) { @@ -109,6 +124,17 @@ export function createAPI(overrideReleaseConfig: NxReleaseConfiguration) { (shouldCommit || userProvidedReleaseConfig.git?.stageChanges) ?? false; const shouldTag = userProvidedReleaseConfig.git?.tag ?? true; + const shouldCreateWorkspaceRelease = shouldCreateGitHubRelease( + nxReleaseConfig.changelog.workspaceChangelog + ); + // If the workspace or any of the release groups specify that a github release should be created, we need to push the changes to the remote + const shouldPush = + (shouldCreateWorkspaceRelease || + releaseGroups.some((group) => + shouldCreateGitHubRelease(group.changelog) + )) ?? + false; + const versionResult: NxReleaseVersionResult = await releaseVersion({ ...args, stageChanges: shouldStage, @@ -124,25 +150,11 @@ export function createAPI(overrideReleaseConfig: NxReleaseConfiguration) { stageChanges: shouldStage, gitCommit: false, gitTag: false, + gitPush: false, createRelease: false, deleteVersionPlans: false, }); - const { - error: filterError, - releaseGroups, - releaseGroupToFilteredProjects, - } = filterReleaseGroups( - projectGraph, - nxReleaseConfig, - args.projects, - args.groups - ); - if (filterError) { - output.error(filterError); - process.exit(1); - } - await setResolvedVersionPlansOnGroups( rawVersionPlans, releaseGroups, @@ -230,23 +242,24 @@ export function createAPI(overrideReleaseConfig: NxReleaseConfiguration) { } } - const shouldCreateWorkspaceRelease = shouldCreateGitHubRelease( - nxReleaseConfig.changelog.workspaceChangelog - ); - let hasPushedChanges = false; - let latestCommit: string | undefined; - - if (shouldCreateWorkspaceRelease && changelogResult.workspaceChangelog) { - output.logSingleLine(`Pushing to git remote`); - - // Before we can create/update the release we need to ensure the commit exists on the remote + if (shouldPush) { + output.logSingleLine(`Pushing to git remote "origin"`); await gitPush({ dryRun: args.dryRun, verbose: args.verbose, }); - hasPushedChanges = true; + } + + let latestCommit: string | undefined; + + if (shouldCreateWorkspaceRelease && changelogResult.workspaceChangelog) { + if (!hasPushedChanges) { + throw new Error( + 'It is not possible to create a github release for the workspace without pushing the changes to the remote, please ensure that you have not disabled git push in your nx release config' + ); + } output.logSingleLine(`Creating GitHub Release`); @@ -282,15 +295,9 @@ export function createAPI(overrideReleaseConfig: NxReleaseConfiguration) { } if (!hasPushedChanges) { - output.logSingleLine(`Pushing to git remote`); - - // Before we can create/update the release we need to ensure the commit exists on the remote - await gitPush({ - dryRun: args.dryRun, - verbose: args.verbose, - }); - - hasPushedChanges = true; + throw new Error( + 'It is not possible to create a github release for the project without pushing the changes to the remote, please ensure that you have not disabled git push in your nx release config' + ); } output.logSingleLine(`Creating GitHub Release`); diff --git a/packages/nx/src/command-line/release/version.ts b/packages/nx/src/command-line/release/version.ts index 2a7dfd7f8c53f..647232dede0e2 100644 --- a/packages/nx/src/command-line/release/version.ts +++ b/packages/nx/src/command-line/release/version.ts @@ -40,7 +40,7 @@ import { setResolvedVersionPlansOnGroups, } from './config/version-plans'; import { batchProjectsByGeneratorConfig } from './utils/batch-projects-by-generator-config'; -import { gitAdd, gitTag } from './utils/git'; +import { gitAdd, gitPush, gitTag } from './utils/git'; import { printDiff } from './utils/print-changes'; import { printConfigAndExit } from './utils/print-config'; import { resolveNxJsonConfigErrorMessage } from './utils/resolve-nx-json-error-message'; @@ -370,6 +370,15 @@ export function createAPI(overrideReleaseConfig: NxReleaseConfiguration) { } } + if (args.gitPush ?? nxReleaseConfig.version.git.push) { + output.logSingleLine(`Pushing to git remote "${args.gitRemote}"`); + await gitPush({ + gitRemote: args.gitRemote, + dryRun: args.dryRun, + verbose: args.verbose, + }); + } + return { // An overall workspace version cannot be relevant when filtering to independent projects workspaceVersion: undefined, diff --git a/packages/nx/src/config/nx-json.ts b/packages/nx/src/config/nx-json.ts index bcb976348feb8..d2e888863b360 100644 --- a/packages/nx/src/config/nx-json.ts +++ b/packages/nx/src/config/nx-json.ts @@ -149,9 +149,13 @@ export interface NxReleaseGitConfiguration { */ tagMessage?: string; /** - * Additional arguments to pass to the `git tag` command invoked behind the scenes. . May be a string or array of strings. + * Additional arguments to pass to the `git tag` command invoked behind the scenes. May be a string or array of strings. */ tagArgs?: string | string[]; + /** + * Whether or not to automatically push the changes made by this command to the remote git repository. + */ + push?: boolean; } export interface NxReleaseConventionalCommitsConfiguration {