From 02f087e258490495010ab765a048a20dc2c6859b Mon Sep 17 00:00:00 2001 From: Dhaya <154633+dhayab@users.noreply.github.com> Date: Tue, 21 Jun 2022 17:53:34 +0200 Subject: [PATCH 1/4] fix(release): rebase before pushing local branch and tag --- packages/shipjs/src/flow/release.js | 5 ++++- packages/shipjs/src/step/fetchAndRebase.js | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 packages/shipjs/src/step/fetchAndRebase.js diff --git a/packages/shipjs/src/flow/release.js b/packages/shipjs/src/flow/release.js index 2f69598d9..b2b57faed 100644 --- a/packages/shipjs/src/flow/release.js +++ b/packages/shipjs/src/flow/release.js @@ -1,4 +1,4 @@ -import { loadConfig } from 'shipjs-lib'; +import { getCurrentBranch, loadConfig } from 'shipjs-lib'; import printHelp from '../step/release/printHelp'; import printDryRunBanner from '../step/printDryRunBanner'; @@ -15,6 +15,7 @@ import createGitHubRelease from '../step/release/createGitHubRelease'; import notifyReleaseSuccess from '../step/release/notifyReleaseSuccess'; import checkGitHubToken from '../step/checkGitHubToken'; import finished from '../step/release/finished'; +import fetchAndRebase from '../step/fetchAndRebase'; import { detectYarn } from '../util'; async function release({ help = false, dir = '.', dryRun = false }) { @@ -43,6 +44,8 @@ async function release({ help = false, dir = '.', dryRun = false }) { runPublish({ isYarn, config, releaseTag, dir, dryRun }); await runAfterPublish({ version, releaseTag, config, dir, dryRun }); const { tagName } = createGitTag({ version, config, dir, dryRun }); + const currentBranch = getCurrentBranch(dir); + await fetchAndRebase({ remote, currentBranch, dir, dryRun }); gitPush({ tagName, config, dir, dryRun }); await createGitHubRelease({ version, config, dir, dryRun }); await notifyReleaseSuccess({ diff --git a/packages/shipjs/src/step/fetchAndRebase.js b/packages/shipjs/src/step/fetchAndRebase.js new file mode 100644 index 000000000..1ee80840f --- /dev/null +++ b/packages/shipjs/src/step/fetchAndRebase.js @@ -0,0 +1,11 @@ +import runStep from './runStep'; +import { run } from '../util'; + +export default ({ remote, currentBranch, dir, dryRun }) => + runStep({ title: 'Rebasing.' }, () => { + run({ + command: `git fetch && git rebase ${remote}/${currentBranch} ${currentBranch}`, + dir, + dryRun, + }); + }); From 3c5df944017f8fd78d7f21451d6146d1b8d45be2 Mon Sep 17 00:00:00 2001 From: Dhaya <154633+dhayab@users.noreply.github.com> Date: Tue, 21 Jun 2022 19:17:44 +0200 Subject: [PATCH 2/4] use modified pull function with --rebase flag --- packages/shipjs/src/flow/release.js | 4 ++-- packages/shipjs/src/step/fetchAndRebase.js | 11 ----------- packages/shipjs/src/step/pull.js | 10 ++++++++-- 3 files changed, 10 insertions(+), 15 deletions(-) delete mode 100644 packages/shipjs/src/step/fetchAndRebase.js diff --git a/packages/shipjs/src/flow/release.js b/packages/shipjs/src/flow/release.js index b2b57faed..31e97a599 100644 --- a/packages/shipjs/src/flow/release.js +++ b/packages/shipjs/src/flow/release.js @@ -15,7 +15,7 @@ import createGitHubRelease from '../step/release/createGitHubRelease'; import notifyReleaseSuccess from '../step/release/notifyReleaseSuccess'; import checkGitHubToken from '../step/checkGitHubToken'; import finished from '../step/release/finished'; -import fetchAndRebase from '../step/fetchAndRebase'; +import pull from '../step/pull'; import { detectYarn } from '../util'; async function release({ help = false, dir = '.', dryRun = false }) { @@ -45,7 +45,7 @@ async function release({ help = false, dir = '.', dryRun = false }) { await runAfterPublish({ version, releaseTag, config, dir, dryRun }); const { tagName } = createGitTag({ version, config, dir, dryRun }); const currentBranch = getCurrentBranch(dir); - await fetchAndRebase({ remote, currentBranch, dir, dryRun }); + pull({ remote, currentBranch, dir, dryRun, rebase: true }); gitPush({ tagName, config, dir, dryRun }); await createGitHubRelease({ version, config, dir, dryRun }); await notifyReleaseSuccess({ diff --git a/packages/shipjs/src/step/fetchAndRebase.js b/packages/shipjs/src/step/fetchAndRebase.js deleted file mode 100644 index 1ee80840f..000000000 --- a/packages/shipjs/src/step/fetchAndRebase.js +++ /dev/null @@ -1,11 +0,0 @@ -import runStep from './runStep'; -import { run } from '../util'; - -export default ({ remote, currentBranch, dir, dryRun }) => - runStep({ title: 'Rebasing.' }, () => { - run({ - command: `git fetch && git rebase ${remote}/${currentBranch} ${currentBranch}`, - dir, - dryRun, - }); - }); diff --git a/packages/shipjs/src/step/pull.js b/packages/shipjs/src/step/pull.js index 52792055e..d8675183f 100644 --- a/packages/shipjs/src/step/pull.js +++ b/packages/shipjs/src/step/pull.js @@ -1,7 +1,13 @@ import runStep from './runStep'; import { run } from '../util'; -export default ({ remote, currentBranch, dir, dryRun }) => +export default ({ remote, currentBranch, dir, dryRun, rebase = false }) => runStep({ title: 'Updating from remote.' }, () => { - run({ command: `git pull ${remote} ${currentBranch}`, dir, dryRun }); + run({ + command: `git pull${ + rebase ? ' --rebase' : '' + } ${remote} ${currentBranch}`, + dir, + dryRun, + }); }); From 26a4c1250b517d1f64ee1a081233a3142331366e Mon Sep 17 00:00:00 2001 From: Dhaya <154633+dhayab@users.noreply.github.com> Date: Tue, 21 Jun 2022 19:59:14 +0200 Subject: [PATCH 3/4] add basic unit test for pull function --- .../shipjs/src/step/__tests__/pull.spec.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 packages/shipjs/src/step/__tests__/pull.spec.js diff --git a/packages/shipjs/src/step/__tests__/pull.spec.js b/packages/shipjs/src/step/__tests__/pull.spec.js new file mode 100644 index 000000000..a71f8788f --- /dev/null +++ b/packages/shipjs/src/step/__tests__/pull.spec.js @@ -0,0 +1,27 @@ +import { run } from '../../util'; +import pull from '../pull'; + +const remote = 'origin-with-token'; +const currentBranch = 'main'; + +describe('pull', () => { + it('works', () => { + pull({ remote, currentBranch, dir: '.', dryRun: false }); + expect(run).toHaveBeenCalledTimes(1); + expect(run).toHaveBeenCalledWith({ + command: 'git pull origin-with-token main', + dir: '.', + dryRun: false, + }); + }); + + it('works with rebase flag', () => { + pull({ remote, currentBranch, dir: '.', dryRun: false, rebase: true }); + expect(run).toHaveBeenCalledTimes(1); + expect(run).toHaveBeenCalledWith({ + command: 'git pull --rebase origin-with-token main', + dir: '.', + dryRun: false, + }); + }); +}); From 1a9d991613a3c4b6d236deedfe7c6c24eff919d4 Mon Sep 17 00:00:00 2001 From: Dhaya <154633+dhayab@users.noreply.github.com> Date: Mon, 27 Jun 2022 17:18:25 +0200 Subject: [PATCH 4/4] allow any option to be passed to pull method --- packages/shipjs/src/step/__tests__/pull.spec.js | 10 ++++++++-- packages/shipjs/src/step/pull.js | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/shipjs/src/step/__tests__/pull.spec.js b/packages/shipjs/src/step/__tests__/pull.spec.js index a71f8788f..9ac4d8d96 100644 --- a/packages/shipjs/src/step/__tests__/pull.spec.js +++ b/packages/shipjs/src/step/__tests__/pull.spec.js @@ -15,8 +15,14 @@ describe('pull', () => { }); }); - it('works with rebase flag', () => { - pull({ remote, currentBranch, dir: '.', dryRun: false, rebase: true }); + it('works with rebase option', () => { + pull({ + remote, + currentBranch, + dir: '.', + dryRun: false, + options: '--rebase', + }); expect(run).toHaveBeenCalledTimes(1); expect(run).toHaveBeenCalledWith({ command: 'git pull --rebase origin-with-token main', diff --git a/packages/shipjs/src/step/pull.js b/packages/shipjs/src/step/pull.js index d8675183f..9474a1a44 100644 --- a/packages/shipjs/src/step/pull.js +++ b/packages/shipjs/src/step/pull.js @@ -1,11 +1,11 @@ import runStep from './runStep'; import { run } from '../util'; -export default ({ remote, currentBranch, dir, dryRun, rebase = false }) => +export default ({ remote, currentBranch, dir, dryRun, options }) => runStep({ title: 'Updating from remote.' }, () => { run({ command: `git pull${ - rebase ? ' --rebase' : '' + options ? ` ${options.trim()}` : '' } ${remote} ${currentBranch}`, dir, dryRun,