|
| 1 | +# ============================================================================= |
| 2 | +# Dependabot Auto-Merge — Caller template |
| 3 | +# ============================================================================= |
| 4 | +# USAGE: |
| 5 | +# Copy this file to your repo at .github/workflows/dependabot-auto-merge.yml. |
| 6 | +# No REPLACE values needed. |
| 7 | +# |
| 8 | +# WHAT IT DOES: |
| 9 | +# Auto-merges a Dependabot PR ONLY when ALL of the following hold: |
| 10 | +# - The PR author is dependabot[bot] |
| 11 | +# - The update is a semver PATCH bump (never minor/major) |
| 12 | +# - The ecosystem is npm, nuget, pub, bundler, or github-actions |
| 13 | +# (NEVER docker — base image bumps always need manual review) |
| 14 | +# - This repo currently has no open critical Dependabot alert (re-checked |
| 15 | +# here explicitly — see workflow-templates/critical-vuln-check.yml's |
| 16 | +# header for why this can't just `needs:` that file's job) |
| 17 | +# "Auto-merge" here means GitHub's native auto-merge feature: it still |
| 18 | +# waits for the repo's actual required status checks (build/test) to pass |
| 19 | +# before merging — this workflow does not bypass those. |
| 20 | +# ============================================================================= |
| 21 | +name: Dependabot Auto-Merge |
| 22 | + |
| 23 | +on: |
| 24 | + pull_request: |
| 25 | + branches: [main, develop] |
| 26 | + |
| 27 | +permissions: |
| 28 | + pull-requests: write |
| 29 | + contents: write |
| 30 | + security-events: read |
| 31 | + |
| 32 | +jobs: |
| 33 | + vuln-gate: |
| 34 | + if: ${{ github.actor == 'dependabot[bot]' }} |
| 35 | + uses: simplify9/.github/.github/workflows/critical-vuln-gate.yml@main |
| 36 | + secrets: |
| 37 | + dependabot-alerts-token: ${{ secrets.DEPENDABOT_ALERTS_TOKEN }} |
| 38 | + |
| 39 | + auto-merge: |
| 40 | + needs: vuln-gate |
| 41 | + if: ${{ github.actor == 'dependabot[bot]' }} |
| 42 | + runs-on: ubuntu-latest |
| 43 | + timeout-minutes: 5 |
| 44 | + steps: |
| 45 | + - name: Fetch Dependabot metadata |
| 46 | + id: metadata |
| 47 | + uses: dependabot/fetch-metadata@v2 |
| 48 | + with: |
| 49 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 50 | + |
| 51 | + - name: Enable auto-merge for eligible patch bumps |
| 52 | + if: | |
| 53 | + steps.metadata.outputs.update-type == 'version-update:semver-patch' && |
| 54 | + contains(fromJSON('["npm_and_yarn", "nuget", "pub", "bundler", "github_actions"]'), steps.metadata.outputs.package-ecosystem) |
| 55 | + env: |
| 56 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 57 | + PR_URL: ${{ github.event.pull_request.html_url }} |
| 58 | + run: | |
| 59 | + set -euo pipefail |
| 60 | + echo "::notice title=🤖 [AUTO-MERGE] Enabling auto-merge::${PR_URL} — patch-level ${{ steps.metadata.outputs.package-ecosystem }} bump, vuln gate passed" |
| 61 | + gh pr merge --auto --squash "$PR_URL" |
0 commit comments