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
Conversation
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 @mweinelt IIRC you asked about using it for release branches? |
.github/workflows/rebase-staging.yml
Outdated
|
||
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') |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
.github/workflows/rebase-staging.yml
Outdated
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}') |
There was a problem hiding this comment.
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
?
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}') |
There was a problem hiding this 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!
There was a problem hiding this 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.
@zowoq Thanks for pinging me on this. This does look like it would be helpful for rebasing stuff on Although I'm not very familiar with these Does the 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 |
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. |
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 I've added a check for |
- 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.
I just triggered this by accident by commenting on a PR with |
I tried rebasing on the same branch and for some reason that is prohibited.
Rebasing became necessary when an eval error hit release-20.09 and allowing rebase onto the same base would've been useful. |
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 |
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. |
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:
|
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. |
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. |
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. |
PR to remove: #126192 |
Motivation for this change
Things done
sandbox
innix.conf
on non-NixOS linux)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
./result/bin/
)nix path-info -S
before and after)