Repository navigation
126 lines (122 loc) · 5.69 KB
/
Copy pathsquad-pr-readiness.yml
File metadata and controls
126 lines (122 loc) · 5.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
name: Squad PR Readiness
# Privileged half of the PR readiness checklist. The github org blocks
# pull_request_target, so PR events arrive through squad-pr-readiness-request.yml
# (`pull_request`, read-only token, no secrets, no checkout), which uploads only
# a claim: the PR number and head SHA it ran for. Squad CI completions still
# refresh the checklist. workflow_run runs THIS file from the default branch.
#
# Trust boundary:
# - Only default-branch scripts run. PR code is never checked out or executed;
# every check reads the GitHub API.
# - The claim is untrusted data: a fork controls the request workflow. It is
# parsed strictly and bound to the workflow_run payload and the live PR (same
# head SHA, same head repository, this base repository, still open) before
# anything is written. See scripts/workflow-run-pr-binding.mjs.
# - Squad CI runs carry no claim, so only GitHub's own
# workflow_run.pull_requests (same-repository PRs) are bound, as before.
#
# Concurrency: only bound runs deduplicate, one group per PR head. A
# workflow-level group is joined by every delivery before any job's `if:` is
# evaluated, so a skipped run (a fork or push run of Squad CI, a failed request)
# could cancel a real refresh, and PRs from one head branch to different bases
# would share a key. So `bind` joins no group, and `readiness` joins one keyed
# by the bound PR number and head SHA. It is skipped when nothing was bound.
# `bind` checks the head outside any group, so a delivery can bind head A and
# start `readiness` after head B's refresh started. Keyed by head, it cannot
# cancel or replace B's refresh, and scripts/pr-readiness.mjs writes nothing
# once the PR head is no longer A.
on:
workflow_run:
workflows: ["Squad CI", "Squad PR Readiness Request"]
types: [completed]
permissions:
actions: read
contents: read
pull-requests: write
statuses: read
checks: read
jobs:
bind:
# workflow_run check runs land on the default-branch tip, the head commit of
# any PR from dev (dev to main). scripts/pr-readiness.mjs lists this name and
# `readiness` in SELF_CHECK_NAMES, so that PR's "CI passing" ignores them.
name: readiness-bind
runs-on: ubuntu-latest
timeout-minutes: 5
# Skip Dependabot, push runs of Squad CI, Squad CI runs with no
# same-repository PR, and request runs that did not succeed.
if: >-
github.event.workflow_run.event == 'pull_request'
&& github.event.workflow_run.actor.login != 'dependabot[bot]'
&& ((github.event.workflow_run.path == '.github/workflows/squad-ci.yml'
&& github.event.workflow_run.pull_requests[0] != null)
|| (github.event.workflow_run.path == '.github/workflows/squad-pr-readiness-request.yml'
&& github.event.workflow_run.conclusion == 'success'))
outputs:
bound: ${{ steps.bind.outputs.bound }}
pr_number: ${{ steps.bind.outputs.pr_number }}
head_sha: ${{ steps.bind.outputs.head_sha }}
base_ref: ${{ steps.bind.outputs.base_ref }}
draft: ${{ steps.bind.outputs.draft }}
labels: ${{ steps.bind.outputs.labels }}
steps:
- name: Checkout binding script (default branch only)
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 #v7
with:
persist-credentials: false
sparse-checkout: |
scripts/workflow-run-pr-binding.mjs
sparse-checkout-cone-mode: false
- name: Download PR claim (untrusted data)
if: github.event.workflow_run.path == '.github/workflows/squad-pr-readiness-request.yml'
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 #v8
with:
name: squad-pr-readiness-request
path: ${{ runner.temp }}/pr-readiness-request
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ github.token }}
- name: Bind the workflow run to its pull request
id: bind
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 #v9
env:
CLAIM_DIR: ${{ runner.temp }}/pr-readiness-request
with:
script: |
const { bindWorkflowRun } = await import(`${process.env.GITHUB_WORKSPACE}/scripts/workflow-run-pr-binding.mjs`);
await bindWorkflowRun({
github,
context,
core,
claimDir: process.env.CLAIM_DIR,
claimWorkflowPath: '.github/workflows/squad-pr-readiness-request.yml',
});
readiness:
needs: bind
# Runs only for a bound PR. When bind is skipped, fails or binds nothing,
# this job is skipped and never joins the group below.
if: needs.bind.outputs.bound == 'true'
runs-on: ubuntu-latest
timeout-minutes: 5
concurrency:
group: squad-pr-readiness-${{ needs.bind.outputs.pr_number }}-${{ needs.bind.outputs.head_sha }}
cancel-in-progress: true
steps:
- name: Checkout readiness script (default branch only)
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 #v7
with:
persist-credentials: false
sparse-checkout: |
scripts/pr-readiness.mjs
sparse-checkout-cone-mode: false
- name: Check PR readiness
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ needs.bind.outputs.pr_number }}
PR_HEAD_SHA: ${{ needs.bind.outputs.head_sha }}
PR_BASE_REF: ${{ needs.bind.outputs.base_ref }}
PR_DRAFT: ${{ needs.bind.outputs.draft }}
PR_LABELS: ${{ needs.bind.outputs.labels }}
REPO_OWNER: ${{ github.repository_owner }}
REPO_NAME: ${{ github.event.repository.name }}
RUN_NAME: ${{ github.workflow }}
run: node scripts/pr-readiness.mjs