|
| 1 | +name: Dependabot CI Updates |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + types: |
| 8 | + - opened |
| 9 | + - synchronize |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: read |
| 13 | + |
| 14 | +jobs: |
| 15 | + dependabot-auto-approve: |
| 16 | + name: Auto-approve and auto-merge safe Dependabot updates |
| 17 | + runs-on: ubuntu-latest |
| 18 | + if: > |
| 19 | + github.event.pull_request.user.login == 'dependabot[bot]' && |
| 20 | + contains(github.event.pull_request.labels.*.name, 'dependencies') |
| 21 | + permissions: |
| 22 | + contents: write |
| 23 | + pull-requests: write |
| 24 | + steps: |
| 25 | + - name: Harden Runner |
| 26 | + uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0 |
| 27 | + with: |
| 28 | + disable-sudo: true |
| 29 | + egress-policy: audit |
| 30 | + |
| 31 | + - name: Generate GitHub App token |
| 32 | + id: token_generator |
| 33 | + uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1 |
| 34 | + with: |
| 35 | + app-id: ${{ secrets.BIRDHOUSE_HELPER_BOT_ID }} |
| 36 | + private-key: ${{ secrets.BIRDHOUSE_HELPER_BOT_KEY }} |
| 37 | + |
| 38 | + - name: Fetch Dependabot metadata |
| 39 | + id: dependabot-metadata |
| 40 | + uses: dependabot/fetch-metadata@21025c705c08248db411dc16f3619e6b5f9ea21a # v2.5.0 |
| 41 | + with: |
| 42 | + github-token: ${{ steps.token_generator.outputs.token }} |
| 43 | + |
| 44 | + - name: Stop workflow if not minor update or patch update |
| 45 | + id: skip-condition |
| 46 | + if: > |
| 47 | + steps.dependabot-metadata.outputs.update-type != 'version-update:semver-minor' && |
| 48 | + steps.dependabot-metadata.outputs.update-type != 'version-update:semver-patch' |
| 49 | + run: | |
| 50 | + echo "Not a minor or patch update; skipping auto-approval." |
| 51 | + echo "skip=true" >> $GITHUB_OUTPUT |
| 52 | +
|
| 53 | + - name: Checkout Repository |
| 54 | + if: steps.skip-condition.outputs.skip != 'true' |
| 55 | + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 |
| 56 | + with: |
| 57 | + persist-credentials: false |
| 58 | + token: ${{ steps.token_generator.outputs.token }} |
| 59 | + |
| 60 | + - name: Approve Changes |
| 61 | + if: steps.skip-condition.outputs.skip != 'true' |
| 62 | + run: | |
| 63 | + decision="$(gh pr status --json reviewDecision -q .currentBranch.reviewDecision)" |
| 64 | + if [ "$decision" != "APPROVED" ]; then |
| 65 | + gh pr review --approve "$PR_URL" |
| 66 | + else |
| 67 | + echo "PR already approved: skipping approval." |
| 68 | + fi |
| 69 | + env: |
| 70 | + GITHUB_TOKEN: ${{ steps.token_generator.outputs.token }} |
| 71 | + PR_URL: ${{ github.event.pull_request.html_url }} |
| 72 | + |
| 73 | + - name: Enable auto-merge on Pull Request |
| 74 | + if: steps.skip-condition.outputs.skip != 'true' |
| 75 | + run: | |
| 76 | + gh pr merge --auto --merge "$PR_URL" |
| 77 | + env: |
| 78 | + GITHUB_TOKEN: ${{ steps.token_generator.outputs.token }} |
| 79 | + PR_URL: ${{ github.event.pull_request.html_url }} |
0 commit comments