Skip to content

chore(IDX): release workflow as a template (DRY) - #269

Merged
basvandijk merged 6 commits into
mirroringfrom
basvandijk/release-testing-on-github-tweaks
Jun 26, 2024
Merged

basvandijk merged 6 commits into
mirroringfrom
basvandijk/release-testing-on-github-tweaks

Conversation

@basvandijk

Copy link
Copy Markdown
Collaborator

No description provided.

@github-actions github-actions Bot added the chore label Jun 25, 2024
@basvandijk
basvandijk marked this pull request as ready for review June 25, 2024 20:33
@basvandijk
basvandijk requested a review from a team as a code owner June 25, 2024 20:33
@marko-k0 marko-k0 changed the title chore(IDX): have the Release Testing workflow as a template (DRY) chore(IDX): release workflow as a template (DRY) Jun 26, 2024
@basvandijk
basvandijk added this pull request to the merge queue Jun 26, 2024
Merged via the queue into mirroring with commit 8140e48 Jun 26, 2024
gitlab-dfinity pushed a commit that referenced this pull request Jun 26, 2024
…into 'master'

chore(github-sync): PR#269 / chore(IDX): release workflow as a template (DRY)

[GitHub PR 269](#269) (branch: basvandijk/release-testing-on-github-tweaks) 

See merge request dfinity-lab/public/ic!20064
@marko-k0
marko-k0 deleted the basvandijk/release-testing-on-github-tweaks branch July 12, 2024 12:19
AleDema pushed a commit to AleDema/ic that referenced this pull request Nov 18, 2026
Upgrades Python from 3.12 to
[3.15](https://docs.python.org/3.15/whatsnew/3.15.html), the latest
Python release. With rules_python 2.5.1, `python_version = "3.15"`
resolves to [CPython
3.15.2](https://www.python.org/downloads/release/python-3152/) from
python-build-standalone 20261026, the same release that provides
3.12.16. The CI jobs that run Python outside Bazel move to 3.15 as well.

This PR was stacked on dfinity#12158 (rules_python 2.5.1), which has landed. It
now targets master, with master merged in (no conflicts).

The released artifacts don't change. Built unstamped, all their 133
output files are byte-identical to those of dfinity#12158 and of master. That
covers the GuestOS, HostOS and SetupOS images, GuestOS's
`launch-measurements.json`, `//publish/binaries:bundle` and
`//publish/canisters:bundle`. That build ran our Python tools under
3.15.2 (see Verification).

## Changes

- **`MODULE.bazel`**:
- `python_version` 3.12 → 3.15, with a comment that the CI jobs below
set up the same version.
  - A `pip.override` that patches simple-parsing's wheel (next item).
- **`bazel/simple_parsing_missing_type.patch`** (new): Python 3.15
implements [PEP 661](https://peps.python.org/pep-0661/), which makes
`dataclasses.MISSING` a sentinel and removes its class
`dataclasses._MISSING_TYPE`. simple-parsing imports that class, so
`import simple_parsing` fails with `ImportError: cannot import name
'_MISSING_TYPE' from 'dataclasses'`.
- That broke `//toolchains/sysimage:build_container_base_image`, which
the `local-base-*` IC-OS variants use. It also broke the four
`launch_bare_metal_main` binaries, one of which the daily bare-metal
workflow runs.
- Neither simple-parsing's latest release, 0.1.9, nor its main branch
fixes it.
- The patch puts `type(dataclasses.MISSING)` in place of the class in
the four modules that use it. Three of them define `_MISSING_TYPE =
type(MISSING)`, and `helpers/hparams/hparam.py` writes it into its
annotations. On Python 3.14 and older, that is the class simple-parsing
imported.
- On 3.15, `type(dataclasses.MISSING)` is the builtin class `sentinel`,
which all sentinels share, `dataclasses.KW_ONLY` included. Outside of
type annotations, simple-parsing uses the class once, in `field()`:
`isinstance(default_factory, ...)`. The patch makes that
`default_factory is not MISSING`, the check that `subgroups()` already
uses.
- rules_python repacks a patched wheel with `zip`, which the dev and
build images install (`ci/container/files/packages.common`).
- rules_python applies a `pip.override` only to the wheel file it names.
It skips it without a warning when the lock has another one. So
`requirements.in` pins simple-parsing to 0.1.7, and the new test below
fails when simple-parsing doesn't import.
- Only Bazel targets import simple-parsing. The CI jobs that `pip
install -r requirements.txt` install it but don't import it.
- **`toolchains/sysimage/BUILD.bazel`** and
**`toolchains/sysimage/build_container_base_image_help_test.sh`** (new):
`//toolchains/sysimage:build_container_base_image_help_test` runs
`build_container_base_image --help`, as
`//ci/githubstats:query_help_test` does for `query.py`. The programs
that import simple-parsing only run in manual targets: the builds of the
`local-base-*` IC-OS variants and the `launch_bare_metal_main` binaries.
So without this test, only the daily bare-metal workflow would notice
when simple-parsing fails to import.
- **`requirements.in`**:
- Lower bounds for the packages whose pinned release doesn't support
Python 3.15 (next section).
- `simple-parsing==0.1.7`, the release whose wheel the `pip.override`
patches, with a comment that points to the override.
- The heading of the packages that aren't used directly no longer says
"for python 3.12". It now gives the reason for
`typing_extensions>=4.6.0`:
[4.6.0](https://github.com/python/typing_extensions/blob/main/CHANGELOG.md#release-460-may-22-2023)
is the first release that can be imported on Python 3.12 and later.
- **`requirements.txt`**: regenerated with `bazel run
//:python-requirements.update`. Its header now says Python 3.15.
- **`.github/workflows/`**: see "CI jobs".

## Python packages

Neither `pip.parse` nor `pip install` can use a release that has no
`cp315`, `abi3` or pure-Python wheel: they build its sdist instead.
These pins had none:

| package | lock: before → after | why |
|---|---|---|
| pandas | 2.3.3 → 3.1.1 | 3.0.6 is the first release with Python 3.15
wheels, so `pandas>=3.0.6`. |
| numpy (via pandas) | 2.4.1 → 2.5.5 | 2.5.2 is the first release with
Python 3.15 wheels, so `numpy>=2.5.2`. On Python 3.14 and later pandas
only requires `numpy>=2.3.3`, which 2.4.1 satisfies. |
| cffi (via cryptography and pynacl) | 2.0.0 → 2.1.1 | 2.1.0 has Python
3.15 wheels, but they crash on 3.15.0b4 and later
([python-cffi/cffi#263](python-cffi/cffi#263),
fixed in 2.1.1 by [dfinity#269](python-cffi/cffi#269)),
so `cffi>=2.1.1`. |
| cbor2 | 6.0.1 → 6.3.0 | 6.1.5 is the first release with Python 3.15
wheels, so `cbor2>=6.1.5`. Nothing in the repository imports it. |

Once a pin no longer satisfies `requirements.in`, pip-compile picks the
latest release, hence 3.1.1, 2.5.5 and 6.3.0. The other packages keep
their pins:

- pandas 3 doesn't depend on pytz, and needs tzdata only on Windows and
Emscripten, so both leave the lock.
- PyYAML stays at 6.0.2, because no release has Python 3.15 wheels.
6.0.3's sdist differs from 6.0.2's only in metadata and a Cython
free-threading directive.
  - pip builds 6.0.2 from its sdist.
- With libyaml's headers it compiles the C extension. GitHub's Ubuntu
runner images have `libyaml-dev`.
- Without them it falls back to pure Python. That's the case in our dev
and build images, so for Bazel's `pip.parse` too.
- simple-parsing stays at 0.1.7, now pinned in `requirements.in` (see
the patch above).
- cbor, uuid, nested-lookup, idracredfishsupport and sev-snp-measure
were already built from their sdists, and still build.
- protobuf stays at 6.33.5 here. dfinity#12166 (protobuf 36.2) moves it to
7.36.2; whichever of the two PRs lands second has to re-lock
`requirements.txt` on top of the other.
- charset-normalizer, coverage, mypy and wrapt have no Python 3.15
wheels at their pins, so they install their pure-Python wheels. mypy
1.16.1 still runs: it reports the type error in a one-line smoke test.

## CI jobs

- **`python-version` 3.12 → 3.15** in `ci-main.yml`'s Python CI Tests,
`security-checks.yml`, `bazel-dependency-submission.yml` and
`container-scan-nightly.yml`. The pinned actions/setup-python v6.2.0
resolves the version from
[actions/python-versions](https://github.com/actions/python-versions)'
manifest, which has 3.15.2 for Ubuntu 22.04, 24.04 and 26.04, on x64 and
arm64.
- On `ubuntu-latest` (Ubuntu 26.04), setup-python takes 3.15 from the
runner's tool cache or downloads it.
- `container-scan-nightly.yml` runs setup-python inside the ic-build
container (Ubuntu 26.04). There it downloads the manifest's
`linux-26.04-x64` build, as it does for 3.12.16 today.
- **New setup-python 3.15 steps** in
`update-mainnet-icos-revisions.yaml` and
`update-mainnet-canister-revisions.yaml`. Both run
`ci/src/mainnet_revisions/mainnet_revisions.py`, which Python CI Tests
tests.
- Until now they ran it with whatever `python` the runner provides and
with the ic-build image's `python3` (3.14.4).
- Both workflows run in dry-run mode on pull requests that change them,
so this PR's CI runs the new steps.
- In the canister job, `mainnet_revisions.py` then runs `bazel run`.
setup-python exports `PATH` and `LD_LIBRARY_PATH` for the steps after
it. Our `--incompatible_strict_action_env` keeps both out of the
actions. `container-scan-nightly.yml` already runs Bazel (`bazel run
vuln-scan`) after a setup-python step in the same container.
- **Left as they are**:
- `ci/scripts/targets.py` (CI Main's Bazel Test All and Check
PULL_REQUEST_BAZEL_TARGETS jobs) and
`ci/scripts/determine-initial-guest-os-versions.py`
(`release-testing.yml`) use only the standard library. They run on the
ic-build image's `python3` (3.14.4). Running them under 3.15 would need
a setup-python step in each of those jobs, or a newer Python in the
image. This PR doesn't change `ci/container/`.
- `ci/scripts/repro-check` (`repro-check.yml`) is meant to run on a
verifier's stock `python3`. It keeps running on `ubuntu:26.04`'s.
- The one-liners in `.github/actions/bazel/action.yaml` (a UUID) and
`schedule-daily-bare-metal.yml` (secret masking).
- Python programs that CI runs through Bazel, such as
`launch_bare_metal`, already use the hermetic 3.15.

## Upstream changes that touch our setup

- **PEP 661 (sentinel values)**: see the simple-parsing patch above. The
four modules it patches are the only ones in simple-parsing 0.1.7 that
use `_MISSING_TYPE`. The other private standard-library names it uses,
such as `dataclasses._FIELDS` and the `argparse._*Action` classes, still
exist in 3.15.
- **[pandas 3.0](https://pandas.pydata.org/docs/whatsnew/v3.0.0.html)**,
a major release, makes Copy-on-Write and the new `str` dtype the
defaults, among other changes. Our users are `ci/githubstats/query.py`
and `//rs/recovery/subnet_splitting/split_finder`. Their tests pass.
`query.py`'s `top` and `last` commands, which its tests don't cover,
print the same tables as with pandas 2.3.3 (see Verification).
- **argparse**: 3.15's `--help` prints an option's metavar once (`-u,
--file_share_url str` instead of `-u str, --file_share_url str`). Its
`ArgumentDefaultsHelpFormatter` no longer appends `(default: None)` to
required options. That changes the `--help` text of our tools, not how
they parse arguments.
- **[PEP 765](https://peps.python.org/pep-0765/)** (3.14) makes the
compiler warn about `return` in a `finally` block.
`ic-os/dev-tools/bare_metal_deployment/deploy.py` has one in
`deploy_server`, so the bare-metal tool now prints a `SyntaxWarning`
when it starts. Its behavior doesn't change. Avoiding the `return` needs
a restructuring of `deploy_server`, which I left to its owners. Compiled
with 3.12 and with 3.15, all 126 Python sources of the repository
produce no other new warning.

## Verification

All of this ran in the dev container:

- **Module graph and analysis**: `bazel mod graph` resolves every module
to the same version as dfinity#12158. `bazel build //... --nobuild` analyzes
all 3388 targets. After merging master, `bazel mod graph` resolves every
module to the same version as master, `bazel build //... --nobuild`
analyzes all 3390 targets, and `bazel run //:buildifier` changes
nothing. Its only warning is the `rules_qemu` `use_repo` warning that
master also prints.
- **Lock file**: `bazel run //:python-requirements.update` regenerated
`requirements.txt`, and `//:python-requirements.test` passes. With
simple-parsing pinned in `requirements.in`, the update leaves
`requirements.txt` unchanged.
- **Builds**: these build:
  - all 26 Python targets (17 `py_binary`, 5 `py_test`, 4 `py_library`)
  - `//ic-os/dev-tools/bare_metal_deployment:redfish_scripts`
- `//:mke2fs`, `//:fuse2fs` and `//:debugfs`, built with
rules_foreign_cc's Python-based meson
- **Tests**: these pass:
  - `//:python-requirements.test`
- `//bazel/inject_version_into_wasm_tests:inspect_stamped_trivial_wasm`
  - `//ci/githubstats:query_test` and `//ci/githubstats:query_help_test`
  - `//ci/scripts:repro_check_test`
  - `//rs/recovery/subnet_splitting/split_finder:split_finder_test`
  - `//rs/recovery/subnet_splitting:integration_test`
- `//toolchains/sysimage:build_container_base_image_help_test`. When I
pointed the `pip.override` at another wheel file,
`simple_parsing-0.1.9-py3-none-any.whl` (the same mismatch as a lock
that moved on without the override), rules_python left the locked 0.1.7
wheel unpatched without a warning, and the test failed with the
`ImportError` above.
- **Programs**: all 16 `py_binary`s other than
`//:python-requirements.update` print their `--help` under `bazel run`.
That includes `//ic-os:sev-snp-measure` and, with the patch, the five
simple-parsing users. Without the patch, those five fail with the
`ImportError` above.
- **simple-parsing**: I parsed two example command lines, each in two
environments:
- Command lines: the one `build_container_base_image`'s `main()` would
get, and `deploy.py`'s with `--config_path zh2-dll01.yaml` and the flags
of the daily bare-metal job.
- Environments: Python 3.15.2 with the patched simple-parsing, and the
3.12.16 build of dfinity#12158 with the unpatched one.
- All 32 parsed values are identical. The `--help` texts differ only as
described under argparse above.
- I ran this with both versions of the patch: the first commit's, whose
`field()` kept the `isinstance()` check, and the second commit's. Their
parsed values and the `--help` of the five users are identical.
- With the patched simple-parsing on 3.15.2,
`field(default_factory=list)`, `field()` and `field(default=1)` return
the expected `default` and `default_factory`. `typing.get_type_hints`
resolves the annotations of `field()`, `flag()`, `subgroups()`,
`utils.default_value()` and hparam's `uniform()` and `log_uniform()`,
which use the class, to `... | sentinel`.
- **`query.py`**: I ran its `top` (three variants) and `last
--skip-download` (two variants) commands with a fake database cursor,
which returns rows of the column names and types of `top.sql` and
`last.sql`. I ran them in the runfiles of this build and of dfinity#12158's
build (Python 3.12.16, pandas 2.3.3), with the same `query.py`, and they
print identical tables.
- **Python CI Tests, locally**: I created a venv from the hermetic
Python 3.15.2 and ran the job's steps: `pip install -r
requirements.txt`, then `pytest -m "not fails_on_merge_train"` in
`ci/src`, with `PYTHONPATH` as in `ci-main.yml`. The result is 250
passed with 8 warnings, the same as the job on master with 3.12.16. I
ran it twice:
  - without libyaml's headers, so PyYAML falls back to pure Python
- with `libyaml-dev` installed, as on GitHub's runners, so PyYAML builds
its C extension
- **Release artifacts**: I built these unstamped:
- the IC-OS bundles that `ci/container/build-ic.sh --icos` builds:
GuestOS prod disk and update, GuestOS recovery update, HostOS update,
and SetupOS
  - `//publish/binaries:bundle` and `//publish/canisters:bundle`

All 133 output files are byte-identical to the build of dfinity#12158 and to
master's. A rebuild with an execution log shows the 53 spawns that have
the 3.15 interpreter among their inputs:
- 40 actions that build the IC-OS images (with our
`//toolchains/sysimage` tools) and the bundles
  - 6 rules_pkg `pkg_tar` actions
- 5 genrules: GuestOS's two `launch-measurements.json` (sev-snp-measure)
and three root partitions
  - libfuse's meson build
  - sev-snp-measure's entry point

Because the interpreter is one of their inputs, a cached result from a
3.12 build can't serve any of them, so they all ran under 3.15.2 on this
branch.

That build was of the first commit. The second commit changes
simple-parsing's patch, `requirements.in` and a comment in
`MODULE.bazel`, adds a test, and leaves `requirements.txt` as it is.
`bazel cquery 'deps(...)'` of the release targets lists 111042 labels,
none of them simple-parsing's or `build_container_base_image`'s. So the
second commit can't change the artifacts, and I didn't rebuild them for
it.
- **Lint**: on both commits, the Linter job's checks pass: shfmt, ruff,
buf, DFINITY capitalization, do-not-merge, buildifier, gazelle and
buf-breaking. Its autofixes leave the tree unchanged.
- **Not verified locally**: macOS, Namespace RBE, the daily bare-metal
deployment itself, and the workflows that don't run on this PR:
- `security-checks.yml` runs the base branch's copy of the workflow
(`pull_request_target`).
  - `bazel-dependency-submission.yml` runs on master only.
  - `container-scan-nightly.yml` runs nightly.

This PR's CI builds and tests `//...`. It also runs Python CI Tests and
both mainnet-revisions workflows.

## Follow-ups

- Drop the simple-parsing patch, and its pin in `requirements.in`, once
a simple-parsing release supports Python 3.15.
- The `SyntaxWarning` from `deploy.py` (PEP 765, above).
- Optionally, Python 3.15 for the scripts that run on the ic-build
image's `python3` (see "Left as they are"). That needs a setup-python
step in each of those jobs, or a newer Python in the image.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants