Repository navigation
283 lines (272 loc) · 11.5 KB
/
Copy pathpr_code_changes.yaml
File metadata and controls
283 lines (272 loc) · 11.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
280
281
282
283
# Report PR code checks on opened, synchronised, reopened and edited pull
# requests and on manual dispatch. Skip code jobs when a pull request's
# changed paths match the documentation exclusions.
#
# Runners. These jobs, the docs build, and Lint and Test on pushes to main
# run on ubuntu-latest unless a repository variable names another runner
# (Settings > Secrets and variables > Actions > Variables):
# CI_RUNNER_X64 instead of ubuntu-latest for those jobs
# CERTIFY_RUNNER_X64 instead of ubuntu-latest for the model compatibility
# workflow's check job, which holds the GitHub App key
# and a token that can write issues: a GitHub-hosted
# larger runner only
# CI_RUNNER_EVENTS optional: event names separated by commas, no
# spaces, such as push,workflow_dispatch. Only those
# events use the variables. Empty means every event.
# Delete a variable to go back to ubuntu-latest for the next run. Versioning,
# Publish, NotifyConsumers, the docs deploy and the compatibility workflow's
# plan job always keep GitHub-hosted runners. Each CI_RUNNER_X64 job has a read-only
# GITHUB_TOKEN, since the organisation's default token can write. Test and
# BundleVerification read the dataset with HUGGING_FACE_TOKEN, so point the
# variables only at runners where that data may be processed, such as the
# organisation's GitHub-hosted larger runners.
# tests/test_ci_runner_variables.py holds the workflows to this.
name: Code changes
on:
pull_request:
types: [opened, synchronize, reopened, edited]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
Changes:
name: Detect code changes
runs-on: ubuntu-latest
permissions:
contents: read
timeout-minutes: 10
outputs:
code: ${{ steps.paths.outputs.code }}
steps:
- uses: actions/checkout@v6
if: github.event_name == 'pull_request'
with:
fetch-depth: 0
persist-credentials: false
- name: Check changed paths
id: paths
env:
EVENT: ${{ github.event_name }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
status=1
if [[ "$EVENT" == pull_request ]]; then
status=0
git diff --quiet "$BASE_SHA...$HEAD_SHA" -- . ':(exclude)docs/**' \
':(exclude)README.md' ':(exclude)CONTRIBUTING.md' \
':(exclude)CHANGELOG.md' ':(exclude)CODE_OF_CONDUCT.md' || status=$?
fi
case "$status" in
0) echo "code=false" >> "$GITHUB_OUTPUT" ;;
1) echo "code=true" >> "$GITHUB_OUTPUT" ;;
*) exit "$status" ;;
esac
check-changelog:
name: Check changelog fragment
needs: Changes
if: needs.Changes.outputs.code == 'true'
runs-on: ${{ vars.CI_RUNNER_X64 != '' && (vars.CI_RUNNER_EVENTS == '' || contains(format(',{0},', vars.CI_RUNNER_EVENTS), format(',{0},', github.event_name))) && vars.CI_RUNNER_X64 || 'ubuntu-latest' }}
permissions:
contents: read
timeout-minutes: 10
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
fetch-depth: 0
persist-credentials: false
- name: Install towncrier
run: pip install towncrier
- name: Check for changelog fragment
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
run: .github/check-changelog.sh "${BASE_SHA:-origin/main}"
Lint:
needs: Changes
if: needs.Changes.outputs.code == 'true'
runs-on: ${{ vars.CI_RUNNER_X64 != '' && (vars.CI_RUNNER_EVENTS == '' || contains(format(',{0},', vars.CI_RUNNER_EVENTS), format(',{0},', github.event_name))) && vars.CI_RUNNER_X64 || 'ubuntu-latest' }}
permissions:
contents: read
timeout-minutes: 10
steps:
- uses: actions/checkout@v6
- name: Install ruff
run: pip install ruff
- name: Run ruff format check
run: ruff format --check .
- name: Run ruff check
run: ruff check .
Mypy:
needs: Changes
if: needs.Changes.outputs.code == 'true'
runs-on: ${{ vars.CI_RUNNER_X64 != '' && (vars.CI_RUNNER_EVENTS == '' || contains(format(',{0},', vars.CI_RUNNER_EVENTS), format(',{0},', github.event_name))) && vars.CI_RUNNER_X64 || 'ubuntu-latest' }}
permissions:
contents: read
timeout-minutes: 20
steps:
- uses: actions/checkout@v6
- name: Install uv
uses: astral-sh/[email protected]
with:
version: "0.13.4"
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.13'
- name: Install package
run: uv pip install -e .[dev] --system
- name: Run mypy (informational)
run: mypy src/policyengine || echo "mypy found errors (non-blocking until codebase is clean)"
Python-Compat:
name: Install + smoke-import (py${{ matrix.python-version }})
needs: Changes
if: needs.Changes.outputs.code == 'true'
runs-on: ${{ vars.CI_RUNNER_X64 != '' && (vars.CI_RUNNER_EVENTS == '' || contains(format(',{0},', vars.CI_RUNNER_EVENTS), format(',{0},', github.event_name))) && vars.CI_RUNNER_X64 || 'ubuntu-latest' }}
permissions:
contents: read
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
python-version: ["3.11", "3.12", "3.13", "3.14"]
steps:
- uses: actions/checkout@v6
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
- name: Install uv
uses: astral-sh/[email protected]
with:
version: "0.13.4"
- name: Install package (no country-model extras)
run: uv pip install --system .
- name: Smoke-import core modules
run: python -c "import policyengine; from policyengine.core import Dataset, Policy, Simulation; from policyengine.outputs import aggregate, poverty, inequality; print('import OK')"
BundleVerification:
name: Verify release inputs and bundle packages
needs: Changes
# Private manifest credentials are available only to trusted repository PRs.
if: needs.Changes.outputs.code == 'true' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
runs-on: ${{ vars.CI_RUNNER_X64 != '' && (vars.CI_RUNNER_EVENTS == '' || contains(format(',{0},', vars.CI_RUNNER_EVENTS), format(',{0},', github.event_name))) && vars.CI_RUNNER_X64 || 'ubuntu-latest' }}
permissions:
contents: read
timeout-minutes: 30
env:
POLICYENGINE_SKIP_COUNTRY_IMPORTS: "1"
steps:
- uses: actions/checkout@v6
- name: Install uv
uses: astral-sh/[email protected]
with:
version: "0.13.4"
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.13'
- name: Install package for TRACE verification
run: uv pip install -e . h5py --system
- name: Check reviewed release inputs
env:
HUGGING_FACE_TOKEN: ${{ secrets.HUGGING_FACE_TOKEN }}
run: |
if [[ -z "${HUGGING_FACE_TOKEN:-}" ]]; then
echo "::error::Full private release verification requires HUGGING_FACE_TOKEN"
exit 1
fi
python scripts/check_release_credentials.py
python scripts/bundle.py check --published-spm --include-tros --strict-tros
python scripts/release_lock.py
- name: Install bundle package scaffold
run: |
uv pip install -e ".[models]" --system
python - <<'PY'
import subprocess
import sys
from policyengine import bundle
requirements = [
requirement
for requirement in bundle.bundle_install_requirements(
countries=["us", "uk"]
)
if not requirement.startswith("policyengine==")
]
subprocess.check_call(
[sys.executable, "-m", "pip", "install", *requirements]
)
PY
- name: Check installed package consistency
run: python -m pip check
- name: Verify bundle packages
run: policyengine bundle verify --country us --country uk --packages-only --json
Test:
needs: Changes
if: needs.Changes.outputs.code == 'true'
runs-on: ${{ vars.CI_RUNNER_X64 != '' && (vars.CI_RUNNER_EVENTS == '' || contains(format(',{0},', vars.CI_RUNNER_EVENTS), format(',{0},', github.event_name))) && vars.CI_RUNNER_X64 || 'ubuntu-latest' }}
permissions:
contents: read
# Observed 2026-10-14..15: 28 to 54 minutes per Python version, with runs on
# 3.12 and 3.13 cancelled at the old 60-minute limit. By early Nov, 65 to 90
# minutes on 3.11-3.13, where coverage.py 7.13.5 uses its C trace function
# (sys.monitoring only on 3.14, which takes 47-60), and one of them was often
# cancelled at 90: 3.12 on #730, 3.11 on #735 (#736). With the UK pin on
# policyengine-uk 2.165.1 (#731, 4 Nov), 3.11 took 105 minutes, 3.13 100
# and 3.12 86, so 105 cancels them; 2.174.1 adds parameters and variables
# again. Fail a hung job instead of holding a shared org runner for the
# 6-hour default.
timeout-minutes: 150
strategy:
fail-fast: false
matrix:
python-version: ['3.11', '3.12', '3.13', '3.14']
steps:
- name: Checkout repo
uses: actions/checkout@v6
- name: Install uv
uses: astral-sh/[email protected]
with:
version: "0.13.4"
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
- name: Install package
run: uv pip install -e .[dev] --system
- name: Install policyengine
run: uv pip install policyengine --system
- name: Run tests with coverage
run: make test
env:
HUGGING_FACE_TOKEN: ${{ secrets.HUGGING_FACE_TOKEN }}
PR-Checks:
name: PR code checks
if: always()
needs: [Changes, check-changelog, Lint, Mypy, Python-Compat, BundleVerification, Test]
runs-on: ubuntu-latest
permissions: {}
timeout-minutes: 5
steps:
- name: Fail when a dependency failed or was cancelled
if: failure() || cancelled()
run: exit 1
- name: Check code job results
env:
RESULTS: ${{ toJSON(needs) }}
VERIFY_BUNDLE: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }}
run: |
jq -e --arg verify_bundle "$VERIFY_BUNDLE" '
(keys == ["BundleVerification", "Changes", "Lint", "Mypy",
"Python-Compat", "Test", "check-changelog"]) and
(.Changes as $changes |
$changes.result == "success" and
($changes.outputs.code == "true" or $changes.outputs.code == "false") and
all(del(.Changes) | to_entries[];
.value.result ==
(if $changes.outputs.code == "false" or
(.key == "BundleVerification" and $verify_bundle == "false")
then "skipped" else "success" end)))
' <<< "$RESULTS"