|
| 1 | +name: Tailor automerge 🤖 |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + workflow_dispatch: |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: write |
| 9 | + pull-requests: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + automerge: |
| 13 | + runs-on: ubuntu-slim |
| 14 | + if: github.event_name == 'pull_request' |
| 15 | + steps: |
| 16 | + - name: Fetch Dependabot metadata |
| 17 | + if: github.event.pull_request.user.login == 'dependabot[bot]' |
| 18 | + id: metadata |
| 19 | + uses: dependabot/fetch-metadata@v2 |
| 20 | + with: |
| 21 | + github-token: "${{ secrets.GITHUB_TOKEN }}" |
| 22 | + skip-commit-verification: true |
| 23 | + |
| 24 | + - name: Automerge GitHub Actions updates |
| 25 | + if: >- |
| 26 | + github.event.pull_request.user.login == 'dependabot[bot]' |
| 27 | + && steps.metadata.outputs.package-ecosystem == 'github_actions' |
| 28 | + run: gh pr merge --auto --squash "$PR_URL" |
| 29 | + env: |
| 30 | + PR_URL: ${{ github.event.pull_request.html_url }} |
| 31 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 32 | + |
| 33 | + - name: Automerge patch and minor dependency updates |
| 34 | + if: >- |
| 35 | + github.event.pull_request.user.login == 'dependabot[bot]' |
| 36 | + && steps.metadata.outputs.package-ecosystem != 'github_actions' |
| 37 | + && ( |
| 38 | + steps.metadata.outputs.update-type == 'version-update:semver-patch' |
| 39 | + || steps.metadata.outputs.update-type == 'version-update:semver-minor' |
| 40 | + ) |
| 41 | + run: gh pr merge --auto --squash "$PR_URL" |
| 42 | + env: |
| 43 | + PR_URL: ${{ github.event.pull_request.html_url }} |
| 44 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 45 | + |
| 46 | + - name: Automerge flake.lock update |
| 47 | + if: >- |
| 48 | + github.event.pull_request.user.login == 'github-actions[bot]' |
| 49 | + && startsWith(github.event.pull_request.head.ref, 'update_flake_lock') |
| 50 | + run: gh pr merge --auto --squash "$PR_URL" |
| 51 | + env: |
| 52 | + PR_URL: ${{ github.event.pull_request.html_url }} |
| 53 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 54 | + |
| 55 | + automerge-existing: |
| 56 | + runs-on: ubuntu-slim |
| 57 | + if: github.event_name == 'workflow_dispatch' |
| 58 | + steps: |
| 59 | + - name: Merge open Dependabot PRs |
| 60 | + run: | |
| 61 | + gh pr list --repo "$GITHUB_REPOSITORY" \ |
| 62 | + --author "app/dependabot" \ |
| 63 | + --state open \ |
| 64 | + --json number,url \ |
| 65 | + --jq '.[].url' | |
| 66 | + while read -r pr_url; do |
| 67 | + echo "::group::Merging $pr_url" |
| 68 | + if gh pr merge --squash "$pr_url"; then |
| 69 | + echo "Merged $pr_url" |
| 70 | + else |
| 71 | + echo "::warning::Failed to merge $pr_url" |
| 72 | + fi |
| 73 | + echo "::endgroup::" |
| 74 | + done |
| 75 | + env: |
| 76 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments