Add Dependabot auto-merge workflows (ROSA-745)#391
Conversation
WalkthroughAdds a scheduled/manual branch-protection check that validates Dependabot config files, and a Dependabot auto-merge workflow that enables auto-merge for safe updates or posts/manual-review comments for major updates. ChangesDependabot Automation
Sequence DiagramsequenceDiagram
participant GitHub as GitHub (PR Event)
participant Workflow as Auto-Merge Workflow
participant Metadata as Dependabot Metadata
participant REST as GitHub REST API
participant GraphQL as GitHub GraphQL API
GitHub->>Workflow: pull_request_target (Dependabot)
Workflow->>Metadata: Fetch update type
Metadata-->>Workflow: update type (patch/minor/digest/major)
alt Patch/Minor/Digest Update
Workflow->>REST: Get PR node_id
REST-->>Workflow: node_id
Workflow->>GraphQL: Enable autoMergeRequest (SQUASH)
GraphQL-->>Workflow: Success or failure
alt Enable Failed
Workflow->>GitHub: Post comment with update details
end
else Major Version Update
Workflow->>GitHub: Post comment requiring manual review
end
Workflow->>Workflow: Log auto-merge decision
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 11 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (11 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Comment |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: MitaliBhalla The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.github/workflows/branch-protection-check.yml:
- Around line 25-33: Replace the plain existence checks (the if [ -f
".github/dependabot.yml" ] and if [ -f
".github/workflows/dependabot-auto-merge.yml" ] branches and the grep -A 10
"package-ecosystem:" usage) with structural YAML validation: after confirming
the file exists, parse the YAML (using yq or a short python -c YAML load) and
assert required keys/values (for dependabot.yml ensure top-level fields like
version, updates/updates[].package-ecosystem, updates[].directory exist; for
dependabot-auto-merge workflow ensure on/jobs and the expected job names/steps
exist and that required trigger (e.g., pull_request or schedule) and
permissions/steps for automerge are present); if validation fails, print a clear
error and exit 1 so the job fails on malformed configs.
In @.github/workflows/dependabot-auto-merge.yml:
- Around line 4-5: The workflow currently triggers on pull_request_target with
types: [opened, synchronize, reopened, ready_for_review], causing the
major-update notice to be posted on every rerun; fix by either restricting the
trigger to only the initial open event (change types to [opened]) or keep the
current trigger set but add a dedupe check in the job that posts comments: in
the step that posts the Dependabot major-update comment, query existing PR
comments (using the same bot identity) and skip posting if a matching bot
comment already exists; look for the pull_request_target block and the step that
creates the comment to implement one of these fixes.
- Around line 87-105: The step currently prints "Auto-merge ENABLED" based
solely on the update-type even when the GraphQL mutation failed; instead capture
and persist the actual GraphQL mutation outcome (use the existing http_code and
/tmp/response.json produced by the curl call), set a boolean/variable (e.g.,
AUTO_MERGE_ENABLED) based on the graphql_auto_merge_ok "$http_code" check, and
use that variable to decide both the echo messages and the content passed to
post_issue_comment; also include or embed the actual /tmp/response.json (or a
parsed error message) in the log/posted comment so the real mutation result is
visible. Apply the same change to the other auto-merge block that currently
mirrors this behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: c89cf215-2c55-4bc5-864e-066fbbf34e01
📒 Files selected for processing (2)
.github/workflows/branch-protection-check.yml.github/workflows/dependabot-auto-merge.yml
81b43eb to
c982e8a
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.github/workflows/dependabot-auto-merge.yml:
- Around line 125-134: The curl call that sets the existing variable must
validate the HTTP response before piping to jq: capture both the response body
and the HTTP status from the curl invocation used to fetch issue comments (the
block that defines existing via curl | jq), check the HTTP status is 200 (or in
2xx) before running jq on the body, and if not 200 log an error and exit or
retry; ensure you reference the same curl invocation and the existing variable
so you don't silently treat error responses as empty comment lists.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: fb9a35aa-fca0-4001-8698-dfb67ea20e17
📒 Files selected for processing (2)
.github/workflows/branch-protection-check.yml.github/workflows/dependabot-auto-merge.yml
046984c to
839fe32
Compare
- Auto-merge patch/minor/digest after CI; majors manual - pull_request_target with validated API responses - branch-protection-check for config/workflow presence Co-authored-by: Cursor <cursoragent@cursor.com>
839fe32 to
cd860d1
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (2)
.github/workflows/branch-protection-check.yml (2)
72-77: ⚡ Quick winConsider validating explicit permissions in the auto-merge job.
When using
pull_request_target, jobs inherit elevated write permissions by default. Security best practice is to explicitly declare required permissions following the principle of least privilege.🔒 Suggested enhancement
job = jobs["auto-merge"] if not isinstance(job, dict): fail("jobs.auto-merge must be a mapping") +perms = job.get("permissions") +if not isinstance(perms, dict): + fail("jobs.auto-merge must declare explicit permissions") +required_perms = {"pull-requests", "contents"} +if not required_perms.issubset(perms.keys()): + fail(f"jobs.auto-merge must declare permissions: {required_perms}") steps = job.get("steps")🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In @.github/workflows/branch-protection-check.yml around lines 72 - 77, The auto-merge job validation currently only checks that jobs["auto-merge"] is a mapping and has steps; add a check that the job defines an explicit "permissions" mapping and validate it is a dict (e.g., perms = job.get("permissions")) and fail if missing or not a mapping; additionally assert that it does not grant broad elevated write access (e.g., reject wildcards or top-level "write" unless intentionally required) so the auto-merge job follows least-privilege. Use the existing job/jobs["auto-merge"]/steps symbols to locate where to insert this permission validation.
78-84: ⚡ Quick winValidate that the fetch-metadata action is pinned to a specific version.
The validation checks for the presence of
dependabot/fetch-metadatabut doesn't verify it's pinned to a specific version or commit SHA. Using unpinned or loosely pinned action versions (e.g.,@v1) is a supply chain security risk.🔒 Suggested enhancement
uses = [ s.get("uses", "") for s in steps if isinstance(s, dict) ] -if not any("dependabot/fetch-metadata" in u for u in uses): - fail("jobs.auto-merge must include dependabot/fetch-metadata") +fetch_meta_uses = [u for u in uses if "dependabot/fetch-metadata" in u] +if not fetch_meta_uses: + fail("jobs.auto-merge must include dependabot/fetch-metadata") +# Verify it's pinned to a version or SHA (not just `@v1`, `@v2`, etc.) +for u in fetch_meta_uses: + if "@" not in u: + fail(f"dependabot/fetch-metadata must be pinned: {u}") + # Check for specific version (vX.Y.Z) or SHA (40-char hex) + ref = u.split("@", 1)[1] + import re + if not (re.match(r"v\d+\.\d+\.\d+", ref) or re.match(r"[0-9a-f]{40}", ref)): + fail(f"dependabot/fetch-metadata should be pinned to vX.Y.Z or SHA, not: {ref}")🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In @.github/workflows/branch-protection-check.yml around lines 78 - 84, The current check only looks for "dependabot/fetch-metadata" in uses entries; update the validation to require a pinned reference by checking that any uses string contains "dependabot/fetch-metadata@" and that the suffix after '@' is a specific pin (not a bare major tag like "v1" or empty). Modify the logic that builds/inspects uses (the uses list and the final conditional) so it only passes when a uses entry matches "dependabot/fetch-metadata@" followed by a commit SHA or a full version (e.g., semver with major.minor.patch) rather than an unpinned or loosely pinned ref. Ensure you still treat uses items that are dicts and extract s.get("uses", "") as before.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In @.github/workflows/branch-protection-check.yml:
- Around line 72-77: The auto-merge job validation currently only checks that
jobs["auto-merge"] is a mapping and has steps; add a check that the job defines
an explicit "permissions" mapping and validate it is a dict (e.g., perms =
job.get("permissions")) and fail if missing or not a mapping; additionally
assert that it does not grant broad elevated write access (e.g., reject
wildcards or top-level "write" unless intentionally required) so the auto-merge
job follows least-privilege. Use the existing job/jobs["auto-merge"]/steps
symbols to locate where to insert this permission validation.
- Around line 78-84: The current check only looks for
"dependabot/fetch-metadata" in uses entries; update the validation to require a
pinned reference by checking that any uses string contains
"dependabot/fetch-metadata@" and that the suffix after '@' is a specific pin
(not a bare major tag like "v1" or empty). Modify the logic that builds/inspects
uses (the uses list and the final conditional) so it only passes when a uses
entry matches "dependabot/fetch-metadata@" followed by a commit SHA or a full
version (e.g., semver with major.minor.patch) rather than an unpinned or loosely
pinned ref. Ensure you still treat uses items that are dicts and extract
s.get("uses", "") as before.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 0e36402e-cf20-4695-88dd-471bf1cc5d33
📒 Files selected for processing (2)
.github/workflows/branch-protection-check.yml.github/workflows/dependabot-auto-merge.yml
|
@MitaliBhalla: all tests passed! Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
|
On hold — pausing this per-repo workflow rollout while we switch to the boilerplate / MintMaker (Renovate) path for ROSA-745. Please do not merge; we will close or reopen after the platform PR lands. |
Summary
Dependabot auto-merge for routine updates (ROSA-745 / ROSAENG-751), aligned with openshift/backplane-cli (SREP-2438).
Changes
pull_request_target(no PR checkout), validated GraphQL/REST/comment responses.Notes
dependabot[bot]+openshiftorg only.Test plan
Made with Cursor
Summary by CodeRabbit