-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add dependabot-rebase workflow standard #52
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 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
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
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,134 @@ | ||
| # Dependabot update and merge workflow | ||
| # Copy to .github/workflows/dependabot-rebase.yml | ||
| # | ||
| # Requires repository secrets: | ||
| # APP_ID — GitHub App ID with contents:write and pull-requests:write | ||
| # APP_PRIVATE_KEY — GitHub App private key | ||
| # | ||
| # Problem: when branch protection requires branches to be up-to-date | ||
| # (strict status checks), merging one Dependabot PR makes the others fall | ||
| # behind. Dependabot does not auto-rebase PRs that are merely behind — it | ||
| # only rebases on its next scheduled run or when there are merge conflicts. | ||
| # Additionally, GitHub auto-merge (--auto) may not trigger when rulesets | ||
| # cause mergeable_state to report "blocked" even though all requirements | ||
| # are actually met. | ||
| # | ||
| # Solution: after every push to main (typically a merged PR), this workflow: | ||
| # 1. Updates behind Dependabot PRs using the merge method (not rebase) | ||
| # 2. Merges any Dependabot PR that is up-to-date, approved, and passing CI | ||
| # | ||
| # Using the app token for merges ensures the resulting push to main triggers | ||
| # this workflow again, creating a self-sustaining chain that serializes | ||
| # Dependabot PR merges one at a time. | ||
| # | ||
| # Important: never use the API update-branch endpoint with rebase method on | ||
| # Dependabot PRs — it replaces Dependabot's commit signature with GitHub's, | ||
| # which breaks dependabot/fetch-metadata verification and causes Dependabot | ||
| # to refuse future rebases on that PR. The merge method preserves the | ||
| # original commits. | ||
| # | ||
| # Note: the merge commit is authored by GitHub, not Dependabot, so the | ||
| # dependabot-automerge workflow must use skip-commit-verification: true | ||
| # in the dependabot/fetch-metadata step. | ||
| name: Dependabot update and merge | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
|
|
||
| concurrency: | ||
| group: dependabot-update-and-merge | ||
| cancel-in-progress: false | ||
|
|
||
| permissions: {} | ||
don-petry marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| jobs: | ||
| update-and-merge: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| pull-requests: read | ||
| steps: | ||
| - name: Generate app token | ||
| id: app-token | ||
| uses: actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859 # v3 | ||
| with: | ||
| app-id: ${{ secrets.APP_ID }} | ||
| private-key: ${{ secrets.APP_PRIVATE_KEY }} | ||
|
|
||
| - name: Update and merge Dependabot PRs | ||
| env: | ||
| GH_TOKEN: ${{ steps.app-token.outputs.token }} | ||
| REPO: ${{ github.repository }} | ||
| run: | | ||
| # Find open Dependabot PRs | ||
| PRS=$(gh pr list --repo "$REPO" --author "app/dependabot" \ | ||
| --json number,headRefName \ | ||
| --jq '.[] | "\(.number) \(.headRefName)"') | ||
|
|
||
| if [[ -z "$PRS" ]]; then | ||
| echo "No open Dependabot PRs" | ||
| exit 0 | ||
| fi | ||
|
|
||
| MERGED=false | ||
|
|
||
| while IFS=' ' read -r PR_NUMBER HEAD_REF; do | ||
| BEHIND=$(gh api "repos/$REPO/compare/main...$HEAD_REF" \ | ||
| --jq '.behind_by') | ||
|
|
||
don-petry marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if [[ "$BEHIND" -gt 0 ]]; then | ||
| echo "PR #$PR_NUMBER ($HEAD_REF) is $BEHIND commit(s) behind — merging main into branch" | ||
| gh api "repos/$REPO/pulls/$PR_NUMBER/update-branch" \ | ||
| -X PUT -f update_method=merge \ | ||
| --silent || echo "Warning: failed to update PR #$PR_NUMBER" | ||
| continue | ||
| fi | ||
|
|
||
| echo "PR #$PR_NUMBER ($HEAD_REF) is up to date — checking if merge-ready" | ||
|
|
||
| # Skip if we already merged one (strict mode means others are now behind) | ||
| if [[ "$MERGED" == "true" ]]; then | ||
| echo " Skipping — already merged a PR this run" | ||
| continue | ||
| fi | ||
|
|
||
| # Check if auto-merge is enabled (set by the automerge workflow) | ||
| AUTO_MERGE=$(gh pr view "$PR_NUMBER" --repo "$REPO" \ | ||
| --json autoMergeRequest --jq '.autoMergeRequest != null') | ||
|
|
||
| if [[ "$AUTO_MERGE" != "true" ]]; then | ||
| echo " Skipping — auto-merge not enabled" | ||
| continue | ||
| fi | ||
|
|
||
| # Check if all required checks pass (look at overall rollup) | ||
| CHECKS_PASS=$(gh pr view "$PR_NUMBER" --repo "$REPO" \ | ||
| --json statusCheckRollup \ | ||
| --jq '[.statusCheckRollup[]? | select(.name != null and .status == "COMPLETED") | .conclusion] | all(. == "SUCCESS" or . == "NEUTRAL" or . == "SKIPPED")') | ||
|
|
||
| CHECKS_PENDING=$(gh pr view "$PR_NUMBER" --repo "$REPO" \ | ||
| --json statusCheckRollup \ | ||
| --jq '[.statusCheckRollup[]? | select(.name != null and .status != "COMPLETED")] | length') | ||
|
|
||
| if [[ "$CHECKS_PENDING" -gt 0 ]]; then | ||
| echo " Skipping — $CHECKS_PENDING check(s) still pending" | ||
| continue | ||
| fi | ||
|
|
||
| if [[ "$CHECKS_PASS" != "true" ]]; then | ||
| echo " Skipping — some checks failed" | ||
| continue | ||
| fi | ||
|
|
||
| echo " All checks pass — merging PR #$PR_NUMBER" | ||
| if gh api "repos/$REPO/pulls/$PR_NUMBER/merge" \ | ||
| -X PUT -f merge_method=squash \ | ||
| --silent; then | ||
| echo " Merged PR #$PR_NUMBER" | ||
| MERGED=true | ||
| else | ||
| echo " Warning: failed to merge PR #$PR_NUMBER" | ||
| fi | ||
| done <<< "$PRS" | ||
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.