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

.github/workflows/rebase.yml: rebase for multiple branches #110843

Merged
merged 1 commit into from Feb 14, 2021
Merged

.github/workflows/rebase.yml: rebase for multiple branches #110843

merged 1 commit into from Feb 14, 2021

Conversation

zowoq
Copy link
Contributor

@zowoq zowoq commented Jan 26, 2021

Motivation for this change
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@zowoq
Copy link
Contributor Author

zowoq commented Jan 29, 2021

Leaving this as a draft but it's ready for review. I'll rename the action when merging.

@cdepillabout You may find this useful for PRs that need rebasing onto haskell-updates?

@mweinelt IIRC you asked about using it for release branches?


jobs:
rebase:
runs-on: ubuntu-latest
if: github.repository_owner == 'NixOS' && github.event.issue.pull_request != '' && contains(github.event.comment.body, '/rebase-staging')
if: github.repository_owner == 'NixOS' && github.event.issue.pull_request != '' && contains(github.event.comment.body, '/rebase')
Copy link
Member

Choose a reason for hiding this comment

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

Should be even backwards compatible.

Copy link
Member

Choose a reason for hiding this comment

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

It's not. We're expecting /rebase <branch> with this (see the awk '{ print $2 }'), while previously we accepted /rebase-staging.

COMMITS=$(jq -r '.commits' pr.json)
CURRENT_BASE=$(jq -r '.base.ref' pr.json)
PR_BRANCH=$(jq -r '.head.ref' pr.json)
COMMENT_BRANCH=$(echo ${{ github.event.comment.body }} | grep '/rebase' | awk '{print $2}')
Copy link
Member

Choose a reason for hiding this comment

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

This looks a bit fragile. Maybe only accept lines beginning with /rebase?

Suggested change
COMMENT_BRANCH=$(echo ${{ github.event.comment.body }} | grep '/rebase' | awk '{print $2}')
COMMENT_BRANCH=$(echo ${{ github.event.comment.body }} | grep -E '^/rebase' | awk '{print $2}')

Copy link
Member

@mweinelt mweinelt left a comment

Choose a reason for hiding this comment

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

Loving the idea, thank you for making it happen!

Copy link
Member

@mweinelt mweinelt left a comment

Choose a reason for hiding this comment

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

Looks pretty good IMO. I don't have much experience with GHA though.

@cdepillabout
Copy link
Member

@zowoq Thanks for pinging me on this. This does look like it would be helpful for rebasing stuff on haskell-updates.

Although I'm not very familiar with these / commands using GitHub actions.

Does the /rebase command actually rebase a branch in a user's repo (and not just change the base branch on GitHub)?

I was under the impression that even people with the commit bit in a repo aren't able to rebase a branch in a user's repo (even if they checked the box allow maintainer to push to my branch or whatever). So I'm somewhat surprised that this functionality is available as a / command.

@SuperSandro2000
Copy link
Member

Does the /rebase command actually rebase a branch in a user's repo (and not just change the base branch on GitHub)?

Yes. Base branch can be changed on the website but the two actions need to happen at once or you ping a lot of people.

I used it multiple times already and it mostly worked.

@zowoq
Copy link
Contributor Author

zowoq commented Feb 14, 2021

Once we've used this for a couple of weeks without any problems I'll see about getting a token added to the repo so we can drop the close/reopen hack.

I've added a check for Allow edits .. by maintainers / maintainer_can_modify as it seems like it might be a common error, some of the other failures look like problems with the gh tool itself or the runners environment.

@zowoq zowoq changed the title .github/workflows/rebase-staging.yml: rebase for multiple branches .github/workflows/rebase.yml: rebase for multiple branches Feb 14, 2021
@zowoq zowoq marked this pull request as ready for review February 14, 2021 00:34
- Error if the commenter doesn't have write access or maintainers can't edit the PR branch.

- Close and comment on PR after rebase so that actions are run when it's reopened.
  This doesn't happen currently as we're using the default github token which isn't allowed to trigger other actions.

- Disallow unwanted rebases.
  e.g. invalid branches, redundant rebases or rebasing permanent branches onto permanent branches.
@zowoq zowoq merged commit fc3b385 into NixOS:master Feb 14, 2021
@zowoq zowoq deleted the actions-rebase branch February 14, 2021 01:16
@zowoq
Copy link
Contributor Author

zowoq commented Feb 16, 2021

I just triggered this by accident by commenting on a PR with Updated{slash}rebased on master, we may need to change it to use something a bit more specific.

@mweinelt
Copy link
Member

I tried rebasing on the same branch and for some reason that is prohibited.

Can't rebase 20.09/microcodeIntel from release-20.09 onto release-20.09 (PR:113521 COMMITS:1)

Rebasing became necessary when an eval error hit release-20.09 and allowing rebase onto the same base would've been useful.

@zowoq
Copy link
Contributor Author

zowoq commented Feb 17, 2021

It's disabled it to simplify the action as the merge-base and change base API commands aren't needed in that case.

The action is intended to cover the more complicated cases that also require additional steps: an API call or manually changing the base branch.

TBH I don't think it's worthwhile having support for the same branch as the action only works for committers and it's simple (and quicker) to rebase a branch on HEAD as it only needs git commands.

@mweinelt
Copy link
Member

The API calls could be conditional on whether the branches aren't the same, no?

I know this is an afterthought, but It would be an amazing convenience feature, allowing the bot to take care of rebasing to HEAD to let the CI reevaluate with fixes that are on the target branch.

The benefit of the command is that it is lazy, it can be issued when you see the necessity and you don't have to open a shell, fetch and checkout the relevant branch. I believe there is little harm in allowing this.

Granted the whole action is getting quite complex, but we're talking about incremental improvements here.

@zowoq
Copy link
Contributor Author

zowoq commented Feb 18, 2021

The confusion about how to "properly" rebase across branches without the CODEOWNER spam has generated many discussion and issues. Even the IRC bot has a programmed response. It's worthwhile having the action to simplify it.

I don't see rebasing on HEAD it as an incremental improvement, it's an increase in complexity to address a use case that is already uncomplicated.

I don't think this needs to be supported as an action:

$ git fetch origin
$ gh pr checkout "$PR"
$ git rebase origin/HEAD
$ git push --force

@cdepillabout
Copy link
Member

I don't see rebasing on HEAD it as an incremental improvement, it's an increase in complexity to address a use case that is already uncomplicated.

While I agree that increasing complexity is definitely something to watch out for, it would be great to be able to do more directly through the github UI.

For instance, in #114418 (comment), I tried to use the /rebase command to do a rebase on the same branch, but it failed. I had to do it through the CLI.

If this would work to do a rebase on the same base branch, then I could have merged in that PR without ever going to the CLI. This would have been slightly easier for me.

@github-actions
Copy link
Contributor

Failed to rebase

@zowoq
Copy link
Contributor Author

zowoq commented Feb 26, 2021

Okay, there's been a few of requests now for rebasing on the same branch, let's add it.

Currently it doesn't work with the close/reopen hack, we won't be able to reopen the PR because of "branch was force pushed or recreated". If we change the action to use a different token we avoid the need for close/reopen hack so that seems to be the easier option. I'll try to see about organising that in the next couple of days.

@zowoq
Copy link
Contributor Author

zowoq commented May 27, 2021

... next couple of days.

Took a bit longer than I planned but I've opened a draft at #124560, also includes some other changes which will make the commands more reliable.

@zowoq
Copy link
Contributor Author

zowoq commented Jun 8, 2021

PR to remove: #126192

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants