Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
584 changes: 0 additions & 584 deletions .github/workflows/certify-uk-release.yaml

This file was deleted.

260 changes: 260 additions & 0 deletions .github/workflows/check-model-compatibility.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
# Check each country's newest model release against the Microcosm builds the
# bundle pins, on Tuesdays and Fridays, and by hand for a named version.
#
# The plan job reads the bundle manifest and PyPI. For each country it picks
# the newest policyengine-us or policyengine-uk release (or the version named
# by hand) and leaves the country out when the bundle already pins that
# version, or a pull request from its branch exists (open, closed or merged),
# or the branch exists without one.
#
# The check job runs once per remaining country. scripts/bundle.py
# certify-build --in-place runs the compatibility check on the pinned national
# and local-area builds with that model version and certifies them for it,
# changing only this checkout's files. The checkout keeps no token while the
# check runs. A pass then makes a GitHub App token, commits the files
# certify-build lists to the new branch
# certify/<country>/<national build>/<local-area build>/<model package>-<version>,
# and opens a draft pull request with its body, which a person merges. Earlier
# certification pull requests stay open, so any checked version can still be
# chosen.
#
# For each country it checks, a run uploads a compatibility-<country> result
# file (the model version, the builds, passed, failed or cancelled, and the
# pull request), which the drift report reads to find the version that day's
# check passed. A failure opens or comments on the country's "Model
# compatibility check failed" issue; the next pass closes it, and a cancelled
# run leaves it as it is.

name: Check model compatibility

on:
schedule:
# 06:17 UTC on Tuesdays and Fridays.
- cron: "17 6 * * 2,5"
workflow_dispatch:
inputs:
country:
description: Country to check
type: choice
options: [both, us, uk]
default: both
model_version:
description: Model version to check (default the newest on PyPI); needs one country
required: false

permissions:
contents: read

# One run at a time, so two runs never push the same branch. Waiting runs
# queue in order (up to 100): without queue: max, a newly queued run would
# cancel the one already waiting.
concurrency:
group: check-model-compatibility
cancel-in-progress: false
queue: max

env:
UV_VERSION: "0.13.4"
PYTHON_VERSION: "3.13"
# Keep equal to PYTHON_VERSION. The repository's .python-version asks for a
# newer Python, and every uv command here must use the 3.13 environment the
# job installed; each `uv run` passes --no-sync for the same reason.
UV_PYTHON: "3.13"

jobs:
plan:
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
pull-requests: read
outputs:
matrix: ${{ steps.plan.outputs.matrix }}
any: ${{ steps.plan.outputs.any }}
steps:
- uses: actions/checkout@v6
with:
ref: main
- uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Choose the model version to check for each country
id: plan
env:
GH_TOKEN: ${{ github.token }}
COUNTRY: ${{ inputs.country || 'both' }}
MODEL_VERSION: ${{ inputs.model_version }}
run: |
python scripts/compatibility_workflow.py plan \
--country "$COUNTRY" \
--model-version "$MODEL_VERSION" \
--repository "$GITHUB_REPOSITORY" \
--github-output "$GITHUB_OUTPUT"
# After the outputs are written, so the other country is still checked.
- name: Fail when a country could not be planned
if: steps.plan.outputs.unplanned != ''
env:
UNPLANNED: ${{ steps.plan.outputs.unplanned }}
run: |
echo "::error::Could not plan the check for: $UNPLANNED. The step above lists the error."
exit 1

