Repository navigation
Pr update action #9146
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
Open
ericspod
wants to merge
5
commits into
Project-MONAI:dev
Choose a base branch
from
ericspod:pr_update_action
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Pr update action #9146
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
|
|
||
| # This action will keep PRs branches updated which have been approved and have automerge enabled. This is meant to | ||
| # automate the integration of PRs which have been reviewed but will be stopped from merging when something else gets | ||
| # merged first. Needing to manually update branches whenever this happens slows the review process so this action | ||
| # should speed things along, but a PR with failed tests will stop this automation from helping. The key control is that | ||
| # reviewers must approve AND enable automerge, a PR that's approved but should wait will be left alone if automerge | ||
| # isn't on. This action updates the oldest approved-automerging PR only to avoid wasting compute. | ||
|
|
||
| # IMPORTANT: requires a personal access token (PAT_UPDATE_TOKEN) with contents and pull request read/write access. | ||
|
|
||
| name: Auto-Update PRs | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - dev | ||
| workflow_dispatch: # Allows manual triggering if needed | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| update-prs: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout target branch | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| fetch-depth: 0 # Fetches all history so branches can be merged locally | ||
|
|
||
| - name: Update the oldest PR which is approved and automerging-enabled | ||
| env: | ||
| GH_TOKEN: ${{ secrets.PAT_UPDATE_TOKEN }} # PAT with read/write access to Contents and PullRequests | ||
| BASE_REF: ${{ github.ref_name }} # neutralizes CWE-78 command injection through branch names with shell syntax | ||
| run: | | ||
| # Find all open PRs targeting this branch which are open and approved | ||
| PR_DATA=$(gh pr list --state open --search 'review:approved sort:created-asc' --base $BASE_REF --json number,reviewDecision,autoMergeRequest) | ||
|
|
||
| echo '================================' | ||
| echo "PR_DATA:" | ||
| echo $PR_DATA | ||
| echo '================================' | ||
|
|
||
| # select the oldest open approved PR with automerge enabled | ||
| OLDEST_APPROVED=$(echo $PR_DATA | jq -r '.[] | select(.reviewDecision == "APPROVED") | select(.autoMergeRequest != null) | "\(.number)"'|head -n 1) | ||
|
|
||
| if [ -z "$OLDEST_APPROVED" ] | ||
| then | ||
| echo "No approved PRs to update." | ||
| else | ||
| echo "Updating PR $OLDEST_APPROVED ..." | ||
| gh pr update-branch "$OLDEST_APPROVED" || echo "Failed to update PR #$OLDEST_APPROVED (merge conflicts?)." | ||
| fi | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.