|
| 1 | +name: Dependabot auto-approve |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + secrets: |
| 6 | + AUTOMERGE_APP_ID: |
| 7 | + required: true |
| 8 | + AUTOMERGE_PEM: |
| 9 | + required: true |
| 10 | + |
| 11 | +permissions: |
| 12 | + pull-requests: write |
| 13 | + contents: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + dependabot: |
| 17 | + runs-on: ubuntu-22.04 |
| 18 | + if: ${{ github.actor == 'dependabot[bot]' }} |
| 19 | + steps: |
| 20 | + - name: Get token from Github App |
| 21 | + id: get_app_token |
| 22 | + uses: actions/create-github-app-token@67018539274d69449ef7c02e8e71183d1719ab42 |
| 23 | + with: |
| 24 | + app-id: ${{ secrets.AUTOMERGE_APP_ID }} |
| 25 | + private-key: ${{ secrets.AUTOMERGE_PEM }} |
| 26 | + |
| 27 | + - name: Dependabot metadata |
| 28 | + id: dependabot-metadata |
| 29 | + uses: dependabot/fetch-metadata@08eff52bf64351f401fb50d4972fa95b9f2c2d1b |
| 30 | + with: |
| 31 | + github-token: "${{ secrets.GITHUB_TOKEN }}" |
| 32 | + |
| 33 | + - name: Approve patch and minor updates |
| 34 | + if: ${{steps.dependabot-metadata.outputs.update-type == 'version-update:semver-patch' || steps.dependabot-metadata.outputs.update-type == 'version-update:semver-minor'}} |
| 35 | + run: gh pr review "$PR_URL" --approve -b "I'm **approving** this pull request because **it includes a patch or minor update**" |
| 36 | + env: |
| 37 | + PR_URL: ${{github.event.pull_request.html_url}} |
| 38 | + GITHUB_TOKEN: ${{ steps.get_app_token.outputs.token }} |
| 39 | + |
| 40 | + - name: Approve major updates of development dependencies |
| 41 | + if: ${{steps.dependabot-metadata.outputs.update-type == 'version-update:semver-major' && steps.dependabot-metadata.outputs.dependency-type == 'direct:development'}} |
| 42 | + run: gh pr review "$PR_URL" --approve -b "I'm **approving** this pull request because **it includes a major update of a dependency used only in development**" |
| 43 | + env: |
| 44 | + PR_URL: ${{github.event.pull_request.html_url}} |
| 45 | + GITHUB_TOKEN: ${{ steps.get_app_token.outputs.token }} |
| 46 | + |
| 47 | + - name: Comment on major updates of non-development dependencies |
| 48 | + if: ${{steps.dependabot-metadata.outputs.update-type == 'version-update:semver-major' && steps.dependabot-metadata.outputs.dependency-type == 'direct:production'}} |
| 49 | + run: | |
| 50 | + gh pr comment "$PR_URL" --body "I'm **not approving** this PR because **it includes a major update of a dependency used in production**" |
| 51 | + gh pr edit "$PR_URL" --add-label "requires-manual-qa" |
| 52 | + env: |
| 53 | + PR_URL: ${{github.event.pull_request.html_url}} |
| 54 | + GITHUB_TOKEN: ${{ steps.get_app_token.outputs.token }} |
| 55 | + |
| 56 | + # enable auto merge on all dependabot prs |
| 57 | + - name: Enable auto-merge for Dependabot PRs |
| 58 | + run: gh pr merge --auto --squash "$PR_URL" |
| 59 | + env: |
| 60 | + PR_URL: ${{github.event.pull_request.html_url}} |
| 61 | + GITHUB_TOKEN: ${{ steps.get_app_token.outputs.token }} |
0 commit comments