|
| 1 | +name: Dependabot auto-merge |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + update-types: |
| 7 | + description: Comma-separated semver bump types to auto-merge (patch, minor, major) |
| 8 | + required: false |
| 9 | + type: string |
| 10 | + default: "patch,minor" |
| 11 | + merge-method: |
| 12 | + description: Merge method passed to `gh pr merge` (squash, merge, rebase) |
| 13 | + required: false |
| 14 | + type: string |
| 15 | + default: "squash" |
| 16 | + |
| 17 | + secrets: |
| 18 | + github_token: |
| 19 | + required: true |
| 20 | + |
| 21 | +jobs: |
| 22 | + dependabot-auto-merge: |
| 23 | + name: Auto-merge eligible Dependabot PRs |
| 24 | + runs-on: ubuntu-latest |
| 25 | + timeout-minutes: 5 |
| 26 | + if: github.actor == 'dependabot[bot]' && github.repository_owner == 'code4romania' |
| 27 | + |
| 28 | + permissions: |
| 29 | + contents: write |
| 30 | + pull-requests: write |
| 31 | + |
| 32 | + steps: |
| 33 | + - name: Fetch Dependabot metadata |
| 34 | + id: metadata |
| 35 | + uses: dependabot/fetch-metadata@v3 |
| 36 | + with: |
| 37 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 38 | + |
| 39 | + - name: Decide auto-merge eligibility |
| 40 | + id: decide |
| 41 | + env: |
| 42 | + UPDATE_TYPE: ${{ steps.metadata.outputs.update-type }} |
| 43 | + ALLOWED: ${{ inputs.update-types }} |
| 44 | + run: | |
| 45 | + short="${UPDATE_TYPE#version-update:semver-}" |
| 46 | + if echo ",${ALLOWED}," | tr -d ' ' | grep -q ",${short},"; then |
| 47 | + echo "should_merge=true" >> "$GITHUB_OUTPUT" |
| 48 | + else |
| 49 | + echo "should_merge=false" >> "$GITHUB_OUTPUT" |
| 50 | + fi |
| 51 | +
|
| 52 | + - name: Approve PR |
| 53 | + if: steps.decide.outputs.should_merge == 'true' |
| 54 | + run: gh pr review --approve "$PR_URL" |
| 55 | + env: |
| 56 | + PR_URL: ${{ github.event.pull_request.html_url }} |
| 57 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 58 | + |
| 59 | + - name: Enable auto-merge |
| 60 | + if: steps.decide.outputs.should_merge == 'true' |
| 61 | + run: gh pr merge --auto --${{ inputs.merge-method }} "$PR_URL" |
| 62 | + env: |
| 63 | + PR_URL: ${{ github.event.pull_request.html_url }} |
| 64 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments