diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml index 4dd11fc..f8c95f0 100644 --- a/.github/workflows/automerge.yml +++ b/.github/workflows/automerge.yml @@ -9,7 +9,7 @@ on: jobs: merge: - if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.actor.login == 'dependabot[bot]' + if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.actor.login == 'dependabot[bot]' runs-on: ubuntu-latest permissions: contents: write @@ -18,8 +18,17 @@ jobs: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # nothing is checked out here, so gh has no remote to infer the repo from GH_REPO: ${{ github.repository }} + BRANCH: ${{ github.event.workflow_run.head_branch }} + HEAD_SHA: ${{ github.event.workflow_run.head_sha }} steps: - - run: gh pr merge --squash --match-head-commit "$HEAD_SHA" "$BRANCH" + - if: github.event.workflow_run.conclusion == 'success' + run: gh pr merge --squash --match-head-commit "$HEAD_SHA" "$BRANCH" + # a cancelled build or a pull request that has since moved on gets another run, so + # neither is worth a mention + - if: failure() || github.event.workflow_run.conclusion == 'failure' || github.event.workflow_run.conclusion == 'timed_out' + run: | + if [ "$(gh pr view "$BRANCH" --json state,headRefOid --jq '"\(.state) \(.headRefOid)"')" = "OPEN $HEAD_SHA" ]; then + gh pr comment "$BRANCH" --body "@erikbrinkman automerge left this open: $REASON" + fi env: - BRANCH: ${{ github.event.workflow_run.head_branch }} - HEAD_SHA: ${{ github.event.workflow_run.head_sha }} + REASON: ${{ github.event.workflow_run.conclusion == 'success' && 'the merge failed' || 'the build failed' }}