Repository navigation
ci: let Dependabot merge patch and minor updates #10
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
ItsPaulAT
wants to merge
5
commits into
main
Choose a base branch
from
ci/dependabot-automerge
base: main
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e8d8000
ci: let Dependabot merge patch and minor updates
ItsPaulAT 1219578
docs: list the auto-merge settings in the publishing checklist
ItsPaulAT 90cac73
Enhance review condition for Dependabot commits
ItsPaulAT 8c9259f
Refine version check for minor updates in workflow
ItsPaulAT aa9bab7
Merge branch 'main' into ci/dependabot-automerge
ItsPaulAT 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| # Approves Dependabot's patch and minor updates and turns on auto-merge (squash); GitHub merges | ||
| # once the required checks pass. Majors, 0.x minors and updates without a semver type (image | ||
| # digests) stay for a manual review. The update types come from the metadata block of | ||
| # Dependabot's commit message, the same source dependabot/fetch-metadata reads. | ||
| name: dependabot-automerge | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize, reopened] | ||
|
|
||
| permissions: {} | ||
|
|
||
| concurrency: | ||
| group: dependabot-automerge-${{ github.event.pull_request.number }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| automerge: | ||
| name: automerge | ||
| if: >- | ||
| github.event.pull_request.user.login == 'dependabot[bot]' && | ||
| github.event.pull_request.head.repo.full_name == github.repository | ||
| runs-on: ubuntu-24.04 | ||
| timeout-minutes: 5 | ||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
| steps: | ||
| - name: Approve and enable auto-merge for patch and minor updates | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| REPO: ${{ github.repository }} | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| HEAD_SHA: ${{ github.event.pull_request.head.sha }} | ||
| run: | | ||
| set -euo pipefail | ||
| commits="$(gh api "repos/$REPO/pulls/$PR_NUMBER/commits?per_page=100")" | ||
| authors="$(jq -r '[.[].author.login // "unknown"] | unique | join(",")' <<<"$commits")" | ||
| if [ "$authors" != "dependabot[bot]" ] || ! jq -e 'all(.[]; .commit.verification.verified == true)' <<<"$commits" >/dev/null; then | ||
| echo "::notice::Unverified commits or commits by $authors; left for a manual review." | ||
| exit 0 | ||
| fi | ||
| export MESSAGE | ||
| MESSAGE="$(jq -r '.[-1].commit.message' <<<"$commits")" | ||
| verdict="$(python3 - <<'PY' | ||
| import os | ||
| deps, block = [], False | ||
| for line in os.environ["MESSAGE"].splitlines(): | ||
| if line == "updated-dependencies:": | ||
| block = True | ||
| elif block and line in ("...", "---", ""): | ||
| break | ||
| elif block and line.startswith("- "): | ||
| deps.append({}) | ||
| if block and deps and ":" in line: | ||
| key, _, value = line[2:].partition(":") | ||
| deps[-1][key.strip()] = value.strip().strip("'\"") | ||
| reasons = [] | ||
| for d in deps: | ||
| kind = d.get("update-type", "") | ||
| name = d.get("dependency-name", "?") | ||
| if kind not in ("version-update:semver-patch", "version-update:semver-minor"): | ||
| reasons.append(f"{name}: {kind or 'no semver update type'}") | ||
| elif kind.endswith("minor") and (not d.get("dependency-version") or d["dependency-version"].removeprefix("v").startswith("0.")): | ||
| reasons.append(f"{name}: unknown version or minor update below 1.0") | ||
| print("; ".join(reasons) if deps else "no update metadata") | ||
| PY | ||
| )" | ||
| if [ -n "$verdict" ]; then | ||
| echo "::notice::Left for a manual review ($verdict)." | ||
| exit 0 | ||
| fi | ||
| url="https://github.com/$REPO/pull/$PR_NUMBER" | ||
| gh pr review "$url" --approve || echo "::warning::Could not approve the pull request." | ||
| gh pr merge "$url" --auto --squash --match-head-commit "$HEAD_SHA" | ||
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
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.