diff --git a/packages/semver/src/builders/version/builder.spec.ts b/packages/semver/src/builders/version/builder.spec.ts index 072a9ec6b..1904409ed 100644 --- a/packages/semver/src/builders/version/builder.spec.ts +++ b/packages/semver/src/builders/version/builder.spec.ts @@ -63,7 +63,6 @@ describe('@jscutlery/semver:version', () => { expect.arrayContaining([ 'push', '--follow-tags', - '--no-verify', '--atomic', 'origin', 'main', @@ -71,6 +70,30 @@ describe('@jscutlery/semver:version', () => { ); }); + it(`should push to Git and add '--no-verify' option when asked for`, async () => { + await runBuilder( + { + ...options, + push: true, + remote: 'origin', + baseBranch: 'main', + noVerify: true, + }, + context + ).toPromise(); + + expect(childProcess.exec).toHaveBeenCalledWith( + 'git', + expect.arrayContaining([ + 'push', + '--follow-tags', + '--no-verify', + '--atomic', + 'origin', + 'main', + ]) + ); + }); it('should fail if Git config is missing', async () => { const output = await runBuilder( { ...options, push: true, remote: undefined, baseBranch: null }, diff --git a/packages/semver/src/builders/version/builder.ts b/packages/semver/src/builders/version/builder.ts index 3b40ed933..52a2f1185 100644 --- a/packages/semver/src/builders/version/builder.ts +++ b/packages/semver/src/builders/version/builder.ts @@ -17,21 +17,31 @@ async function getProjectRoot(context: BuilderContext): Promise { return metadata.root as string; } -function pushToGitRemote( - remote: string, - branch: string, - context: BuilderContext -): Rule { +function pushToGitRemote({ + remote, + branch, + context, + noVerify, +}: { + remote: string; + branch: string; + context: BuilderContext; + noVerify: boolean; +}): Rule { if (remote == null || branch == null) { throw new Error( 'Missing configuration for Git push, please provide --remote and --branch options' ); } + const gitPushOptions = [ + '--follow-tags', + ...(noVerify ? ['--no-verify'] : []), + ]; + return exec('git', [ 'push', - '--follow-tags', - '--no-verify', + ...gitPushOptions, '--atomic', remote, branch, @@ -51,13 +61,7 @@ function pushToGitRemote( 'git push --atomic failed, attempting non-atomic push' ); - return exec('git', [ - 'push', - '--follow-tags', - '--no-verify', - remote, - branch, - ]); + return exec('git', ['push', ...gitPushOptions, remote, branch]); } // ensure unexpected errors still break chain @@ -85,7 +89,12 @@ export function runBuilder( options.push && options.dryRun === false ? switchMapTo( defer(() => - pushToGitRemote(options.remote, options.baseBranch, context) + pushToGitRemote({ + remote: options.remote, + branch: options.baseBranch, + context, + noVerify: options.noVerify, + }) ) ) : mapTo(noop()),