-
Notifications
You must be signed in to change notification settings - Fork 1
feat(ci): add guarded Mergify auto-merge for Dependabot security PRs #563
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
7 commits
Select commit
Hold shift + click to select a range
19df9a5
Add guarded Mergify auto-merge for Dependabot security PRs
ashleyshaw 12060f5
Fix invalid Mergify merge strict setting
ashleyshaw d69c01d
Fix workflow permissions and gate Mergify on CI checks
ashleyshaw 2120535
fix(labels): use canonical meta prefix for dependabot security label
ashleyshaw 89d35fc
docs(changelog): record dependabot security auto-merge governance cha…
ashleyshaw 2315b7f
fix(changelog): update frontmatter metadata and remove pending PR link
ashleyshaw c4c4a62
fix(changelog): use date-only last_updated for freshness validator
ashleyshaw 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,15 @@ | ||
| pull_request_rules: | ||
| - name: Auto-merge Dependabot security updates on develop | ||
| conditions: | ||
| - author=dependabot[bot] | ||
| - base=develop | ||
| - label=dependencies | ||
| - label=meta:dependabot-security | ||
| - check-success=CI / check | ||
| - check-success=lint / lint | ||
| - check-success=reviewer / coderabbit-gate | ||
| - -draft | ||
| - -conflict | ||
| actions: | ||
| merge: | ||
| method: squash | ||
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 @@ | ||
| name: dependabot-security-label | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, reopened, edited, synchronize] | ||
| branches: [develop] | ||
|
|
||
| jobs: | ||
| label-security-updates: | ||
| if: github.event.pull_request.user.login == 'dependabot[bot]' | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
| issues: write | ||
| steps: | ||
| - name: Detect security-related Dependabot updates | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| script: | | ||
| const owner = context.repo.owner; | ||
| const repo = context.repo.repo; | ||
| const issue_number = context.payload.pull_request.number; | ||
| const labelName = 'meta:dependabot-security'; | ||
|
|
||
| const title = context.payload.pull_request.title || ''; | ||
| const body = context.payload.pull_request.body || ''; | ||
| const text = `${title}\n${body}`; | ||
|
|
||
| // Keep this strict to avoid matching boilerplate text present in most Dependabot PRs. | ||
| const securityPatterns = [ | ||
| /\bto fix\b/i, | ||
| /\bvulnerabilit(?:y|ies)\b/i, | ||
| /\bcve-\d{4}-\d+\b/i, | ||
| /\bghsa-[a-z0-9-]+\b/i, | ||
| /\bsecurity\s+fix\b/i, | ||
| ]; | ||
|
|
||
| const isSecurityRelated = securityPatterns.some((pattern) => pattern.test(text)); | ||
|
|
||
| try { | ||
| await github.rest.issues.getLabel({ owner, repo, name: labelName }); | ||
| } catch (error) { | ||
| if (error.status === 404) { | ||
| await github.rest.issues.createLabel({ | ||
| owner, | ||
| repo, | ||
| name: labelName, | ||
| color: 'B60205', | ||
| description: 'Dependabot update appears security-related and eligible for guarded automation', | ||
| }); | ||
| } else { | ||
| throw error; | ||
| } | ||
| } | ||
|
|
||
| const existing = await github.rest.issues.listLabelsOnIssue({ owner, repo, issue_number }); | ||
| const hasLabel = existing.data.some((label) => label.name === labelName); | ||
|
|
||
| if (isSecurityRelated && !hasLabel) { | ||
| await github.rest.issues.addLabels({ owner, repo, issue_number, labels: [labelName] }); | ||
| core.notice(`Added '${labelName}' to PR #${issue_number}.`); | ||
| return; | ||
| } | ||
|
|
||
| if (!isSecurityRelated && hasLabel) { | ||
| await github.rest.issues.removeLabel({ owner, repo, issue_number, name: labelName }); | ||
| core.notice(`Removed '${labelName}' from PR #${issue_number}.`); | ||
| return; | ||
| } | ||
|
|
||
| core.notice( | ||
| `No label change needed for PR #${issue_number}; security-related=${isSecurityRelated}, hasLabel=${hasLabel}.`, | ||
| ); |
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.