Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(release): rebase before pushing local branch and tag #983

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

dhayab
Copy link
Member

@dhayab dhayab commented Jun 21, 2022

Summary

On rare occasions, the release process orchestrated by Ship.js cannot be completed if the local main branch and its remote counterpart are not in sync, when an unrelated PR is merged just after a release is started for instance (see one example of such issue).

This is not critical, but it can be a bother as the latest git tag won't be pushed to the remote, and the releases list on GitHub will not be updated too.

This PR addresses the issue by performing a rebase onto the main branch in order to sync them before performing the git tag operation.

Result

The release flow should now be more resilient to this kind of issue.

Note
I could not find a way to integrate a test for this addition. Let me know if you have any guidance for that 馃檹 .

Copy link
Member

@sarahdayan sarahdayan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the Git stuff lives in shipjs-lib and is tested there.

It could be better to have your command there and tested the same way, and here only test the flow.

export default ({ remote, currentBranch, dir, dryRun }) =>
runStep({ title: 'Rebasing.' }, () => {
run({
command: `git fetch && git rebase ${remote}/${currentBranch} ${currentBranch}`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe git fetch && git rebase can be replaced with git pull --rebase.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works indeed, thanks! I removed the fetchAndRebase function and replaced it with the existing pull function with an additional flag for --rebase.

As for the location of git operations, what I'm seeing is that most/all the methods that gather information on git repositories are indeed in shipjs-lib, but the methods used to actually perform git operations are in shipjs, for instance:

  • gitPush in shipjs/src/helper
  • pull in shipjs/src/step

For testing, apart from empirical testing which was done with a dummy repository, there is no flow test I could hook into or a way to simulate changes on a remote repository, or an individual test on the pull function. I added basic tests that verify the command is well-formed similarly to other steps / helpers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be done later, but we could add integration tests for the full flow. We create a fake project in which Ship.js is a dependency (like any of our repos) and perform flows with a mocked CI.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked a bit further and there's a workflow similar to this in packages/shipjs-lib/tests with shell scripts bootstrapping mock repositories. This could be reused for packages/shipjs probably.

I won't be able to put more time on it during this sprint, so we can do it later or keep this PR open and add it here next sprint, both are fine for me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Can you just add a ticket in Jira to track it?

@@ -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 }) =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or allow more flexibility and pass any flag?

@@ -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);
pull({ remote, currentBranch, dir, dryRun, rebase: true });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be updated to pass options instead, no?

@dhayab dhayab marked this pull request as draft March 15, 2023 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants