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