|
| 1 | +name: Props Bot |
| 2 | + |
| 3 | +on: |
| 4 | + # This event runs anytime a PR is (re)opened, updated, marked ready for review, or labeled. |
| 5 | + # GitHub does not allow filtering the `labeled` event by a specific label. |
| 6 | + # However, the logic below will short-circuit the workflow when the `props-bot` label is not the one being added. |
| 7 | + # Note: The pull_request_target event is used instead of pull_request because this workflow needs permission to comment |
| 8 | + # on the pull request. Because this event grants extra permissions to `GITHUB_TOKEN`, any code changes within the PR |
| 9 | + # should be considered untrusted. See https://securitylab.github.com/research/github-actions-preventing-pwn-requests/. |
| 10 | + pull_request_target: |
| 11 | + types: |
| 12 | + - opened |
| 13 | + - synchronize |
| 14 | + - reopened |
| 15 | + - labeled |
| 16 | + - ready_for_review |
| 17 | + # This event runs anytime a comment is added or deleted. |
| 18 | + # You cannot filter this event for PR comments only. |
| 19 | + # However, the logic below does short-circuit the workflow for issues. |
| 20 | + issue_comment: |
| 21 | + types: |
| 22 | + - created |
| 23 | + # This event will run everytime a new PR review is initially submitted. |
| 24 | + pull_request_review: |
| 25 | + types: |
| 26 | + - submitted |
| 27 | + # This event runs anytime a PR review comment is created or deleted. |
| 28 | + pull_request_review_comment: |
| 29 | + types: |
| 30 | + - created |
| 31 | + |
| 32 | +# Cancels all previous workflow runs for pull requests that have not completed. |
| 33 | +concurrency: |
| 34 | + # The concurrency group contains the workflow name and the branch name for pull requests |
| 35 | + # or the commit hash for any other events. |
| 36 | + group: ${{ github.workflow }}-${{ contains( fromJSON( '["pull_request_target", "pull_request_review", "pull_request_review_comment"]' ), github.event_name ) && github.head_ref || github.sha }} |
| 37 | + cancel-in-progress: true |
| 38 | + |
| 39 | +# Disable permissions for all available scopes by default. |
| 40 | +# Any needed permissions should be configured at the job level. |
| 41 | +permissions: {} |
| 42 | + |
| 43 | +jobs: |
| 44 | + # Compiles a list of props for a pull request. |
| 45 | + # |
| 46 | + # Performs the following steps: |
| 47 | + # - Collects a list of contributor props and leaves a comment. |
| 48 | + # - Removes the props-bot label, if necessary. |
| 49 | + props-bot: |
| 50 | + name: Generate a list of props |
| 51 | + runs-on: ubuntu-24.04 |
| 52 | + permissions: |
| 53 | + # The action needs permission `write` permission for PRs in order to add a comment. |
| 54 | + pull-requests: write |
| 55 | + contents: read |
| 56 | + timeout-minutes: 20 |
| 57 | + # The job will run when pull requests are open, ready for review and: |
| 58 | + # |
| 59 | + # - A comment is added to the pull request. |
| 60 | + # - A review is created or commented on (unless PR originates from a fork). |
| 61 | + # - The pull request is opened, synchronized, marked ready for review, or reopened. |
| 62 | + # - The `props-bot` label is added to the pull request. |
| 63 | + if: | |
| 64 | + ( |
| 65 | + github.event_name == 'issue_comment' && github.event.issue.pull_request || |
| 66 | + ( contains( fromJSON( '["pull_request_review", "pull_request_review_comment"]' ), github.event_name ) && ! github.event.pull_request.head.repo.fork ) || |
| 67 | + github.event_name == 'pull_request_target' && github.event.action != 'labeled' || |
| 68 | + 'props-bot' == github.event.label.name |
| 69 | + ) && |
| 70 | + ( ! github.event.pull_request.draft && github.event.pull_request.state == 'open' || ! github.event.issue.draft && github.event.issue.state == 'open' ) |
| 71 | +
|
| 72 | + steps: |
| 73 | + - name: Gather a list of contributors |
| 74 | + uses: WordPress/props-bot-action@trunk |
| 75 | + with: |
| 76 | + format: 'git' |
| 77 | + |
| 78 | + - name: Remove the props-bot label |
| 79 | + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 |
| 80 | + if: ${{ github.event.action == 'labeled' && 'props-bot' == github.event.label.name }} |
| 81 | + with: |
| 82 | + retries: 2 |
| 83 | + retry-exempt-status-codes: 418 |
| 84 | + script: | |
| 85 | + github.rest.issues.removeLabel({ |
| 86 | + owner: context.repo.owner, |
| 87 | + repo: context.repo.repo, |
| 88 | + issue_number: process.env.ISSUE_NUMBER, |
| 89 | + name: 'props-bot' |
| 90 | + }); |
| 91 | + env: |
| 92 | + ISSUE_NUMBER: ${{ github.event.number }} |
0 commit comments