From b283671ee92d0c196519f83acfa4bdb28a9e911b Mon Sep 17 00:00:00 2001 From: JamesHenry Date: Tue, 10 Dec 2024 13:12:42 +0400 Subject: [PATCH] feat(release): allow automated git push from version or changelog step --- docs/generated/cli/release.md | 5 +- .../packages/nx/documents/release.md | 5 +- .../nx/src/command-line/release/changelog.ts | 49 +-- .../command-line/release/command-object.ts | 34 +- .../release/config/config.spec.ts | 290 ++++++++++++++++++ .../src/command-line/release/config/config.ts | 63 +++- .../nx/src/command-line/release/version.ts | 11 +- packages/nx/src/config/nx-json.ts | 6 +- 8 files changed, 402 insertions(+), 61 deletions(-) diff --git a/docs/generated/cli/release.md b/docs/generated/cli/release.md index 08343d1fb55fe7..6f9512b98c014c 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 08343d1fb55fe7..6f9512b98c014c 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/packages/nx/src/command-line/release/changelog.ts b/packages/nx/src/command-line/release/changelog.ts index 2c38293e6af3b9..7a12605dcca377 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 f142fdab854c6e..57f4e4016138c7 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 7c75ef51d7373a..ccd665eaceca11 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": true, "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 8bf907ddd31b4c..544f126e886960 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,65 @@ export async function createNxReleaseConfig( tagMessage: '', tagArgs: '', stageChanges: false, + push: false, }; const versionGitDefaults = { ...gitDefaults, stageChanges: true, }; + + const isCreateReleaseEnabledAtTheRoot = + userConfig.changelog?.workspaceChangelog && + typeof userConfig.changelog.workspaceChangelog === 'object' && + userConfig.changelog.workspaceChangelog.createRelease !== false; + + const isCreateReleaseEnabledForProjectChangelogs = + // At the root + (userConfig.changelog?.projectChangelogs && + typeof userConfig.changelog.projectChangelogs === 'object' && + userConfig.changelog.projectChangelogs.createRelease !== false) || + // Or any release group + Object.values(userConfig.groups ?? {}).some( + (group) => + group.changelog && + typeof group.changelog === 'object' && + group.changelog.createRelease !== false + ); + + 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 +866,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/version.ts b/packages/nx/src/command-line/release/version.ts index 2a7dfd7f8c53f0..647232dede0e25 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 bcb976348feb8d..d2e888863b3609 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 {