|
| 1 | +# Automatically merge pull requests opened by web3-bot, as soon as (and only if) all tests pass. |
| 2 | +# This reduces the friction associated with updating with our workflows. |
| 3 | + |
| 4 | +on: [ pull_request ] |
| 5 | +name: Automerge |
| 6 | + |
| 7 | +jobs: |
| 8 | + automerge-check: |
| 9 | + if: github.event.pull_request.user.login == 'web3-bot' |
| 10 | + runs-on: ubuntu-latest |
| 11 | + outputs: |
| 12 | + status: ${{ steps.should-automerge.outputs.status }} |
| 13 | + steps: |
| 14 | + - uses: actions/checkout@v2 |
| 15 | + with: |
| 16 | + fetch-depth: 0 |
| 17 | + - name: Check if we should automerge |
| 18 | + id: should-automerge |
| 19 | + run: | |
| 20 | + for commit in $(git rev-list --first-parent origin/${{ github.event.pull_request.base.ref }}..${{ github.event.pull_request.head.sha }}); do |
| 21 | + committer=$(git show --format=$'%ce' -s $commit) |
| 22 | + echo "Committer: $committer" |
| 23 | + if [[ "$committer" != "[email protected]" ]]; then |
| 24 | + echo "Commit $commit wasn't committed by web3-bot, but by $committer." |
| 25 | + echo "::set-output name=status::false" |
| 26 | + exit |
| 27 | + fi |
| 28 | + done |
| 29 | + echo "::set-output name=status::true" |
| 30 | + automerge: |
| 31 | + needs: automerge-check |
| 32 | + runs-on: ubuntu-latest |
| 33 | + # The check for the user is redundant here, as this job depends on the automerge-check job, |
| 34 | + # but it prevents this job from spinning up, just to be skipped shortly after. |
| 35 | + if: github.event.pull_request.user.login == 'web3-bot' && needs.automerge-check.outputs.status == 'true' |
| 36 | + steps: |
| 37 | + - name: Wait on tests |
| 38 | + uses: lewagon/wait-on-check-action@bafe56a6863672c681c3cf671f5e10b20abf2eaa # v0.2 |
| 39 | + with: |
| 40 | + ref: ${{ github.event.pull_request.head.sha }} |
| 41 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 42 | + wait-interval: 10 |
| 43 | + running-workflow-name: 'automerge' # the name of this job |
| 44 | + - name: Merge PR |
| 45 | + uses: pascalgn/automerge-action@741c311a47881be9625932b0a0de1b0937aab1ae # v0.13.1 |
| 46 | + env: |
| 47 | + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" |
| 48 | + MERGE_LABELS: "" |
| 49 | + MERGE_METHOD: "squash" |
| 50 | + MERGE_DELETE_BRANCH: true |
0 commit comments