|
| 1 | +# Check if e2e-desktop should run: trigger in comment, or (optional) main branch, or [e2e] in commit. |
| 2 | +# Use in e2e-desktop-comment.yml (comment only) or ci.yml (comment + main + commit). |
| 3 | + |
| 4 | +name: Check comment trigger |
| 5 | +description: Check if trigger phrase in PR comment; optionally also main branch or [e2e] in commit |
| 6 | +inputs: |
| 7 | + trigger: |
| 8 | + description: Trigger phrase to look for (e.g. /e2e-desktop) |
| 9 | + required: true |
| 10 | + check_main: |
| 11 | + description: Also return true when ref is refs/heads/main |
| 12 | + required: false |
| 13 | + default: "false" |
| 14 | + check_commit: |
| 15 | + description: Also return true when [e2e] in commit message |
| 16 | + required: false |
| 17 | + default: "false" |
| 18 | + allow_workflow_dispatch: |
| 19 | + description: When true, workflow_dispatch events always return true (for manual runs) |
| 20 | + required: false |
| 21 | + default: "false" |
| 22 | +outputs: |
| 23 | + should_run: |
| 24 | + description: "true if any condition matches, else false" |
| 25 | + value: ${{ steps.check.outputs.should_run }} |
| 26 | +runs: |
| 27 | + using: composite |
| 28 | + steps: |
| 29 | + - name: Check if e2e-desktop should run |
| 30 | + id: check |
| 31 | + uses: actions/github-script@v7 |
| 32 | + env: |
| 33 | + TRIGGER: ${{ inputs.trigger }} |
| 34 | + CHECK_MAIN: ${{ inputs.check_main }} |
| 35 | + CHECK_COMMIT: ${{ inputs.check_commit }} |
| 36 | + ALLOW_WORKFLOW_DISPATCH: ${{ inputs.allow_workflow_dispatch }} |
| 37 | + with: |
| 38 | + script: | |
| 39 | + const trigger = process.env.TRIGGER; |
| 40 | + const checkMain = process.env.CHECK_MAIN === 'true'; |
| 41 | + const checkCommit = process.env.CHECK_COMMIT === 'true'; |
| 42 | + const allowWorkflowDispatch = process.env.ALLOW_WORKFLOW_DISPATCH === 'true'; |
| 43 | +
|
| 44 | + if (allowWorkflowDispatch && context.eventName === 'workflow_dispatch') { |
| 45 | + core.setOutput('should_run', 'true'); |
| 46 | + return; |
| 47 | + } |
| 48 | +
|
| 49 | + if (checkMain && context.ref === 'refs/heads/main') { |
| 50 | + core.setOutput('should_run', 'true'); |
| 51 | + return; |
| 52 | + } |
| 53 | +
|
| 54 | + if (checkCommit) { |
| 55 | + let msg = ''; |
| 56 | + if (context.eventName === 'push' && context.payload.head_commit) { |
| 57 | + msg = context.payload.head_commit.message || ''; |
| 58 | + } else if (context.eventName === 'pull_request' && context.payload.pull_request) { |
| 59 | + const pr = context.payload.pull_request; |
| 60 | + const { data: commit } = await github.rest.repos.getCommit({ |
| 61 | + owner: context.repo.owner, |
| 62 | + repo: context.repo.repo, |
| 63 | + ref: pr.head.sha, |
| 64 | + }); |
| 65 | + msg = commit.commit?.message || ''; |
| 66 | + } |
| 67 | + if (msg.includes('[e2e]')) { |
| 68 | + core.setOutput('should_run', 'true'); |
| 69 | + return; |
| 70 | + } |
| 71 | + } |
| 72 | +
|
| 73 | + let commentMatch = false; |
| 74 | + if (context.eventName === 'issue_comment' && context.payload.issue?.pull_request) { |
| 75 | + commentMatch = (context.payload.comment?.body || '').includes(trigger); |
| 76 | + } else if (context.eventName === 'pull_request' && context.payload.pull_request) { |
| 77 | + const pr = context.payload.pull_request; |
| 78 | + const { data: comments } = await github.rest.issues.listComments({ |
| 79 | + owner: context.repo.owner, |
| 80 | + repo: context.repo.repo, |
| 81 | + issue_number: pr.number, |
| 82 | + }); |
| 83 | + commentMatch = comments.some(c => c.body && c.body.includes(trigger)); |
| 84 | + } |
| 85 | +
|
| 86 | + core.setOutput('should_run', commentMatch ? 'true' : 'false'); |
0 commit comments