check:
needs: plan
# Also when the plan job failed for the other country.
if: ${{ !cancelled() && needs.plan.outputs.any == 'true' }}
runs-on: ${{ vars.CERTIFY_RUNNER_X64 != '' && (vars.CI_RUNNER_EVENTS == '' || contains(format(',{0},', vars.CI_RUNNER_EVENTS), format(',{0},', github.event_name))) && vars.CERTIFY_RUNNER_X64 || 'ubuntu-latest' }}
timeout-minutes: 300
strategy:
fail-fast: false
matrix:
include: ${{ fromJSON(needs.plan.outputs.matrix) }}
permissions:
contents: read
issues: write
steps:
# First, so the result and issue steps below always have the script.
# The checkout keeps no token: certify-build runs without one.
- uses: actions/checkout@v6
with:
ref: main
persist-credentials: false
# The US check downloads about 11 GB of builds and certify-build wants
# 5 GB more free; a GitHub-hosted runner starts with about 14 GB. These
# directories hold tools this job does not use.
- name: Free disk space on a GitHub-hosted runner
if: runner.environment == 'github-hosted'
run: |
df -h /
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc \
/usr/local/.ghcup /opt/hostedtoolcache/CodeQL
df -h /
- uses: astral-sh/setup-uv@v8.1.0
with:
version: ${{ env.UV_VERSION }}
- uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install the pinned environment
env:
COUNTRY: ${{ matrix.country }}
run: uv sync --frozen --extra "$COUNTRY" --extra dev --python "$PYTHON_VERSION"
# A step that reaches its limit fails, and is recorded as a failed
# check. A job that reaches its limit is cancelled, which would be
# recorded as cancelled and leave the failure issue alone.
- name: Check and certify the pinned builds for the model version
id: certify
timeout-minutes: 270
env:
HUGGING_FACE_TOKEN: ${{ secrets.HUGGING_FACE_TOKEN }}
COUNTRY: ${{ matrix.country }}
NATIONAL_RELEASE: ${{ matrix.national_release }}
NATIONAL_BUILD: ${{ matrix.national_build }}
LOCAL_AREA_RELEASE: ${{ matrix.local_area_release }}
LOCAL_AREA_BUILD: ${{ matrix.local_area_build }}
MODEL_VERSION: ${{ matrix.model_version }}
OUTPUT_DIR: ${{ runner.temp }}/certification
FOOTER: >-
Opened by the check-model-compatibility workflow in
${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}.
Each run opens its own pull request and leaves earlier ones open;
merge the version you want.
run: |
uv run --no-sync python scripts/bundle.py certify-build \
--country "$COUNTRY" \
--national-release "$NATIONAL_RELEASE" \
--national-build "$NATIONAL_BUILD" \
--local-area-release "$LOCAL_AREA_RELEASE" \
--local-area-build "$LOCAL_AREA_BUILD" \
--model-version "$MODEL_VERSION" \
--in-place \
--output-dir "$OUTPUT_DIR" \
--pr-body-footer "$FOOTER"
# Made after the check, because App tokens last an hour and the check
# can take several. Pushes and pull requests made with the App's token
# start the pull request's own workflows; the job's token would not.
- name: Generate GitHub App token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Open a draft certification pull request
id: pull-request
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
BRANCH: ${{ matrix.branch }}
COUNTRY: ${{ matrix.country }}
MODEL_PACKAGE: ${{ matrix.model_package }}
MODEL_VERSION: ${{ matrix.model_version }}
NATIONAL_BUILD: ${{ matrix.national_build }}
OUTPUT_DIR: ${{ runner.temp }}/certification
run: |
# certify-build wrote one pull request body and one list of the
# files it changed into this directory, next to its log and the
# builds it downloaded.
shopt -s nullglob
bodies=("$OUTPUT_DIR"/*.pr-body.md)
changed=("$OUTPUT_DIR"/*.changed-paths.txt)
if (( ${#bodies[@]} != 1 || ${#changed[@]} != 1 )); then
echo "::error::certify-build left ${#bodies[@]} pull request bodies and ${#changed[@]} changed-path lists in $OUTPUT_DIR, not one of each."
exit 1
fi
body="${bodies[0]}"
label=$(printf '%s' "$COUNTRY" | tr '[:lower:]' '[:upper:]')
git switch -c "$BRANCH"
git add --pathspec-from-file="${changed[0]}"
git -c user.name="github-actions[bot]" \
-c user.email="41898282+github-actions[bot]@users.noreply.github.com" \
commit -q -m "Certify Microcosm $label build $NATIONAL_BUILD for $MODEL_PACKAGE $MODEL_VERSION"
# git asks gh for credentials, and gh gives it GH_TOKEN.
gh auth setup-git
git push origin "HEAD:refs/heads/$BRANCH"
url=$(gh pr create --draft --base main --head "$BRANCH" \
--title "Certify Microcosm $label build $NATIONAL_BUILD for $MODEL_PACKAGE $MODEL_VERSION" \
--body-file "$body")
echo "url=$url" >> "$GITHUB_OUTPUT"
# python3, not python: the runner has it even when setup-python failed.
- name: Write the result file
if: always()
env:
ENTRY: ${{ toJSON(matrix) }}
COUNTRY: ${{ matrix.country }}
CERTIFY_OUTCOME: ${{ steps.certify.outcome }}
PULL_REQUEST_OUTCOME: ${{ steps.pull-request.outcome }}
JOB_STATUS: ${{ job.status }}
PULL_REQUEST: ${{ steps.pull-request.outputs.url }}
run: |
python3 scripts/compatibility_workflow.py record \
--entry "$ENTRY" \
--certify-outcome "$CERTIFY_OUTCOME" \
--pull-request-outcome "$PULL_REQUEST_OUTCOME" \
--job-status "$JOB_STATUS" \
--pull-request "$PULL_REQUEST" \
--run-url "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" \
--out "$RUNNER_TEMP/compatibility/compatibility-$COUNTRY.json"
- name: Upload the result file
if: always()
uses: actions/upload-artifact@v4
with:
name: compatibility-${{ matrix.country }}
path: ${{ runner.temp }}/compatibility/compatibility-${{ matrix.country }}.json
if-no-files-found: error
- name: Open, update or close the failure issue
if: always()
env:
GH_TOKEN: ${{ github.token }}
ENTRY: ${{ toJSON(matrix) }}
CERTIFY_OUTCOME: ${{ steps.certify.outcome }}
PULL_REQUEST_OUTCOME: ${{ steps.pull-request.outcome }}
JOB_STATUS: ${{ job.status }}
PULL_REQUEST: ${{ steps.pull-request.outputs.url }}
run: |
python3 scripts/compatibility_workflow.py report \
--entry "$ENTRY" \
--certify-outcome "$CERTIFY_OUTCOME" \
--pull-request-outcome "$PULL_REQUEST_OUTCOME" \
--job-status "$JOB_STATUS" \
--pull-request "$PULL_REQUEST" \
--run-url "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" \
--repository "$GITHUB_REPOSITORY"
12 changes: 6 additions & 6 deletions .github/workflows/pr_code_changes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
# 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 UK certification's
# qualify and replay jobs, which hold the GitHub App
# key and a write token: a GitHub-hosted larger runner
# only
# 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 other certification jobs
# always keep GitHub-hosted runners. Each CI_RUNNER_X64 job has a read-only
# 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
Expand Down
1 change: 1 addition & 0 deletions changelog.d/787.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
On Tuesdays and Fridays, and by hand for a named version, a workflow now checks each country's newest model release against the Microcosm builds the bundle pins and opens a draft certification pull request when it passes. It replaces `certify-uk-release.yaml`, which checked policyengine-uk wheels only against policyengine-uk-data releases.
Loading