Repository navigation
279 lines (260 loc) · 13.5 KB
/
Copy pathpython-test.yml
File metadata and controls
279 lines (260 loc) · 13.5 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
name: python-test
# Minimal PR/push gate for pure-Python regressions (no native engine): the
# focused fingerprint canonicalization contract test and the release-rule
# tests (scripts/release_pair.py and its wiring into the release workflows).
on:
push:
branches: [main, master]
pull_request:
# ready_for_review starts the suites skipped on draft PRs.
types: [opened, synchronize, reopened, ready_for_review]
merge_group:
permissions:
contents: read
# Only superseded PR runs share a cancellable group. Other events use run_id.
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
authz:
name: authz
# Standard GitHub-hosted label; never a larger-runner label.
runs-on: ubuntu-24.04
permissions: {}
# No timeout-minutes: the owner's no-time-limits rule (check-no-time-limits refuses new ones).
steps:
- name: Only our own pull requests and our own events run CI
env:
EVENT: ${{ github.event_name }}
REPO: ${{ github.repository }}
HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }}
HEAD_IS_FORK: ${{ github.event.pull_request.head.repo.fork }}
ASSOCIATION: ${{ github.event.pull_request.author_association }}
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
WR_HEAD_REPO: ${{ github.event.workflow_run.head_repository.full_name }}
WR_ACTOR: ${{ github.event.workflow_run.triggering_actor.login }}
GH_TOKEN: ${{ github.token }} # read-only use: one permission lookup for workflow_run
# Bot logins whose same-repository pull requests count as ours: dependabot[bot]
# and the org's own GitHub App bot logins by name (space-separated), nothing else.
ALLOWED_BOTS: "dependabot[bot] pineforge-app[bot]"
run: |
set -eu
fail() { echo "::error title=authz::$1"; echo "authz: REFUSED: $1" >> "$GITHUB_STEP_SUMMARY"; exit 1; }
case "$EVENT" in
push|workflow_dispatch|schedule|merge_group|release|workflow_call|repository_dispatch)
# Only someone with write access to this repository (or our App's token) can cause these
# events; none of them runs pull-request code.
;;
workflow_run)
# Bind identity to the triggering run and its re-runner.
# These two App bots are fixed canon policy; ALLOWED_BOTS is PR-only.
[ -n "${WR_HEAD_REPO:-}" ] || fail "workflow_run head repository is missing"
[ -n "${WR_ACTOR:-}" ] || fail "workflow_run triggering actor is missing"
[ "$WR_HEAD_REPO" = "$REPO" ] || fail "workflow_run head repository does not match this repository"
case "$WR_ACTOR" in
"pineforge-app[bot]"|"pineforge-ci-dispatcher[bot]") ;;
*"[bot]") fail "workflow_run bot is not on the canon allowlist" ;;
*)
perm=$(gh api "repos/$REPO/collaborators/$WR_ACTOR/permission" --jq .permission 2>/dev/null) || fail "workflow_run permission lookup failed"
case "$perm" in admin|maintain|write) ;; *) fail "workflow_run triggering actor does not have write permission" ;; esac ;;
esac ;;
pull_request)
[ "$HEAD_REPO" = "$REPO" ] || fail "pull request from another repository (${HEAD_REPO:-unknown})"
[ "$HEAD_IS_FORK" = "false" ] || fail "pull request from a fork"
case "$ASSOCIATION" in
OWNER|MEMBER|COLLABORATOR) ;;
*)
case " $ALLOWED_BOTS " in
*" $PR_AUTHOR "*) ;;
*)
# A member whose org membership is private shows as CONTRIBUTOR: ask GitHub for the
# author's permission on this repository; anything but admin/maintain/write (or a
# failed call) refuses.
perm=$(gh api "repos/$REPO/collaborators/$PR_AUTHOR/permission" --jq .permission 2>/dev/null || echo none)
case "$perm" in admin|maintain|write) ;; *) fail "author ${PR_AUTHOR:-unknown} (${ASSOCIATION:-NONE}) has permission '$perm', not write, and is not an allowlisted bot" ;; esac ;;
esac ;;
esac ;;
*) fail "event $EVENT does not run CI (pull_request_target and other events are not allowed)" ;;
esac
echo "authz: allowed ($EVENT${PR_AUTHOR:+ by $PR_AUTHOR})" >> "$GITHUB_STEP_SUMMARY"
changes:
needs: authz
# A skipped classifier keeps release/ready red, even for docs-only drafts.
if: ${{ !github.event.pull_request.draft }}
# Standard GitHub-hosted runner for every configured event.
runs-on: ubuntu-24.04
outputs:
docs-only: ${{ steps.paths.outputs.docs-only }}
steps:
- name: Install push runner tools
if: github.event_name == 'push'
run: sudo apt-get update && sudo apt-get install -y python3
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
if: github.event_name == 'pull_request'
with:
fetch-depth: 0
persist-credentials: false
- name: Detect documentation-only PR
id: paths
env:
EVENT_NAME: ${{ github.event_name }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
python3 - <<'PY'
import os
import subprocess
from pathlib import PurePosixPath
docs_only = False
if os.environ['EVENT_NAME'] == 'pull_request':
paths = subprocess.check_output([
'git', 'diff', '--name-only', '--no-renames', '-z',
os.environ['BASE_SHA'] + '...' + os.environ['HEAD_SHA'], '--',
]).split(b'\0')
paths = [PurePosixPath(os.fsdecode(path)) for path in paths if path]
# Release tests consume these documents and scan automation files.
test_inputs = {'README.md', 'docs/release-chain.md', 'LICENSE'}
docs_only = bool(paths) and all(
str(path) not in test_inputs and
path.parts[:2] != ('.github', 'workflows') and
path.parts[0] not in {'scripts', 'tools'} and (
path.suffix in {'.md', '.rst'} or str(path) == 'LICENSE' or
(path.parts[0] == 'docs' and path.suffix in {
'.txt', '.png', '.jpg', '.jpeg', '.gif', '.svg', '.webp', '.pdf',
})
)
for path in paths
)
with open(os.environ['GITHUB_OUTPUT'], 'a', encoding='utf-8') as output:
output.write('docs-only=' + str(docs_only).lower() + '\n')
PY
fingerprint-canonical:
needs: [authz, changes]
if: ${{ !github.event.pull_request.draft && (needs.changes.outputs.docs-only == 'false') }}
runs-on: ubuntu-24.04
steps:
- name: Install push runner tools
if: github.event_name == 'push'
run: sudo apt-get update && sudo apt-get install -y ca-certificates git
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.12"
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: "20"
- name: Fingerprint canonical regression
run: |
python3 -m py_compile docker/run_json.py tests/test_fingerprint_canonical.py
python3 tests/test_fingerprint_canonical.py
release-rules:
needs: [authz, changes]
if: ${{ !github.event.pull_request.draft && (needs.changes.outputs.docs-only == 'false') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.12"
- name: Install workflow YAML parser
run: python3 -m pip install 'PyYAML==6.0.3' -r facts/requirements-validation.txt
- name: Download published hpo wheels
run: |
set -euo pipefail
cd "$RUNNER_TEMP"
curl -fsSL --retry 3 --max-time 120 \
'https://github.com/pineforge-4pass/pineforge-hpo/releases/download/v0.15.0/pineforge_hpo-0.15.0-py3-none-any.whl' \
-o pineforge_hpo-0.15.0-py3-none-any.whl
printf '%s\n' 'ee09f5fd72fd43c26027c294d0e871ab6f3d856fbc5d28c53910a3bbcfa968a6 pineforge_hpo-0.15.0-py3-none-any.whl' > hpo-accepted.sha256
sha256sum -c --strict hpo-accepted.sha256
curl -fsSL --retry 3 --max-time 120 \
'https://github.com/pineforge-4pass/pineforge-hpo/releases/download/v0.13.2/pineforge_hpo-0.13.2-py3-none-any.whl' \
-o pineforge_hpo-0.13.2-py3-none-any.whl
printf '%s\n' '57fff4c49cba794a9657e7882376eee294366843cf0442306195b8390dd0d073 pineforge_hpo-0.13.2-py3-none-any.whl' > hpo-rejected.sha256
sha256sum -c --strict hpo-rejected.sha256
{
echo "PINEFORGE_HPO_ACCEPTED_WHEEL=$RUNNER_TEMP/pineforge_hpo-0.15.0-py3-none-any.whl"
echo "PINEFORGE_HPO_REJECTED_WHEEL=$RUNNER_TEMP/pineforge_hpo-0.13.2-py3-none-any.whl"
} >> "$GITHUB_ENV"
- name: Release rules (version order, prerelease channel, 1.0 pairing)
run: |
python3 -m py_compile scripts/release_pair.py
python3 -m unittest discover -s tests -p 'test_release_*.py' -v
description-renderer:
needs: [authz, changes]
if: ${{ !github.event.pull_request.draft && (needs.changes.outputs.docs-only == 'false') }}
runs-on: ubuntu-24.04
steps:
- name: Install push runner tools
if: github.event_name == 'push'
run: sudo apt-get update && sudo apt-get install -y ca-certificates git
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: '3.12'
- run: python3 -m pip install -r facts/requirements-validation.txt
- name: Existing description renderer acceptance regressions
run: python3 -m unittest discover -s tests -p 'test_repo_descriptions.py' -v
release-ready-replay:
needs: [authz, changes]
if: ${{ !github.event.pull_request.draft && (needs.changes.outputs.docs-only == 'false') }}
runs-on: ubuntu-24.04
steps:
- name: Install push runner tools
if: github.event_name == 'push'
run: sudo apt-get update && sudo apt-get install -y ca-certificates git jq
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: '3.12'
- run: python3 -m pip install 'PyYAML==6.0.3' -r facts/requirements-validation.txt
- name: Replay ready release and failure recovery without production credentials
run: python3 tools/release-dry-run/dry_run.py --ready
release-ready:
name: release/ready
if: ${{ always() }}
needs: [authz, changes, fingerprint-canonical, release-rules, description-renderer, release-ready-replay]
runs-on: ubuntu-24.04
steps:
- name: Install push runner tools
if: needs.authz.result == 'success' && (github.event_name == 'push')
run: sudo apt-get update && sudo apt-get install -y python3
- name: Refuse an unauthorised run before anything else
if: ${{ needs.authz.result != 'success' }}
run: |
echo "::error::authz did not pass; nothing of this run's code is checked out or run"
exit 1
- name: Require the complete expected inventory
if: needs.authz.result == 'success'
env:
RESULTS: ${{ toJSON(needs) }}
EVENT_NAME: ${{ github.event_name }}
AUTHZ_OK: ${{ needs.authz.result == 'success' }}
run: |
python3 - <<'PY'
import json, os
results = json.loads(os.environ['RESULTS'])
expected = {'fingerprint-canonical', 'release-rules', 'description-renderer', 'release-ready-replay'}
if set(results) != expected | {'authz', 'changes'} or results['changes']['result'] != 'success':
raise SystemExit('release/ready: change detection failed or the job inventory differs')
if os.environ['AUTHZ_OK'] != 'true' or results['authz']['result'] != 'success':
raise SystemExit('release/ready: authz did not succeed')
docs_only = results['changes']['outputs'].get('docs-only')
if docs_only not in {'true', 'false'}:
raise SystemExit('release/ready: missing or invalid change detection output')
required_result = 'success'
if docs_only == 'true':
if os.environ['EVENT_NAME'] != 'pull_request':
raise SystemExit('release/ready: only a documentation-only PR may skip suites')
required_result = 'skipped'
if any(results[name]['result'] != required_result for name in expected):
raise SystemExit('release/ready: a required job failed, was cancelled, skipped or missing')
PY