-
Notifications
You must be signed in to change notification settings - Fork 430
Add workflow to merge main and rebuild generated files #340
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
Conversation
| # https://api.github.com/repos/github/codeql-action/actions/workflows/update-lib.yml/dispatches \ | ||
| # -d '{"ref":"main","inputs":{"branch":"<branch name>"}}' | ||
| # Replace <token> with a personal access token from this page: https://github.com/settings/tokens | ||
| # Replace <pr-number> by the number of the pull request to update |
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.
| # Replace <pr-number> by the number of the pull request to update | |
| # Replace <branch name> by the name of the branch of the PR. |
Did you test this for forks? Should it then be <user>:<branch>?
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.
I did not test this for forks and you're right this isn't going to work as it is.
chrisgavin
left a comment
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.
Nice! I've added some suggestions that allow putting a label on the PR to trigger the job instead, which might be a bit easier. If you'd prefer to merge it as-is though, that's also fine. Either way it makes things easier.
I think unfortunately the GITHUB_TOKEN provided by Actions can't write to forks even if they've explicitly allowed edits by maintainers so I don't think it's going to be possible to use a workflow to update external contributions unless we provide a personal access token to the workflow.
| workflow_dispatch: | ||
| # Example of how to trigger this using the API: | ||
| # curl -X POST \ | ||
| # -H "Authorization: Bearer <token>" \ | ||
| # https://api.github.com/repos/github/codeql-action/actions/workflows/update-lib.yml/dispatches \ | ||
| # -d '{"ref":"main","inputs":{"branch":"<branch name>"}}' | ||
| # Replace <token> with a personal access token from this page: https://github.com/settings/tokens | ||
| # Replace <pr-number> by the number of the pull request to update | ||
| inputs: | ||
| branch: | ||
| description: 'The branch to update' | ||
| required: true |
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.
| workflow_dispatch: | |
| # Example of how to trigger this using the API: | |
| # curl -X POST \ | |
| # -H "Authorization: Bearer <token>" \ | |
| # https://api.github.com/repos/github/codeql-action/actions/workflows/update-lib.yml/dispatches \ | |
| # -d '{"ref":"main","inputs":{"branch":"<branch name>"}}' | |
| # Replace <token> with a personal access token from this page: https://github.com/settings/tokens | |
| # Replace <pr-number> by the number of the pull request to update | |
| inputs: | |
| branch: | |
| description: 'The branch to update' | |
| required: true | |
| pull_request_target: | |
| types: | |
| - labeled |
| jobs: | ||
| update-lib: | ||
| runs-on: ubuntu-latest | ||
|
|
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.
| if: ${{ github.event.label.name == 'update-lib' }} | |
| uses: actions/checkout@v2 | ||
| with: | ||
| fetch-depth: 0 | ||
| ref: ${{ github.event.inputs.branch }} |
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.
| ref: ${{ github.event.inputs.branch }} | |
| repository: ${{ github.event.pull_request.head.repo.full_name }} | |
| ref: ${{ github.event.pull_request.head.ref }} |
| git fetch origin | ||
| if ! merge_output=$(git merge origin/main --no-ff); then |
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.
| git fetch origin | |
| if ! merge_output=$(git merge origin/main --no-ff); then | |
| git remote add base ${{ github.event.pull_request.base.repo.clone_url }} | |
| git fetch base | |
| if ! merge_output=$(git merge base/${{ github.event.pull_request.base.ref }} --no-ff); then |
| git commit -am "merge main" | ||
| fi | ||
|
|
||
| git push origin HEAD:${{ github.event.inputs.branch }} |
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.
| git push origin HEAD:${{ github.event.inputs.branch }} | |
| git push ${{ github.event.pull_request.head.repo.clone_url }} ${{ github.event.pull_request.head.ref }} | |
| - name: Remove Label | |
| uses: buildsville/add-remove-label@dd82a87afd13f1e78e35131fe1945380c685305e | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| label: update-lib | |
| type: remove |
|
Closing this as it's unlikely to get completed. I think trying to make it work on PRs from forks will be too difficult and not worth it. |
This is a potential alternative to #322
Adds a workflow that can be triggered via workflow dispatch and will merge main into a branch and fix any conflicts in the
libdirectory if required. Will be of some use for people at GitHub to update their own PRs, but the main intended use is it'll make it much easier to update a PR from an external contributor. You don't have to wait for the contributor to update their PR, or have to manually add a remote and push changes yourself.There are a few 3rd party actions out there for checking out PRs and committing and pushing changes (for example https://github.com/dawidd6/action-checkout-pr and https://github.com/stefanzweifel/git-auto-commit-action), but I found it easier to do manually with
gitandbash.Merge / deployment checklist