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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abort release if new commits detected upstream #1418

Closed
hipstersmoothie opened this issue Jul 30, 2020 · 13 comments
Closed

Abort release if new commits detected upstream #1418

hipstersmoothie opened this issue Jul 30, 2020 · 13 comments
Labels
bug Something isn't working

Comments

@hipstersmoothie
Copy link
Collaborator

Is your feature request related to a problem? Please describe.

When running auto shipit from master which is not at the same commit of the remote an error will occur when the version bump and changelog commits are pushed.

Describe the solution you'd like

Detect the issue prior to git and give an instructive error.

Describe alternatives you've considered

Checkout the local baseBranch and git pull from remote.

@hipstersmoothie hipstersmoothie added the bug Something isn't working label Jul 30, 2020
@hipstersmoothie
Copy link
Collaborator Author

@jrschumacher I recreated the issue without the screenshot of the leaked token. Forgot what the title was though

@jrschumacher
Copy link

🤦‍♂️ thanks it's been a long day. If you point me to the right file I'll investigate adding the check and error. I looked in core but didn't see where the push was happening.

@hipstersmoothie
Copy link
Collaborator Author

Is this repo public? I can poke around.

@jrschumacher
Copy link

@hipstersmoothie
Copy link
Collaborator Author

Where are the logs for this. Currently we do have code that will abort the release if we detect this situation

this.hooks.afterVersion.tapPromise("Check remote for commits", async () => {
// Credit from https://github.com/semantic-release/semantic-release/blob/b2b7b57fbd51af3fe25accdd6cd8499beb9005e5/lib/git.js#L179
// `true` is the HEAD of the current local branch is the same as the HEAD of the remote branch, falsy otherwise.
try {
const currentBranch = getCurrentBranch();
const heads = await execPromise("git", [
"ls-remote",
"--heads",
this.remote,
currentBranch,
]);
this.logger.verbose.info("Branch:", currentBranch);
this.logger.verbose.info("HEADs:", heads);
const baseBranchHeadRef = new RegExp(
`^(\\w+)\\s+refs/heads/${this.baseBranch}$`
);
const [, remoteHead] = heads.match(baseBranchHeadRef) || [];
if (remoteHead) {
// This will throw if the branch is ahead of the current branch
execSync(`git merge-base --is-ancestor ${remoteHead} HEAD`, {
stdio: "ignore",
});
}
this.logger.verbose.info(
"Current branch is up to date, proceeding with release"
);
} catch (error) {
// If we are behind or there is no match, exit and skip the release
this.logger.log.warn(
"Current commit is behind, skipping the release to avoid collisions."
);
this.logger.verbose.warn(error);
process.exit(0);
}
});

docs for the ls-remote command: https://riptutorial.com/git/example/1486/ls-remote

So the only way I could see this happening is if you merged 2 PRs at the exact right time.

The hook order goes like:

  • changelog
  • version
  • afterVersion <- ls-remote check here
  • merge?
  • publish <- tags pushed here

@jrschumacher
Copy link

Let me see if I can create a repeatable scenario and provide logs.

@hipstersmoothie
Copy link
Collaborator Author

I see what's happening. You use prepublishOnly which will lengthen the window between afterVersion and publish if the command it runs is long.

  • 1st merged PR is building and on publish step
  • 2nd merged PR gets to publish while the 1st PR is just finishing

My recommendation would be to run your build then run auto (remove the prepublishOnly script)

@hipstersmoothie
Copy link
Collaborator Author

hipstersmoothie commented Jul 30, 2020

I will update this doc and warn about this type of situation.

@jrschumacher
Copy link

Gotcha. So if I move it to prerelease that should solve it?

@hipstersmoothie hipstersmoothie changed the title wip Abort release if new commits detected upstream Jul 30, 2020
@hipstersmoothie
Copy link
Collaborator Author

yup that would work too!

@jrschumacher
Copy link

Thanks so much for this great tool and the support.

@hipstersmoothie
Copy link
Collaborator Author

Thanks for using auto! (and for surfacing this issue #1419)

@hipstersmoothie
Copy link
Collaborator Author

I'm gonna close this issue. If you find this is still happening feel free open another issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants