|
42 | 42 | labels: linux-ubuntu-latest |
43 | 43 | permissions: |
44 | 44 | checks: write |
| 45 | + contents: read |
| 46 | + pull-requests: read |
45 | 47 | steps: |
| 48 | + # The reporter triggers on EVERY pull_request run of "Trigger Integration |
| 49 | + # Tests" (opened/synchronize/reopened/labeled/closed), but the |
| 50 | + # workflow_run payload does NOT expose the originating sub-action, so we |
| 51 | + # cannot filter on it directly. Recover the needed context from the PR |
| 52 | + # and post the synthetic success only for the opened/synchronize/reopened |
| 53 | + # scope the old inline job covered: |
| 54 | + # - skip when the PR is closed (outside the old job's scope), and |
| 55 | + # - skip when a real label preview is running for this head (an internal |
| 56 | + # PR carrying the integration-test label): trigger-tests-pr dispatches |
| 57 | + # the real suite and driver-test posts the real check for the same |
| 58 | + # app + name + head_sha, so a premature success placeholder would race |
| 59 | + # that check and could mask a real preview failure. |
| 60 | + # Fork PRs KEEP the placeholder even when labeled: their label preview |
| 61 | + # cannot dispatch (no secret access), so nothing else posts the required |
| 62 | + # check for them. This is a read-only lookup (no checkout / no execution |
| 63 | + # of PR-controlled content) and does not weaken the SECURITY note above. |
| 64 | + - name: Decide whether to post the placeholder |
| 65 | + id: gate |
| 66 | + uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0 |
| 67 | + env: |
| 68 | + HEAD_SHA: ${{ github.event.workflow_run.head_sha }} |
| 69 | + with: |
| 70 | + script: | |
| 71 | + let prs = context.payload.workflow_run.pull_requests || []; |
| 72 | + let number = prs.length ? prs[0].number : null; |
| 73 | + if (number === null) { |
| 74 | + // Fork PRs: workflow_run.pull_requests is empty. Resolve by SHA. |
| 75 | + const { data } = await github.rest.repos.listPullRequestsAssociatedWithCommit({ |
| 76 | + owner: context.repo.owner, |
| 77 | + repo: context.repo.repo, |
| 78 | + commit_sha: process.env.HEAD_SHA, |
| 79 | + }); |
| 80 | + number = data.length ? data[0].number : null; |
| 81 | + } |
| 82 | + if (number === null) { |
| 83 | + // No PR resolvable (unexpected) — default to posting so the |
| 84 | + // required check isn't left unfulfilled. |
| 85 | + core.setOutput('post', 'true'); |
| 86 | + return; |
| 87 | + } |
| 88 | + const { data: pr } = await github.rest.pulls.get({ |
| 89 | + owner: context.repo.owner, |
| 90 | + repo: context.repo.repo, |
| 91 | + pull_number: number, |
| 92 | + }); |
| 93 | + const isFork = pr.head.repo.full_name !== `${context.repo.owner}/${context.repo.repo}`; |
| 94 | + const hasLabel = pr.labels.some(l => l.name === 'integration-test'); |
| 95 | + const isClosed = pr.state === 'closed'; |
| 96 | + const skip = isClosed || (hasLabel && !isFork); |
| 97 | + console.log(`PR #${number} fork=${isFork} label=${hasLabel} closed=${isClosed} -> post=${!skip}`); |
| 98 | + core.setOutput('post', (!skip).toString()); |
| 99 | +
|
46 | 100 | - name: Generate GitHub App token (this repo) |
47 | 101 | id: app-token |
| 102 | + if: steps.gate.outputs.post == 'true' |
48 | 103 | uses: actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859 # v3.0.0 |
49 | 104 | with: |
50 | 105 | app-id: ${{ secrets.INTEGRATION_TEST_APP_ID }} |
|
53 | 108 | repositories: databricks-sql-python |
54 | 109 |
|
55 | 110 | - name: Post skipped Python Integration Tests check |
| 111 | + if: steps.gate.outputs.post == 'true' |
56 | 112 | uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0 |
57 | 113 | env: |
58 | 114 | HEAD_SHA: ${{ github.event.workflow_run.head_sha }} |
|
0 commit comments