detect-conflicting-prs.yml 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. name: "Detect conflicting PRs"
  2. on:
  3. workflow_dispatch: # manually
  4. # So that PRs touching the same files as the push are updated
  5. push:
  6. # So that the `dirtyLabel` is removed if conflicts are resolved
  7. pull_request_target: # - A pull request (even with conflicts)
  8. types:
  9. - synchronize # pushing more commits
  10. permissions:
  11. # no checkouts/branching needed
  12. contents: none
  13. # need by "eps1lon/actions-label-merge-conflict" to manage PR label/comments
  14. pull-requests: write
  15. # This allows a subsequently queued workflow run to interrupt/wait for previous runs
  16. concurrency:
  17. group: '${{ github.workflow }}'
  18. cancel-in-progress: false # true: interrupt, false = wait for
  19. jobs:
  20. detect-prs:
  21. name: Detect
  22. if: ${{ github.actor != 'dependabot[bot]' }} # avoid dependabot PRs
  23. runs-on: ubuntu-latest
  24. steps:
  25. - name: Label conflicting PRs that are open
  26. id: pr-labeler
  27. uses: eps1lon/actions-label-merge-conflict@v2.1.0
  28. with:
  29. repoToken: ${{ secrets.GITHUB_TOKEN }}
  30. retryAfter: 30 # seconds
  31. retryMax: 5 # atemps
  32. dirtyLabel: conflicts
  33. commentOnDirty: |
  34. Oh no 😟! Conflicts have been found.
  35. Please 🙏, take a moment and [address the merge conflicts](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/addressing-merge-conflicts) of your pull request before we can evaluate it again.
  36. Thanks in advance for your effort and patience ❤️!
  37. continueOnMissingPermissions: true
  38. - name: Print outputs
  39. run: echo ${{ join(steps.pr-labeler.outputs.*, ',') }}
  40. - name: Set PRs outputs
  41. id: set-prs
  42. run: |
  43. echo "$INPUT_PRS" \
  44. | jq --compact-output --raw-output 'to_entries | map({number: .key, dirty: .value})' \
  45. | sed -e 's/^/prs=/' \
  46. >> $GITHUB_OUTPUT
  47. echo "$INPUT_PRS" \
  48. | jq --raw-output 'to_entries | length' \
  49. | sed -e 's/^/prs-len=/' \
  50. >> $GITHUB_OUTPUT
  51. env:
  52. INPUT_PRS: ${{ steps.pr-labeler.outputs.prDirtyStatuses }}
  53. - name: Write job summary
  54. run: |
  55. echo "### Pull Request statuses" \
  56. >> $GITHUB_STEP_SUMMARY
  57. # render json array to a Markdown table with an optional "No records" message if empty
  58. echo "$INPUT_PRS" \
  59. | jq --raw-output 'map("| [#\(.number)](\(env.GITHUB_PUBLIC_URL)/\(.number)) | \(if (.dirty) then "❌" else "✔️" end) |") | join("\n") | if (. == "") then "\nNo records.\n" else "\n| PR | Mergeable? |\n|---:|:----------:|\n\(.)\n" end' \
  60. >> $GITHUB_STEP_SUMMARY
  61. env:
  62. GITHUB_PUBLIC_URL: ${{ format('{0}/{1}/pull', github.server_url, github.repository) }}
  63. INPUT_PRS: ${{ steps.set-prs.outputs.prs }}