diff --git a/.github/ci-paths.toml b/.github/ci-paths.toml new file mode 100644 index 0000000000..468ca03890 --- /dev/null +++ b/.github/ci-paths.toml @@ -0,0 +1,370 @@ +# Pre-commit-style path filters for pull-request CI: main.yml job `changes` runs `mise run dev:ci-changes` +# (.mise/scripts/dev/ci_changes.py), whose JSON list of skipped units gates the jobs. +# - Every pattern is a Python regex compiled with re.VERBOSE (whitespace and `# comments` ignored) and +# applied with re.search to each repo-relative path the PR changes (renames list old and new path). +# - `full`: one matching file runs every unit. +# - A unit runs when a changed file matches one of its `sets` or its `files`. +# - A changed file matching no unit must match `ignore`, otherwise every unit runs (fail-safe for new paths). +# - Unit keys: test-group.yml `suite` ids (cloud, db:psql, interop:ase, ...) or the job keys tested in +# main.yml, test_all.yml and test_windows.yml. A job whose key is not listed here always runs. +# - `variants`: the legs (`fips`, `non-fips`) of a test-group.yml suite run by the `test-suites` job of test_all.yml; +# ci_changes.py turns the running units into its `suites-matrix`, so a suite that does not run has no row at all. +# Not on `cloud` and `ui`, which keep their own jobs (their secrets must stay isolated). `bench` (variant -> HSM models) is optional. +# - [callers]: main.yml jobs skipped as a whole (one row) when none of their units runs. +# Tags, schedule and workflow_dispatch ignore this file and run everything. + +full = ''' + ^\.github/actions/(install-mise|install-rust|setup-nix|setup-nix-mise|cache-openssl-buildrs|cleanup-runner)/ +| ^\.mise/lib/(common|nix_helpers|kms_build|kms_server|test_slots)\.sh$ +| ^\.mise/scripts/common\.sh$ +| ^(mise\.toml|shell\.nix|default\.nix|rust-toolchain\.toml|Cargo\.toml|Cargo\.lock|docker-compose\.yml)$ +| ^nix/(openssl\.nix|openssl-fips-bootstrap\.|softhsm2\.nix|utimaco\.nix) +| ^\.cargo/config\.toml$ +| ^\.config/ +| ^crate/crypto/build\.rs$ +| ^(test_data|\.github/reusable_scripts)$ +''' + +# Changed files that legitimately trigger nothing (docs, packaging, release, ungated jobs' inputs). +ignore = ''' + \.md$ +| ^CHANGELOG/ +| ^\.github/(dependabot\.yml|\.markdownlint\.yaml|scripts/patch-kube-apiserver\.py)$ +| ^\.github/workflows/(benchmark|build_windows|cla|flamegraph|github_cache_cleanup|linkcheck|nightly|nix-update-hashes + |package-and-commit-sbom|packaging|packaging-apk|packaging-docker|packaging-kubernetes + |packaging-tests|release|supply-chain|update-generated-docs)\.yml$ +| ^\.github/actions/(docker-login-ghcr|import-gpg-key|push-package-cosmian|setup-helm-minikube)/ +| ^(supply-chain|sbom|cbom|charts|pkg|ansible|nix)/ +| ^(deny\.toml|_typos\.toml|lychee\.toml|\.pre-commit-config\.yaml|\.gitignore|\.gitattributes|LICENSE|\.cargo/audit\.toml)$ +| ^\.mise/tasks/(audit|bench|cse|demo|dev|git|package|release|sbom)/ +| ^\.mise/tasks/build/(docker|k8s-bins|k8s-csi-provider-image|k8s-operator-image|nix)$ +| ^\.mise/tasks/test/(k8s|pkg)/ +| ^\.mise/lib/(k8s|package_build|package_smoke|bench_helpers)\.sh$ +| ^\.mise/scripts/(audit|bench|demo|dev|git|package|pre-commit|release|sbom)/ +| ^\.github/ci-paths\.toml$ # validated by the `--self-test` run of the `changes` job +| ^\.github/workflows/test-group\.yml$ # reusable wrapper: no suite leg stands for it, any run of another suite exercises it +| ^\.github/workflows/(no-nix|test_windows)\.yml$ # Rust-only jobs: they run on crate changes, not on their own workflow files +| ^\.mise/scripts/windows/cargo_test\.ps1$ # idem: script of the Rust-only windows-cargo-test job +''' + +[sets] +# Whole workspace: compile-wide jobs and whole-workspace unit-test runners. +# kmip/ (KMIP XML vectors) and the Google CSE key fixture are read by crate tests. +rust = '^crate/ | ^kmip$ | ^documentation/docs/google_cse/test_wrapped_private_key$' + +# Code linked into cosmian_kms or the ckms / test_kms_server harness: triggers the units that still run on any +# server change (forward-proxy, xks-remote, spire). The negative lookaheads carve out feature-owned paths. +# sql/query.sql stays core: SQLite loads it under its query_sqlite.sql overrides (server_database/src/stores/mod.rs). +server_core = ''' + ^crate/(kmip|kmip-derive|access|interfaces|crypto|test_kms_server)/ +| ^crate/hsm/(base_hsm|softhsm2)/ +| ^crate/clients/(client|client_utils|ckms)/ +| ^crate/clients/clap/(?!src/actions/(google/|aws/|azure/|pkcs11/|bench/|cng\.rs$|cng_verify\.rs$|audit\.rs$)) +| ^crate/server_database/(?!src/stores/(sql/(pgsql\.rs|mysql\.rs|query_mysql\.sql)$|redis/)) +| ^crate/server/(?!src/(routes/(aws_xks|azure_ekm|google_cse|ms_dke|est|scep|ocsp|jose)/ + |routes/(crl|jwks|ui_auth)\.rs$ + |core/otel_metrics\.rs$ + |middlewares/otel_http_middleware\.rs$ + |config/wizard/ + |tests/)) +''' + +pg_store = '^crate/server_database/src/stores/sql/pgsql\.rs$' +mysql_store = '^crate/server_database/src/stores/sql/(mysql\.rs|query_mysql\.sql)$' + +# Database code shared by every backend (all of server_database except the other backends' stores). +db_core = '^crate/server_database/(?!src/stores/(sql/(pgsql\.rs|mysql\.rs|query_mysql\.sql)$|redis/))' + +# KMIP wire format (TTLV types and the /kmip endpoint) that every KMIP interop client exercises. +kmip_wire = '^crate/(kmip|kmip-derive)/ | ^crate/server/src/routes/kmip/' + +# Shared plumbing of every non-sqlite db leg (task, SoftHSM2 KEK helper). +db_shared = ''' + ^\.mise/tasks/test/db/_default$ +| ^\.mise/lib/softhsm2\.sh$ +''' + +interop_shared = '^\.mise/tasks/test/interop/_default$' + +windows = ''' + ^vcpkg(_fips)?\.json$ +| ^\.github/actions/(build-static-openssl|windows-vs-ninja)/ +| ^\.mise/scripts/windows/(common|install_ninja)\.ps1$ +''' + +# main.yml jobs that call a reusable workflow holding several units: main.yml skips the whole job (one row) +# when none of its units runs. Values are fnmatch patterns over unit keys. +[callers] +test = ["cargo-publish-dry-run", "xks-remote", "db:*", "interop:*", "cloud", "hsm", "pkcs11", "obs", "pki", "spire", "ui"] +windows = ["windows-*"] + +# ── main.yml ──────────────────────────────────────────────────────────────────────────────── +[units.cargo-clippy] +sets = ["rust"] +files = '^clippy\.toml$ | ^\.github/workflows/main\.yml$' + +[units.cargo-machete] +sets = ["rust"] +files = '^\.github/workflows/main\.yml$' + +[units.no-nix] +sets = ["rust"] + +[units.forward-proxy] +sets = ["server_core"] +files = '^\.github/workflows/(main|forward_proxy)\.yml$ | ^\.github/scripts/squid/' + +# `build-documentation` runs `docs:check-ai` (AI instruction files) and `docs:mdbook-build` (the mdBook site). +[units.build-documentation] +files = ''' + ^documentation/ +| ^(AGENTS|CONTRIBUTING)\.md$ +| ^\.github/(copilot-instructions\.md|instructions/|skills/) +| ^\.mise/(tasks|scripts)/docs/ +| ^\.github/workflows/main\.yml$ +''' + +# ── test_all.yml (non test-group jobs) ────────────────────────────────────────────────────── +[units.cargo-publish-dry-run] +sets = ["rust"] +files = '^\.github/workflows/(test_all|cargo-publish)\.yml$' + +[units.xks-remote] +sets = ["server_core"] +files = '^crate/server/src/routes/aws_xks/ | ^\.github/workflows/test_all\.yml$ | ^\.mise/scripts/test/(deploy_xks_remote|test_xks_remote|test_xks_aws_e2e)\.sh$' + +# ── test-group.yml suites (key = `suite` input; `pki` also gates the macOS job interop-macos) ── +[units."db:sqlite"] +sets = ["rust", "db_shared"] +files = '^\.mise/tasks/test/db/sqlite$' +variants = ["fips", "non-fips"] + +[units."db:psql"] +sets = ["db_core", "db_shared", "pg_store"] +files = '^\.mise/tasks/test/db/psql$' +variants = ["fips", "non-fips"] + +[units."db:mysql"] +sets = ["db_core", "db_shared", "mysql_store"] +files = '^\.mise/tasks/test/db/mysql$' +variants = ["fips", "non-fips"] + +[units."db:mariadb"] +sets = ["db_core", "db_shared", "mysql_store"] +files = '^\.mise/tasks/test/db/mariadb$' +variants = ["fips", "non-fips"] + +[units."db:percona"] +sets = ["db_core", "db_shared", "mysql_store"] +files = '^\.mise/tasks/test/db/percona$' +variants = ["fips", "non-fips"] + +[units."db:redis"] +sets = ["db_core", "db_shared"] +files = '^crate/server_database/src/stores/redis/ | ^\.mise/tasks/test/db/redis$' +# redis (Findex) is non-FIPS only +variants = ["non-fips"] + +[units."db:openbao"] +sets = ["db_core", "pg_store", "mysql_store"] +files = ''' + ^\.mise/tasks/test/db/(_default|openbao)$ +| ^\.mise/tasks/test/interop/openbao$ +| ^\.mise/scripts/test/openbao/ +| ^crate/server/src/routes/kv/ +''' +# the OpenBao KV scenario replayed on PostgreSQL and MySQL +variants = ["fips", "non-fips"] + +[units.cloud] +files = ''' + ^crate/server/src/(routes/(aws_xks|azure_ekm|google_cse)/|tests/) +| ^crate/clients/clap/src/actions/(google|aws|azure)/ +| ^documentation/docs/google_cse/test_wrapped_private_key$ +| ^\.mise/tasks/test/cloud/ +| ^\.mise/scripts/test/(azure_ekm_test|azure_ekm_mtls_test|test_secret_aws|test_secret_azure|test_secret_vault + |test_secret_cosmian_kms|test_xks)\.sh$ +''' + +[units.hsm] +files = ''' + ^crate/hsm/ +| ^crate/clients/pkcs11/ +| ^crate/server/src/tests/ +| ^\.mise/tasks/test/hsm/ +| ^\.mise/lib/(softhsm2|kryoptic|pkcs11_helpers)\.sh$ +| ^\.mise/scripts/test/(c2p_no_inotify\.c|pkcs11_fips_iv_shim\.c|pkcs11_gcm_iv_probe\.(c|py)|test_nix_helpers\.sh)$ +''' +variants = ["fips", "non-fips"] +bench = {fips = "softhsm2 utimaco crypt2pay-simulator", non-fips = "softhsm2 utimaco crypt2pay-simulator kryoptic"} + +[units.pkcs11] +files = ''' + ^crate/clients/pkcs11/ +| ^crate/clients/clap/src/actions/pkcs11/ +| ^\.mise/tasks/test/pkcs11/ +| ^\.mise/lib/(softhsm2|pkcs11_helpers)\.sh$ +| ^\.mise/scripts/test/(test_pkcs11_conformance\.sh|pkcs11_raw_abi_check\.py|test_gnupg\.sh|test_gnupg_smartcard\.sh + |gnupg_pkcs11_scd_driver\.py|test_luks\.sh|test_openssh\.sh|test_hsm_kek_pkcs11_comprehensive\.sh + |test_pkcs11_check\.sh|requirements-pkcs11-check\.(in|txt)|test_veracrypt\.sh)$ +| ^crate/server/src/core/operations/pkcs11\.rs$ +''' +# Every pkcs11 leaf is non-FIPS only. +variants = ["non-fips"] + +[units.obs] +files = ''' + ^crate/server/src/(core/otel_metrics\.rs$|middlewares/otel_http_middleware\.rs$|tests/) +| ^crate/clients/clap/src/actions/audit\.rs$ +| ^\.mise/tasks/test/obs/ +| ^\.mise/lib/audit_(e2e|compat)\.sh$ +| ^\.mise/scripts/test/(test_audit_log\.sh|test_audit_postgres_log\.sh|generate_live_audit_fixture\.sh + |validate_audit_compat\.py|fixtures/|test_cef_format\.sh|test_siem_[a-z_]+\.sh + |siem_verify_fields\.py|cef_helper\.py|rsyslog\.conf|test_monitoring\.sh + |requirements-(cef|audit-compat)\.(in|txt)) +| ^monitoring/ +| ^documentation/arcsight/ +| ^crate/server/src/(core/audit/|middlewares/audit/|routes/kmip/audit\.rs$) +| ^crate/server_database/src/stores/audit/ +''' +variants = ["fips", "non-fips"] + +[units.pki] +files = ''' + ^crate/server/src/routes/(est|scep|ocsp)/ +| ^crate/server/src/routes/crl\.rs$ +| ^\.mise/tasks/test/pki/ +| ^\.mise/scripts/test/(test_est_interop|test_scep_interop)\.sh$ +| ^\.mise/scripts/kmip-go/go\.mod$ +| ^crate/server/src/routes/(csr|enrollment|enrollment_guard)\.rs$ +| ^crate/server/src/core/certificate/ +| ^crate/server/src/core/operations/(certify/|generate_crl\.rs$|generate_csr\.rs$|recertify\.rs$) +| ^crate/clients/clap/src/actions/certificates/ +''' +variants = ["fips", "non-fips"] + +[units.spire] +sets = ["server_core"] +files = ''' + ^crate/server/src/tests/ +| ^authentication$ +| ^\.mise/tasks/test/spire/ +| ^\.mise/lib/spire_test\.sh$ +| ^\.mise/scripts/test/grant_spire_pki_certify\.sh$ +''' +variants = ["non-fips"] + +[units.ui] +files = ''' + ^ui/ +| ^crate/clients/wasm/ +| ^crate/server/src/routes/ui_auth\.rs$ +| ^authentication$ +| ^\.mise/tasks/test/ui/ +| ^\.mise/tasks/build/(ui|wasm)$ +| ^\.mise/scripts/test/(test_ui|test_ui_auth|test_ui_oidc|test_ui_saml)\.sh$ +| ^\.mise/scripts/test/saml_sso/ +''' + +[units."interop:ase"] +sets = ["kmip_wire", "interop_shared"] +files = '^crate/clients/pkcs11/ | ^\.mise/tasks/test/interop/ase$ | ^\.mise/scripts/test/test_ase_tde\.sh$ | ^\.mise/scripts/docker/ase/' +variants = ["non-fips"] + +[units."interop:db2"] +sets = ["kmip_wire", "interop_shared"] +files = '^\.mise/tasks/test/interop/db2$ | ^\.mise/scripts/test/test_db2_tde\.sh$' +variants = ["non-fips"] + +[units."interop:edb-tde"] +sets = ["kmip_wire", "interop_shared"] +files = '^\.mise/tasks/test/interop/edb-tde$ | ^\.mise/scripts/test/test_edb_tde\.sh$ | ^\.mise/scripts/(edb_tde|pykmip)/' +variants = ["non-fips"] + +[units."interop:iris"] +sets = ["kmip_wire", "interop_shared"] +files = '^\.mise/tasks/test/interop/iris$ | ^\.mise/scripts/test/test_iris\.sh$' +variants = ["non-fips"] + +[units."interop:jose"] +sets = ["interop_shared"] +files = ''' + ^crate/server/src/(routes/(jose/|jwks\.rs$)|tests/) +| ^crate/hsm/kryoptic/ +| ^\.mise/tasks/test/(interop|hsm)/jose$ +| ^\.mise/lib/kryoptic\.sh$ +| ^\.mise/scripts/test/(test_jose\.sh|jose_interop_helper\.py|requirements-jose\.(in|txt))$ +''' +variants = ["non-fips"] + +[units."interop:kmip-go"] +sets = ["kmip_wire", "interop_shared"] +files = ''' + ^kmip$ +| ^\.mise/tasks/test/interop/kmip-go$ +| ^\.mise/scripts/test/test_kmip_go\.sh$ +| ^\.mise/scripts/kmip-go/ +| ^\.mise/scripts/pykmip/kms\.toml$ +''' +variants = ["fips", "non-fips"] + +[units."interop:kmipkit"] +sets = ["kmip_wire", "interop_shared"] +files = '^\.mise/tasks/test/interop/kmipkit$ | ^\.mise/scripts/kmipkit-fixes\.patch$' +variants = ["non-fips"] + +[units."interop:openbao"] +sets = ["interop_shared"] +files = '^\.mise/tasks/test/interop/openbao$ | ^\.mise/scripts/test/openbao/ | ^crate/server/src/routes/kv/' +variants = ["fips", "non-fips"] + +[units."interop:openbao-auth-verifier"] +sets = ["interop_shared"] +files = '^authentication$ | ^\.mise/tasks/test/interop/openbao-auth-verifier$ | ^\.mise/lib/spire_test\.sh$ | ^\.mise/scripts/test/openbao/ | ^crate/server/src/middlewares/auth_verifier/' +variants = ["fips", "non-fips"] + +[units."interop:openbao-kmip"] +sets = ["kmip_wire", "interop_shared"] +files = '^\.mise/tasks/test/interop/openbao-kmip$ | ^\.mise/scripts/test/openbao/' +variants = ["fips", "non-fips"] + +[units."interop:pykmip"] +sets = ["kmip_wire", "interop_shared"] +files = '^\.mise/tasks/test/interop/pykmip$ | ^\.mise/scripts/test/test_pykmip\.sh$ | ^\.mise/scripts/pykmip/ | ^\.github/workflows/test_all\.yml$' +variants = ["non-fips"] + +[units."interop:ssh-secrets"] +sets = ["interop_shared", "pg_store", "mysql_store"] +files = ''' + ^\.mise/tasks/test/interop/ssh-secrets$ +| ^\.mise/scripts/test/(test_ssh_certificates|test_secret_rotation)\.sh$ +| ^\.mise/scripts/test/openbao/bao_verifier\.sh$ +| ^crate/server/src/routes/(ssh|kv)/ +''' +variants = ["fips", "non-fips"] + +# ── test_windows.yml ──────────────────────────────────────────────────────────────────────── +[units.windows-cargo-test] +sets = ["rust"] + +[units.windows-ui] +sets = ["windows"] +files = '^ui/ | ^crate/clients/wasm/ | ^crate/server/src/routes/ui_auth\.rs$ | ^\.mise/scripts/windows/test_ui\.ps1$' + +[units.windows-cng-ksp] +sets = ["windows"] +files = '^crate/clients/(cng|pkcs11)/ | ^crate/clients/clap/src/actions/(cng|cng_verify)\.rs$ | ^\.mise/scripts/windows/test_cng_ksp\.ps1$' + +[units.windows-hsm-idemia] +sets = ["windows"] +files = ''' + ^crate/hsm/ +| ^crate/server/src/tests/ +| ^\.mise/tasks/test/hsm/(idemia-sphere-simulator|other)$ +| ^\.mise/scripts/windows/(test_hsm_idemia|test_hsm_other|hsm_common|prepare_windows_fips_provider)\.ps1$ +| ^\.mise/scripts/test/pkcs11_fips_iv_shim\.c$ +''' + +[units.windows-est] +sets = ["windows"] +files = '^crate/server/src/routes/est/ | ^\.mise/scripts/windows/test_est_windows\.ps1$ | ^\.mise/scripts/kmip-go/go\.mod$' diff --git a/.github/instructions/hsm.instructions.md b/.github/instructions/hsm.instructions.md index faecf3c8a5..f344835640 100644 --- a/.github/instructions/hsm.instructions.md +++ b/.github/instructions/hsm.instructions.md @@ -15,6 +15,6 @@ matrix. - [ ] HSM model enum updated in `crate/server/src/config/` or `crate/hsm/base_hsm/` - [ ] Wizard step in `crate/server/src/config/wizard/hsm_wizard.rs` - [ ] Test vectors in `test_data/vectors/hsm//` -- [ ] CI added to `.github/workflows/test_all.yml` (software HSMs: list the leaf in `.mise/tasks/test/hsm/_default` and add the model to `test-hsm`'s `bench`; real hardware: add a `test-hsm-hardware` cell with `lock` and its secrets in `test-group.yml`, plus `skip` it in `test-hsm`), and the upstream `env:` gate (`print_error` when `CI=true` and a secret is unset, then `skip_test`) in `.mise/tasks/test/hsm/` for hardware HSMs +- [ ] CI added to `.github/workflows/test_all.yml` and `.github/ci-paths.toml` (software HSMs: list the leaf in `.mise/tasks/test/hsm/_default` and add the model to the `bench` of `[units.hsm]`; real hardware: add a `test-hsm-hardware` cell with `lock` and its secrets in `test-group.yml`, plus `skip` it in the `skip:` of `test-suites`), and the upstream `env:` gate (`print_error` when `CI=true` and a secret is unset, then `skip_test`) in `.mise/tasks/test/hsm/` for hardware HSMs > Rule 4.13 of `/kms-sync-rules`. diff --git a/.github/workflows/README_main.md b/.github/workflows/README_main.md index 92ab5da2b0..19073bfce5 100644 --- a/.github/workflows/README_main.md +++ b/.github/workflows/README_main.md @@ -1,7 +1,7 @@ # CI workflows: `main.yml` `main.yml` is the PR / tag / nightly test pipeline. Its jobs are direct callers, so the run page groups them by area (`test / …`, `supply-chain / …`, `no-nix / …`): -`main.yml` -> `supply-chain.yml`, `no-nix.yml`, `forward_proxy.yml`, `test_windows.yml`, `test_all.yml` -> `test-db.yml`, `test-interop.yml`, `test-group.yml` / `cargo-publish.yml`. +`main.yml` -> `supply-chain.yml`, `no-nix.yml`, `forward_proxy.yml`, `test_windows.yml`, `test_all.yml` -> `test-group.yml` / `cargo-publish.yml`. Packaging and releases are described in [README_nightly.md](README_nightly.md). ## Triggers and concurrency @@ -59,8 +59,8 @@ flowchart TB ```mermaid flowchart TB Cache["nix-dev-shell-cache
OpenSSL 3.1.2 / 3.6.5 + SoftHSM2 built once per Nix input hash"] - subgraph NixJobs["One job per test group, each run by test-group.yml (Nix dev shell)"] - Groups["test-cloud (upstream only) · test-db · test-hsm · test-interop · test-obs
test-pkcs11 · test-pki · test-spire · test-ui"] + subgraph NixJobs["One job per test group or leg, each run by test-group.yml (Nix dev shell)"] + Groups["test-cloud (upstream only) · test-suites (db · hsm · interop · obs · pkcs11 · pki · spire legs) · test-ui"] Hsm["test-hsm-hardware
proteccio · crypt2pay
not on PR"] end Cache --> Groups & Hsm @@ -76,17 +76,13 @@ Each test job runs one group of `.mise/tasks/test` (`mise run test: --var |Job|Group| |---|---| |`test-cloud`|`cloud` (upstream only: needs the Google, AWS and Azure secrets)| -|`test-db`|`test-db.yml`: one `test-group.yml` job per `db` leaf and variant (`sqlite`, `psql`, `mysql`, `mariadb`, `percona`, `redis` non-FIPS only), with the database environment variables| -|`test-hsm`|`hsm` without the real HSMs (`skip: hsm:crypt2pay hsm:proteccio`), then the `bench` models| -|`test-interop`|`test-interop.yml`: one `test-group.yml` job per `interop` leaf (`ase`, `db2`, `edb-tde`, `iris`, `jose`, `kmipkit`, `pykmip` non-FIPS only; `kmip-go` both variants), so a hang or leftover state in one leaf stays in its own job| -|`test-obs`|`obs`| -|`test-pkcs11`|`pkcs11`| -|`test-pki`|`pki`| -|`test-spire`|`spire`| +|`test-suites`|one `test-group.yml` job per leg of the `suites-matrix` that `ci_changes.py` builds from the `variants` of `.github/ci-paths.toml`: the `db` leaves (with the database environment variables), `hsm` without the real HSMs (`skip: hsm:crypt2pay hsm:proteccio`) then the `bench` models, the `interop` leaves (a hang or leftover state in one leaf stays in its own job), `obs`, `pkcs11`, `pki` and `spire`; a suite that does not run has no leg, so no row| |`test-ui`|`ui`| |`test-hsm-hardware`|real HSMs `hsm:proteccio`, `hsm:crypt2pay`, one leaf per cell (never on pull requests)| -`test-ui` runs without cloud or test secrets, because it executes `pnpm install`; `test-spire` receives only the Docker Hub login. Each caller passes `test-group.yml` only the secrets its leaves use. `test-cloud` skips on forks and fork pull requests, `test-hsm-hardware` never runs on pull requests and only in the upstream repository. In both jobs a task whose required `env:` variables are unset (a deleted or renamed secret, a typo in the mapping) fails instead of skipping, because its upstream gate calls `print_error` when `CI=true`, so a green cell proves its tasks ran. A cell's `lock` (`hsm-proteccio`, `hsm-crypt2pay`) is its concurrency group: the HSMs refuse concurrent runs, and `test-k8s-hsm` in `packaging-docker.yml` (also never on pull requests) shares the groups. A cell's `bench` is the list of HSM models whose benchmarks run after its tests, off pull requests. Pull requests cover the HSM code paths with the software simulators of `test-hsm` (`softhsm2`, `utimaco`, `crypt2pay-simulator`, `kryoptic`). +`test-suites` is the only job whose secrets depend on the leg (`secrets:` expressions on `matrix.suite`): the Docker Hub login for every leg, the EDB and IRIS tokens for `interop:*` legs, the Splunk password for `obs`. `cloud` and `ui` stay separate jobs so that their secret scope is set by the job, not by an expression. + +`test-ui` runs without cloud or test secrets, because it executes `pnpm install`. `test-cloud` skips on forks and fork pull requests, `test-hsm-hardware` never runs on pull requests and only in the upstream repository. In both jobs a task whose required `env:` variables are unset (a deleted or renamed secret, a typo in the mapping) fails instead of skipping, because its upstream gate calls `print_error` when `CI=true`, so a green cell proves its tasks ran. A cell's `lock` (`hsm-proteccio`, `hsm-crypt2pay`) is its concurrency group: the HSMs refuse concurrent runs, and `test-k8s-hsm` in `packaging-docker.yml` (also never on pull requests) shares the groups. A cell's `bench` is the list of HSM models whose benchmarks run after its tests, off pull requests. Pull requests cover the HSM code paths with the software simulators of the `hsm` legs of `test-suites` (`softhsm2`, `utimaco`, `crypt2pay-simulator`, `kryoptic`). A leaf that fails only when grouped (port, Docker or environment leak) or only in one variant: add its `:` id to the `skip` input of its job, with a one-line reason comment. diff --git a/.github/workflows/linkcheck.yml b/.github/workflows/linkcheck.yml new file mode 100644 index 0000000000..0954e565d5 --- /dev/null +++ b/.github/workflows/linkcheck.yml @@ -0,0 +1,26 @@ +--- +name: Link check + +# Link checking hits external sites (flaky on PRs): nightly only. A workflow of its own, so pull requests +# do not list it as a skipped job. +on: + schedule: + - cron: 0 3 * * * # Daily at 03:00 UTC + +jobs: + linkcheck: + name: Check documentation links + runs-on: ubuntu-24.04 + permissions: + contents: read + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + with: + submodules: recursive + persist-credentials: false + + - name: Link check + uses: lycheeverse/lychee-action@e7477775783ea5526144ba13e8db5eec57747ce8 # v2 + with: + args: --config lychee.toml 'documentation/docs/**/*.md' + fail: false diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5ea7fd8236..6714916b05 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,8 +25,43 @@ jobs: uses: ./.github/workflows/cla.yml secrets: inherit + # Runs only the jobs whose files (.github/ci-paths.toml) the PR changes; tags, schedule and dispatch run everything. + changes: + name: Detect changed areas + runs-on: ubuntu-24.04 + permissions: + contents: read + outputs: + skip: ${{ steps.classify.outputs.skip }} + suites-matrix: ${{ steps.classify.outputs.suites-matrix }} + run-test: ${{ steps.classify.outputs.run-test }} + run-windows: ${{ steps.classify.outputs.run-windows }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + with: + persist-credentials: false + # On pull_request the checkout is the test merge commit, whose first parent is the base branch tip. + fetch-depth: 2 + + - uses: ./.github/actions/install-mise + + - name: Classify changed files + id: classify + env: + EVENT_NAME: ${{ github.event_name }} + GITHUB_TOKEN: ${{ github.token }} + run: | + mise run dev:ci-changes --self-test + if [ "${EVENT_NAME}" = "pull_request" ]; then + mise run dev:ci-changes --base HEAD^1 + else + mise run dev:ci-changes --all + fi + cargo-clippy: uses: Cosmian/reusable_workflows/.github/workflows/clippy.yml@9079c7a06025e1373a9be950fd94a36464ded0b9 # develop + needs: changes + if: ${{ !contains(fromJSON(needs.changes.outputs.skip), 'cargo-clippy') }} cargo-deny: uses: Cosmian/reusable_workflows/.github/workflows/cargo-audit.yml@9079c7a06025e1373a9be950fd94a36464ded0b9 # develop @@ -34,37 +69,54 @@ jobs: cargo-machete: uses: Cosmian/reusable_workflows/.github/workflows/cargo-machete.yml@9079c7a06025e1373a9be950fd94a36464ded0b9 # develop + needs: changes + if: ${{ !contains(fromJSON(needs.changes.outputs.skip), 'cargo-machete') }} supply-chain: uses: ./.github/workflows/supply-chain.yml forward-proxy: uses: ./.github/workflows/forward_proxy.yml + needs: changes + if: ${{ !contains(fromJSON(needs.changes.outputs.skip), 'forward-proxy') }} no-nix: uses: ./.github/workflows/no-nix.yml + needs: changes + if: ${{ !contains(fromJSON(needs.changes.outputs.skip), 'no-nix') }} windows: # Same gating as `test` (no dependabot PRs) plus no fork PRs. Windows is slow: PRs run the # quick suite; tags and nightly run the full one. + needs: changes if: >- - ((github.event_name == 'pull_request' && !startsWith(github.ref_name, 'dependabot/') && github.actor != 'dependabot[bot]') + (((github.event_name == 'pull_request' && !startsWith(github.ref_name, 'dependabot/') && github.actor != 'dependabot[bot]') || startsWith(github.ref, 'refs/tags/') || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') - && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) + && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)) + && needs.changes.outputs.run-windows == 'true' uses: ./.github/workflows/test_windows.yml with: archive-name: windows # test_kms_server and ckms lib tests are covered on Linux; the full suite runs off-PR only. full-suite: ${{ github.event_name != 'pull_request' }} + skip-units: ${{ needs.changes.outputs.skip }} test: # Run all tests (PRs, tags and the nightly schedule / manual dispatch) - if: (github.event_name == 'pull_request' && !startsWith(github.ref_name, 'dependabot/') && github.actor != 'dependabot[bot]') || startsWith(github.ref, - 'refs/tags/') || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + needs: changes + if: >- + ((github.event_name == 'pull_request' && !startsWith(github.ref_name, 'dependabot/') && github.actor != 'dependabot[bot]') + || startsWith(github.ref, 'refs/tags/') || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') + && needs.changes.outputs.run-test == 'true' uses: ./.github/workflows/test_all.yml secrets: inherit + with: + skip-units: ${{ needs.changes.outputs.skip }} + suites-matrix: ${{ needs.changes.outputs.suites-matrix }} build-documentation: name: Build documentation + needs: changes + if: ${{ !contains(fromJSON(needs.changes.outputs.skip), 'build-documentation') }} runs-on: ubuntu-24.04 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 @@ -84,22 +136,6 @@ jobs: export PATH="$HOME/.cargo/bin:$PATH" mise run docs:mdbook-build - linkcheck: - # Link checking hits external sites (flaky on PRs): nightly only. - if: github.event_name == 'schedule' - name: Check documentation links - runs-on: ubuntu-24.04 - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - with: - submodules: recursive - - - name: Link check - uses: lycheeverse/lychee-action@e7477775783ea5526144ba13e8db5eec57747ce8 # v2 - with: - args: --config lychee.toml 'documentation/docs/**/*.md' - fail: false - public_documentation: if: github.event.pull_request.head.repo.full_name == github.repository && !startsWith(github.ref_name, 'dependabot/') && github.actor != 'dependabot[bot]' || startsWith(github.ref, 'refs/tags/') diff --git a/.github/workflows/test-db.yml b/.github/workflows/test-db.yml deleted file mode 100644 index 019eb18c0f..0000000000 --- a/.github/workflows/test-db.yml +++ /dev/null @@ -1,62 +0,0 @@ ---- -name: Test db - -# One job per database backend (a leaf of .mise/tasks/test/db), so a slow or hung backend never blocks the others. -on: - workflow_call: - secrets: - DOCKERHUB_USERNAME: {required: false} - DOCKERHUB_TOKEN: {required: false} - -jobs: - leaf: - name: Test db ${{ matrix.leaf }} (${{ matrix.variant }}) - strategy: - fail-fast: false - matrix: - include: - - {leaf: sqlite, variant: fips} - - {leaf: sqlite, variant: non-fips} - - {leaf: psql, variant: fips} - - {leaf: psql, variant: non-fips} - - {leaf: mysql, variant: fips} - - {leaf: mysql, variant: non-fips} - - {leaf: mariadb, variant: fips} - - {leaf: mariadb, variant: non-fips} - - {leaf: percona, variant: fips} - - {leaf: percona, variant: non-fips} - # the OpenBao KV scenario replayed on PostgreSQL and MySQL - - {leaf: openbao, variant: fips} - - {leaf: openbao, variant: non-fips} - # redis (Findex) is non-FIPS only - - {leaf: redis, variant: non-fips} - uses: ./.github/workflows/test-group.yml - with: - suite: db:${{ matrix.leaf }} - variant: ${{ matrix.variant }} - extra-env: | - POSTGRES_USER=kms - PGUSER=kms - POSTGRES_PASSWORD=kms - POSTGRES_DB=kms - POSTGRES_HOST=localhost - POSTGRES_PORT=5432 - KMS_POSTGRES_URL=postgresql://kms:kms@127.0.0.1:5432/kms - MYSQL_DATABASE=kms - MYSQL_ROOT_PASSWORD=kms - MYSQL_HOST=localhost - MYSQL_PORT=3306 - KMS_MYSQL_URL=mysql://root:kms@localhost:3306/kms - PERCONA_HOST=localhost - PERCONA_PORT=3307 - KMS_PERCONA_URL=mysql://root:kms@localhost:3307/kms - MARIADB_HOST=localhost - MARIADB_PORT=3308 - KMS_MARIADB_URL=mysql://root:kms@localhost:3308/kms - KMS_SQLITE_PATH=data/shared - REDIS_HOST=localhost - REDIS_PORT=6379 - KMS_REDIS_URL=redis://localhost:6379 - secrets: - DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} diff --git a/.github/workflows/test-group.yml b/.github/workflows/test-group.yml index 454e26336b..29ffce919e 100644 --- a/.github/workflows/test-group.yml +++ b/.github/workflows/test-group.yml @@ -22,11 +22,6 @@ on: required: false type: string default: '' - extra-env: - description: KEY=VALUE lines appended to GITHUB_ENV before the tests - required: false - type: string - default: '' secrets: DOCKERHUB_USERNAME: {required: false} DOCKERHUB_TOKEN: {required: false} @@ -74,11 +69,33 @@ jobs: cleanup-runner: 'true' dev-shell-cache: 'true' - - name: Export suite environment - if: inputs.extra-env != '' - env: - EXTRA_ENV: ${{ inputs.extra-env }} - run: printf '%s\n' "$EXTRA_ENV" >> "$GITHUB_ENV" + - name: Export database suite environment + if: startsWith(inputs.suite, 'db:') + run: | + cat >> "$GITHUB_ENV" <<'EOF' + POSTGRES_USER=kms + PGUSER=kms + POSTGRES_PASSWORD=kms + POSTGRES_DB=kms + POSTGRES_HOST=localhost + POSTGRES_PORT=5432 + KMS_POSTGRES_URL=postgresql://kms:kms@127.0.0.1:5432/kms + MYSQL_DATABASE=kms + MYSQL_ROOT_PASSWORD=kms + MYSQL_HOST=localhost + MYSQL_PORT=3306 + KMS_MYSQL_URL=mysql://root:kms@localhost:3306/kms + PERCONA_HOST=localhost + PERCONA_PORT=3307 + KMS_PERCONA_URL=mysql://root:kms@localhost:3307/kms + MARIADB_HOST=localhost + MARIADB_PORT=3308 + KMS_MARIADB_URL=mysql://root:kms@localhost:3308/kms + KMS_SQLITE_PATH=data/shared + REDIS_HOST=localhost + REDIS_PORT=6379 + KMS_REDIS_URL=redis://localhost:6379 + EOF - name: Docker login (Docker Hub) if: ${{ env.DOCKERHUB_USERNAME != '' }} diff --git a/.github/workflows/test-interop.yml b/.github/workflows/test-interop.yml deleted file mode 100644 index 48926ff202..0000000000 --- a/.github/workflows/test-interop.yml +++ /dev/null @@ -1,46 +0,0 @@ ---- -name: Test interop - -# Third-party client / product interoperability, one job per leaf of .mise/tasks/test/interop so a leaf's -# hang, leftover state or missing secret never affects another. Leaves that need non-FIPS only run there. -on: - workflow_call: - secrets: - DOCKERHUB_USERNAME: {required: false} - DOCKERHUB_TOKEN: {required: false} - EDB_SUBSCRIPTION_TOKEN: {required: false} - IRIS_LICENSE_KEY: {required: false} - -jobs: - leaf: - name: Test interop ${{ matrix.leaf }} (${{ matrix.variant }}) - strategy: - fail-fast: false - matrix: - include: - - {leaf: ase, variant: non-fips} - - {leaf: db2, variant: non-fips} - - {leaf: edb-tde, variant: non-fips} - - {leaf: iris, variant: non-fips} - - {leaf: jose, variant: non-fips} - - {leaf: kmip-go, variant: fips} - - {leaf: kmip-go, variant: non-fips} - - {leaf: kmipkit, variant: non-fips} - - {leaf: openbao, variant: fips} - - {leaf: openbao, variant: non-fips} - - {leaf: openbao-auth-verifier, variant: fips} - - {leaf: openbao-auth-verifier, variant: non-fips} - - {leaf: openbao-kmip, variant: fips} - - {leaf: openbao-kmip, variant: non-fips} - - {leaf: pykmip, variant: non-fips} - - {leaf: ssh-secrets, variant: fips} - - {leaf: ssh-secrets, variant: non-fips} - uses: ./.github/workflows/test-group.yml - with: - suite: interop:${{ matrix.leaf }} - variant: ${{ matrix.variant }} - secrets: - DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} - EDB_SUBSCRIPTION_TOKEN: ${{ secrets.EDB_SUBSCRIPTION_TOKEN }} - IRIS_LICENSE_KEY: ${{ secrets.IRIS_LICENSE_KEY }} diff --git a/.github/workflows/test_all.yml b/.github/workflows/test_all.yml index 4a3d341c45..cab4122327 100644 --- a/.github/workflows/test_all.yml +++ b/.github/workflows/test_all.yml @@ -3,7 +3,16 @@ name: Build all on: workflow_call: - workflow_dispatch: + inputs: + skip-units: + description: JSON list of skipped CI units (.github/ci-paths.toml); jobs whose unit it contains are skipped + required: false + type: string + default: '[]' + suites-matrix: + description: JSON include list [{suite, variant, bench}] of the test-suites legs to run (ci_changes.py from the ci-paths.toml `variants`) + required: true + type: string jobs: # Builds the source-built Nix inputs of shell.nix (OpenSSL 3.1.2 / 3.6.5, FIPS bootstrap, SoftHSM2, @@ -76,6 +85,8 @@ jobs: # One job per group of .mise/tasks/test (`mise run test:`, i.e. its `_default`), each cell run by # test-group.yml. `skip` lists `:` ids a job must not run. `k8s` and `pkg` run in # packaging-docker.yml; a leaf no group lists runs locally only. + # `cloud` and `ui` keep their own jobs (their secrets are isolated); a job whose suite is skipped (ci-paths.toml) shows one + # skipped row. Every other suite is a leg of `test-suites`, whose matrix ci_changes.py builds from the running units. # Upstream only (not on forks or fork pull requests): the Google, AWS and Azure secrets are withheld there. test-cloud: name: Test cloud (${{ matrix.variant }}) @@ -84,7 +95,8 @@ jobs: if: >- github.repository == 'Cosmian/kms' && (github.event_name != 'pull_request' || - github.event.pull_request.head.repo.full_name == github.repository) + github.event.pull_request.head.repo.full_name == github.repository) && + !contains(fromJSON(inputs.skip-units || '[]'), 'cloud') strategy: fail-fast: false matrix: @@ -106,113 +118,30 @@ jobs: KMS_CI_AZURE_CLIENT_SECRET: ${{ secrets.KMS_CI_AZURE_CLIENT_SECRET }} KMS_CI_AZURE_KV_NAME: ${{ secrets.KMS_CI_AZURE_KV_NAME }} - test-db: - name: Test db - needs: - - nix-dev-shell-cache - uses: ./.github/workflows/test-db.yml - secrets: - DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} - - test-hsm: - name: Test hsm (${{ matrix.variant }}) + # Suites that need at most the Docker Hub login and their own product secrets (never cloud credentials), one leg per + # (suite, variant). The per-leg `secrets:` expressions hand EDB/IRIS only to interop legs and Splunk only to obs. + test-suites: + name: Test ${{ matrix.suite }} (${{ matrix.variant }}) needs: - nix-dev-shell-cache + if: inputs.suites-matrix != '[]' strategy: fail-fast: false matrix: - include: - - {variant: fips, bench: softhsm2 utimaco crypt2pay-simulator} - - {variant: non-fips, bench: softhsm2 utimaco crypt2pay-simulator kryoptic} + include: ${{ fromJSON(inputs.suites-matrix) }} uses: ./.github/workflows/test-group.yml with: - suite: hsm + suite: ${{ matrix.suite }} variant: ${{ matrix.variant }} # real HSMs: test-hsm-hardware - skip: hsm:crypt2pay hsm:proteccio + skip: ${{ matrix.suite == 'hsm' && 'hsm:crypt2pay hsm:proteccio' || '' }} bench: ${{ matrix.bench }} secrets: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} - - test-interop: - name: Test interop - needs: - - nix-dev-shell-cache - uses: ./.github/workflows/test-interop.yml - secrets: - DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} - EDB_SUBSCRIPTION_TOKEN: ${{ secrets.EDB_SUBSCRIPTION_TOKEN }} - IRIS_LICENSE_KEY: ${{ secrets.IRIS_LICENSE_KEY }} - - test-obs: - name: Test obs (${{ matrix.variant }}) - needs: - - nix-dev-shell-cache - strategy: - fail-fast: false - matrix: - variant: [fips, non-fips] - uses: ./.github/workflows/test-group.yml - with: - suite: obs - variant: ${{ matrix.variant }} - secrets: - DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} - AUDIT_COMPAT_SPLUNK_PASSWORD: ${{ secrets.AUDIT_COMPAT_SPLUNK_PASSWORD }} - - # Every pkcs11 leaf is non-FIPS only. - test-pkcs11: - name: Test pkcs11 (${{ matrix.variant }}) - needs: - - nix-dev-shell-cache - strategy: - fail-fast: false - matrix: - variant: [non-fips] - uses: ./.github/workflows/test-group.yml - with: - suite: pkcs11 - variant: ${{ matrix.variant }} - secrets: - DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} - - test-pki: - name: Test pki (${{ matrix.variant }}) - needs: - - nix-dev-shell-cache - strategy: - fail-fast: false - matrix: - variant: [fips, non-fips] - uses: ./.github/workflows/test-group.yml - with: - suite: pki - variant: ${{ matrix.variant }} - secrets: - DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} - - # Only spire pulls images among the JS-toolchain groups, so it alone gets the Docker Hub login. - test-spire: - name: Test spire (${{ matrix.variant }}) - needs: - - nix-dev-shell-cache - strategy: - fail-fast: false - matrix: - variant: [non-fips] - uses: ./.github/workflows/test-group.yml - with: - suite: spire - variant: ${{ matrix.variant }} - secrets: - DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} + EDB_SUBSCRIPTION_TOKEN: ${{ startsWith(matrix.suite, 'interop:') && secrets.EDB_SUBSCRIPTION_TOKEN || '' }} + IRIS_LICENSE_KEY: ${{ startsWith(matrix.suite, 'interop:') && secrets.IRIS_LICENSE_KEY || '' }} + AUDIT_COMPAT_SPLUNK_PASSWORD: ${{ matrix.suite == 'obs' && secrets.AUDIT_COMPAT_SPLUNK_PASSWORD || '' }} # Runs pnpm install and the JS toolchain (vite, vitest, playwright): any npm dependency can read the # job's environment, so it gets no cloud/test secrets. @@ -220,6 +149,7 @@ jobs: name: Test ui (${{ matrix.variant }}) needs: - nix-dev-shell-cache + if: ${{ !contains(fromJSON(inputs.skip-units || '[]'), 'ui') }} permissions: contents: read strategy: @@ -232,7 +162,7 @@ jobs: variant: ${{ matrix.variant }} # The real hardware HSMs, reached over the network or OpenVPN. Never on pull requests: nightly, tag and - # dispatch runs only; pull requests cover the HSM code with the software simulators of `test-hsm`. Upstream + # dispatch runs only; pull requests cover the HSM code with the software simulators of the `hsm` legs of `test-suites`. Upstream # repository only, where the secrets exist. The HSMs refuse concurrent connections from several CI runs: # each cell's `lock` is one concurrency group shared by all runs, queued (test-k8s-hsm in packaging-docker.yml # uses the same groups). A task fails, never skips, when an `env:` need is unset: a green cell proves its @@ -283,7 +213,8 @@ jobs: github.event_name != 'schedule' && github.actor != 'dependabot[bot]' && (github.event_name != 'pull_request' || - github.event.pull_request.head.repo.full_name == github.repository) + github.event.pull_request.head.repo.full_name == github.repository) && + !contains(fromJSON(inputs.skip-units || '[]'), 'xks-remote') steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: @@ -327,10 +258,11 @@ jobs: AWS_XKS_KEY_ARN: ${{ secrets.AWS_XKS_KEY_ARN }} run: bash .mise/scripts/test/test_xks_aws_e2e.sh - # PKI group (EST / SCEP third-party clients, OCSP, revocation) on macOS; Linux runs it in `test-pki`. + # PKI group (EST / SCEP third-party clients, OCSP, revocation) on macOS; Linux runs it in the `pki` legs of `test-suites`. # Inline, not test-group.yml: macOS has no Nix. interop-macos: name: Test pki (macOS) + if: ${{ !contains(fromJSON(inputs.skip-units || '[]'), 'pki') }} runs-on: macos-15 timeout-minutes: 60 permissions: @@ -372,7 +304,8 @@ jobs: if: >- !startsWith(github.ref, 'refs/tags/') && (github.event_name != 'pull_request' || - github.event.pull_request.head.repo.full_name == github.repository) + github.event.pull_request.head.repo.full_name == github.repository) && + !contains(fromJSON(inputs.skip-units || '[]'), 'cargo-publish-dry-run') uses: ./.github/workflows/cargo-publish.yml secrets: token: ${{ secrets.CRATES_IO }} @@ -380,14 +313,8 @@ jobs: cargo-publish: needs: - test-cloud - - test-db - - test-hsm - test-hsm-hardware - - test-interop - - test-obs - - test-pkcs11 - - test-pki - - test-spire + - test-suites - test-ui # Real publish, tags only: a skipped dependency (upstream-only jobs on forks) must not skip # it, but any failed or cancelled dependency blocks it. diff --git a/.github/workflows/test_windows.yml b/.github/workflows/test_windows.yml index 645b578dfa..c6e121a90f 100644 --- a/.github/workflows/test_windows.yml +++ b/.github/workflows/test_windows.yml @@ -12,10 +12,16 @@ on: required: false type: boolean default: true + skip-units: + description: JSON list of skipped CI units (.github/ci-paths.toml); the job is skipped when it contains its unit + required: false + type: string + default: '[]' jobs: cargo-test: name: ${{ inputs.archive-name }} - cargo test + if: ${{ !contains(fromJSON(inputs.skip-units || '[]'), 'windows-cargo-test') }} runs-on: windows-2022 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 @@ -43,6 +49,7 @@ jobs: test-ui: name: ${{ inputs.archive-name }} - UI E2E tests + if: ${{ !contains(fromJSON(inputs.skip-units || '[]'), 'windows-ui') }} runs-on: windows-2022 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 @@ -90,6 +97,7 @@ jobs: test-cng-ksp: name: ${{ inputs.archive-name }} - CNG KSP integration tests + if: ${{ !contains(fromJSON(inputs.skip-units || '[]'), 'windows-cng-ksp') }} runs-on: windows-2022 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 @@ -120,6 +128,7 @@ jobs: test-hsm-idemia: name: ${{ inputs.archive-name }} - HSM tests (Idemia SPHERE simulator, ${{ matrix.variant }}) + if: ${{ !contains(fromJSON(inputs.skip-units || '[]'), 'windows-hsm-idemia') }} runs-on: windows-2022 timeout-minutes: 120 strategy: @@ -184,6 +193,7 @@ jobs: test-est-interop: name: ${{ inputs.archive-name }} - EST interoperability tests + if: ${{ !contains(fromJSON(inputs.skip-units || '[]'), 'windows-est') }} runs-on: windows-2022 timeout-minutes: 60 permissions: diff --git a/.mise/scripts/dev/ci_changes.py b/.mise/scripts/dev/ci_changes.py new file mode 100755 index 0000000000..98b68f16ef --- /dev/null +++ b/.mise/scripts/dev/ci_changes.py @@ -0,0 +1,223 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +"""Classify the files a pull request changes against .github/ci-paths.toml (stdlib only). + + ci_changes.py [--base REF] [--head REF] print the units to run/skip, emit the $GITHUB_OUTPUT lines + ci_changes.py --all not a pull request: every unit runs, no git diff + test_ci_changes.py unit tests of this module on the real config (`mise run dev:ci-changes --self-test`) + +The lines `skip=[...]`, `suites-matrix=[...]`, `run-test=` and `run-windows=` are appended to +$GITHUB_OUTPUT when set (and always printed): workflow jobs gate themselves with +`!contains(fromJSON(skip), '')`, the `test-suites` job of test_all.yml takes its legs from the matrix and main.yml +skips a whole reusable-workflow call when its `run-` is false. Fail-safe: an empty diff, a file matching +`full`, or a file matching no unit and not `ignore`d skips nothing. +""" + +from __future__ import annotations + +import argparse +import fnmatch +import json +import os +import re +import subprocess +import sys +import tomllib +from dataclasses import dataclass +from pathlib import Path + +REPO = Path( + subprocess.check_output(['git', 'rev-parse', '--show-toplevel'], text=True).strip() +) +CONFIG = REPO / '.github' / 'ci-paths.toml' + +VARIANTS = ('fips', 'non-fips') + + +@dataclass(frozen=True) +class Config: + full: re.Pattern[str] + ignore: re.Pattern[str] + units: dict[str, list[re.Pattern[str]]] + variants: dict[ + str, list[str] + ] # suite unit -> variants of its matrix legs, in unit order + bench: dict[ + str, dict[str, str] + ] # suite unit -> variant -> HSM models benchmarked after the tests + callers: dict[str, list[str]] # main.yml caller job -> its unit keys, in unit order + + +def fail(message: str) -> None: + print(f"ERROR: {message}", file=sys.stderr) + sys.exit(1) + + +def compile_pattern(key: str, value: object) -> re.Pattern[str]: + if not isinstance(value, str): + fail(f"{key}: expected a regex string") + try: + return re.compile(str(value), re.VERBOSE) + except re.error as exc: + fail(f"{key}: invalid regex: {exc}") + raise # unreachable, fail() exits + + +def load_config(path: Path) -> Config: + with path.open('rb') as handle: + raw = tomllib.load(handle) + for key in ('full', 'ignore', 'units'): + if key not in raw: + fail(f"{path.name}: missing `{key}`") + sets = { + name: compile_pattern(f"sets.{name}", value) + for name, value in raw.get('sets', {}).items() + } + units: dict[str, list[re.Pattern[str]]] = {} + variants: dict[str, list[str]] = {} + bench: dict[str, dict[str, str]] = {} + for unit, spec in raw['units'].items(): + unknown = set(spec) - {'sets', 'files', 'variants', 'bench'} + if unknown: + fail(f"units.{unit}: unknown key(s) {sorted(unknown)}") + if not {'sets', 'files'} & set(spec): + fail(f"units.{unit}: needs `sets` or `files`") + if 'variants' in spec: + legs = spec['variants'] + if ( + not isinstance(legs, list) + or not legs + or any(v not in VARIANTS for v in legs) + or len(set(legs)) != len(legs) + ): + fail( + f"units.{unit}: `variants` must be a non-empty list of distinct values among {list(VARIANTS)}" + ) + variants[unit] = list(legs) + models = spec.get('bench', {}) + if ( + not isinstance(models, dict) + or not all(isinstance(m, str) for m in models.values()) + or set(models) - set(variants.get(unit, [])) + ): + fail( + f"units.{unit}: `bench` must map variants of the unit to a string of HSM models" + ) + if models: + bench[unit] = dict(models) + patterns = [] + for name in spec.get('sets', []): + if name not in sets: + fail(f"units.{unit}: `sets` names unknown set `{name}`") + patterns.append(sets[name]) + if 'files' in spec: + patterns.append(compile_pattern(f"units.{unit}.files", spec['files'])) + units[unit] = patterns + callers: dict[str, list[str]] = {} + for name, pats in raw.get('callers', {}).items(): + if not isinstance(pats, list) or not all(isinstance(p, str) for p in pats): + fail(f"callers.{name}: expected a list of unit patterns") + for pat in pats: + if not any(fnmatch.fnmatchcase(u, pat) for u in units): + fail(f"callers.{name}: `{pat}` matches no unit") + callers[name] = [ + u for u in units if any(fnmatch.fnmatchcase(u, p) for p in pats) + ] + return Config( + full=compile_pattern('full', raw['full']), + ignore=compile_pattern('ignore', raw['ignore']), + units=units, + variants=variants, + bench=bench, + callers=callers, + ) + + +def changed_files(base: str, head: str) -> list[str]: + def git(*args: str) -> str: + return subprocess.run( + ['git', *args], check=True, capture_output=True, text=True, cwd=REPO + ).stdout + + merge = git('merge-base', base, head).strip() + out = git('diff', '--name-only', '--no-renames', merge, head) + return [line for line in out.splitlines() if line] + + +def classify(cfg: Config, files: list[str]) -> tuple[list[str], str]: + if not files: + return [], 'empty diff: run everything' + for f in files: + if cfg.full.search(f): + return [], f"{f} matches full: run everything" + triggered: set[str] = set() + orphans = [] + for f in files: + hits = {u for u, pats in cfg.units.items() if any(p.search(f) for p in pats)} + triggered |= hits + if not hits and not cfg.ignore.search(f): + orphans.append(f) + if orphans: + return [], f"{orphans[0]} matches no unit and is not ignored: run everything" + return ( + sorted(set(cfg.units) - triggered), + f"{len(triggered)} of {len(cfg.units)} units triggered", + ) + + +def outputs(cfg: Config, skipped: list[str]) -> dict[str, str]: + """$GITHUB_OUTPUT values: `skip`, `suites-matrix` (legs of the running suite units) and one `run-` per caller.""" + compact = {'separators': (',', ':')} + legs = [ + { + 'suite': unit, + 'variant': variant, + 'bench': cfg.bench.get(unit, {}).get(variant, ''), + } + for unit, variants in cfg.variants.items() + if unit not in skipped + for variant in variants + ] + result = { + 'skip': json.dumps(skipped, **compact), + 'suites-matrix': json.dumps(legs, **compact), + } + for caller, units in cfg.callers.items(): + result[f"run-{caller}"] = str(any(u not in skipped for u in units)).lower() + return result + + +def main() -> None: + parser = argparse.ArgumentParser(description=__doc__.split('\n')[0]) + parser.add_argument('--base', default='HEAD^1') + parser.add_argument('--head', default='HEAD') + parser.add_argument( + '--all', action='store_true', help='not a pull request: run everything' + ) + args = parser.parse_args() + + cfg = load_config(CONFIG) + if args.all: + files, skipped, reason = [], [], 'not a pull request: run everything' + else: + files = changed_files(args.base, args.head) + skipped, reason = classify(cfg, files) + + print(f"Changed files ({len(files)}):") + for f in files: + print(f" {f}") + print(reason) + for unit in cfg.units: + print(f'{"SKIP" if unit in skipped else "RUN "} {unit}') + + lines = [f"{key}={value}" for key, value in outputs(cfg, skipped).items()] + output = os.environ.get('GITHUB_OUTPUT') + if output: + with open(output, 'a', encoding='utf-8') as handle: + handle.write('\n'.join(lines) + '\n') + for line in lines: + print(line) + + +if __name__ == '__main__': + main() diff --git a/.mise/scripts/dev/test_ci_changes.py b/.mise/scripts/dev/test_ci_changes.py new file mode 100755 index 0000000000..6eb9affb6b --- /dev/null +++ b/.mise/scripts/dev/test_ci_changes.py @@ -0,0 +1,920 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +"""Unit tests of ci_changes.py against the real .github/ci-paths.toml. + +Each scenario simulates a pull request touching one area and asserts the exact set of CI units that run. +Run: python3 -m unittest discover -s .mise/scripts/dev -p 'test_ci_changes.py' (or `mise run dev:ci-changes --self-test`) +""" + +from __future__ import annotations + +import contextlib +import io +import json +import os +import re +import subprocess +import sys +import tempfile +import textwrap +import unittest +from pathlib import Path +from unittest import mock + +sys.path.insert(0, str(Path(__file__).parent)) +import ci_changes # noqa: E402 + +CFG = ci_changes.load_config(ci_changes.CONFIG) +EVERYTHING = set(CFG.units) + +# Units that run on any crate/** change (compile-wide jobs and whole-workspace unit-test runners). +WORKSPACE = { + 'cargo-clippy', + 'cargo-machete', + 'no-nix', + 'cargo-publish-dry-run', + 'db:sqlite', + 'windows-cargo-test', +} +# Units that additionally run on any change of code linked into the server. +SERVER_WIDE = WORKSPACE | {'forward-proxy', 'xks-remote', 'spire'} +DB_LEGS = {'db:psql', 'db:mysql', 'db:mariadb', 'db:percona', 'db:redis', 'db:openbao'} +KMIP_INTEROP = { + 'interop:ase', + 'interop:db2', + 'interop:edb-tde', + 'interop:iris', + 'interop:kmip-go', + 'interop:kmipkit', + 'interop:openbao-kmip', + 'interop:pykmip', +} + + +def leg(suite: str, *variants: str, bench: str = '') -> list[dict[str, str]]: + return [{'suite': suite, 'variant': v, 'bench': bench} for v in variants] + + +BOTH = ('fips', 'non-fips') +SOFT_HSMS = 'softhsm2 utimaco crypt2pay-simulator' +# Every leg, in ci-paths.toml unit order (what `ci_changes.py --all` emits); `cloud` and `ui` have none. +FULL_SUITES = [ + *leg('db:sqlite', *BOTH), + *leg('db:psql', *BOTH), + *leg('db:mysql', *BOTH), + *leg('db:mariadb', *BOTH), + *leg('db:percona', *BOTH), + *leg('db:redis', 'non-fips'), + *leg('db:openbao', *BOTH), + *leg('hsm', 'fips', bench=SOFT_HSMS), + *leg('hsm', 'non-fips', bench=SOFT_HSMS + ' kryoptic'), + *leg('pkcs11', 'non-fips'), + *leg('obs', *BOTH), + *leg('pki', *BOTH), + *leg('spire', 'non-fips'), + *leg('interop:ase', 'non-fips'), + *leg('interop:db2', 'non-fips'), + *leg('interop:edb-tde', 'non-fips'), + *leg('interop:iris', 'non-fips'), + *leg('interop:jose', 'non-fips'), + *leg('interop:kmip-go', *BOTH), + *leg('interop:kmipkit', 'non-fips'), + *leg('interop:openbao', *BOTH), + *leg('interop:openbao-auth-verifier', *BOTH), + *leg('interop:openbao-kmip', *BOTH), + *leg('interop:pykmip', 'non-fips'), + *leg('interop:ssh-secrets', *BOTH), +] + + +def run(*files: str) -> set[str]: + """Units that run for a PR changing `files`.""" + skipped, _ = ci_changes.classify(CFG, list(files)) + return EVERYTHING - set(skipped) + + +class DocsAndIgnored(unittest.TestCase): + def test_changelog_and_root_readme_run_nothing(self) -> None: + self.assertEqual(run('CHANGELOG/x.md', 'README.md'), set()) + + def test_documentation_and_ai_instruction_files_run_only_the_doc_build( + self, + ) -> None: + for path in ( + 'documentation/docs/index.md', + 'documentation/book.toml', + 'AGENTS.md', + '.github/skills/foo/SKILL.md', + '.github/instructions/rust.instructions.md', + '.mise/scripts/docs/check_ai_docs.py', + ): + with self.subTest(path=path): + self.assertEqual(run(path), {'build-documentation'}) + + def test_packaging_and_release_files_run_nothing(self) -> None: + self.assertEqual( + run( + 'pkg/deb/control', + 'nix/docker.nix', + '.github/workflows/release.yml', + '.mise/tasks/package/deb', + ), + set(), + ) + + +class Ui(unittest.TestCase): + def test_ui_source(self) -> None: + self.assertEqual(run('ui/src/App.tsx'), {'ui', 'windows-ui'}) + + def test_ui_playwright_test(self) -> None: + self.assertEqual(run('ui/tests/e2e/keys.spec.ts'), {'ui', 'windows-ui'}) + + def test_wasm_crate_runs_workspace_and_ui(self) -> None: + self.assertEqual( + run('crate/clients/wasm/src/lib.rs'), WORKSPACE | {'ui', 'windows-ui'} + ) + + def test_ui_does_not_touch_rust_jobs(self) -> None: + self.assertFalse(run('ui/src/App.tsx') & WORKSPACE) + + +class RustCoreCrates(unittest.TestCase): + def test_server_operation(self) -> None: + self.assertEqual( + run('crate/server/src/core/operations/encrypt.rs'), SERVER_WIDE + ) + + def test_crypto(self) -> None: + self.assertEqual(run('crate/crypto/src/openssl/mod.rs'), SERVER_WIDE) + + def test_kmip_runs_only_kmip_interop_clients(self) -> None: + self.assertEqual(run('crate/kmip/src/lib.rs'), SERVER_WIDE | KMIP_INTEROP) + + def test_kmip_endpoint(self) -> None: + self.assertEqual( + run('crate/server/src/routes/kmip/mod.rs'), SERVER_WIDE | KMIP_INTEROP + ) + + def test_ckms_client(self) -> None: + self.assertEqual(run('crate/clients/ckms/src/main.rs'), SERVER_WIDE) + + def test_core_change_skips_feature_suites(self) -> None: + ran = run('crate/server/src/core/operations/encrypt.rs') + self.assertFalse( + ran + & ({'ui', 'hsm', 'pkcs11', 'obs', 'pki', 'cloud', 'interop:jose'} | DB_LEGS) + ) + + +class Database(unittest.TestCase): + def test_shared_sql_runs_every_backend(self) -> None: + self.assertEqual( + run('crate/server_database/src/stores/sql/query.sql'), + SERVER_WIDE | DB_LEGS, + ) + + def test_postgres_store_only(self) -> None: + self.assertEqual( + run('crate/server_database/src/stores/sql/pgsql.rs'), + WORKSPACE | {'db:psql', 'db:openbao', 'interop:ssh-secrets'}, + ) + + def test_mysql_store_runs_all_three_mysql_flavours(self) -> None: + self.assertEqual( + run('crate/server_database/src/stores/sql/mysql.rs'), + WORKSPACE + | { + 'db:mysql', + 'db:mariadb', + 'db:percona', + 'db:openbao', + 'interop:ssh-secrets', + }, + ) + + def test_redis_store_only(self) -> None: + self.assertEqual( + run('crate/server_database/src/stores/redis/findex.rs'), + WORKSPACE | {'db:redis'}, + ) + + def test_db_change_skips_non_db_suites(self) -> None: + ran = run('crate/server_database/src/stores/sql/query.sql') + self.assertFalse(ran & {'ui', 'hsm', 'pkcs11', 'windows-ui', 'interop:iris'}) + + def test_db_task_script_runs_its_leg_only(self) -> None: + self.assertEqual(run('.mise/tasks/test/db/psql'), {'db:psql'}) + + +class FeatureCrates(unittest.TestCase): + def test_hsm_vendor_crate(self) -> None: + self.assertEqual( + run('crate/hsm/utimaco/src/lib.rs'), + WORKSPACE | {'hsm', 'windows-hsm-idemia'}, + ) + + def test_pkcs11_client(self) -> None: + self.assertEqual( + run('crate/clients/pkcs11/module/src/pkcs11.rs'), + WORKSPACE | {'pkcs11', 'hsm', 'interop:ase', 'windows-cng-ksp'}, + ) + + def test_aws_xks_route(self) -> None: + self.assertEqual( + run('crate/server/src/routes/aws_xks/mod.rs'), + WORKSPACE | {'cloud', 'xks-remote'}, + ) + + def test_google_cse_route(self) -> None: + self.assertEqual( + run('crate/server/src/routes/google_cse/mod.rs'), WORKSPACE | {'cloud'} + ) + + def test_est_route(self) -> None: + self.assertEqual( + run('crate/server/src/routes/est/mod.rs'), + WORKSPACE | {'pki', 'windows-est'}, + ) + + def test_certificate_core(self) -> None: + self.assertEqual( + run('crate/server/src/core/certificate/validate.rs'), + SERVER_WIDE | {'pki'}, + ) + + def test_audit_core(self) -> None: + self.assertEqual( + run('crate/server/src/core/audit/mod.rs'), SERVER_WIDE | {'obs'} + ) + + def test_kv_route(self) -> None: + self.assertEqual( + run('crate/server/src/routes/kv/mod.rs'), + SERVER_WIDE | {'db:openbao', 'interop:openbao', 'interop:ssh-secrets'}, + ) + + def test_jose_route(self) -> None: + self.assertEqual( + run('crate/server/src/routes/jose/mod.rs'), + WORKSPACE | {'interop:jose'}, + ) + + def test_certificates_cli_action(self) -> None: + self.assertEqual( + run('crate/clients/clap/src/actions/certificates/certify.rs'), + SERVER_WIDE | {'pki'}, + ) + + +class TestScripts(unittest.TestCase): + def test_interop_script_runs_only_its_suite(self) -> None: + self.assertEqual(run('.mise/scripts/test/test_iris.sh'), {'interop:iris'}) + + def test_hsm_task_script(self) -> None: + self.assertIn('hsm', run('.mise/tasks/test/hsm/softhsm')) + + +class CiWorkflows(unittest.TestCase): + def test_workflow_only_pr_runs_direct_units_and_never_db_sqlite(self) -> None: + self.assertEqual( + run( + '.github/ci-paths.toml', + '.github/workflows/main.yml', + '.github/workflows/test_all.yml', + '.github/workflows/test-group.yml', + '.github/workflows/test_windows.yml', + '.mise/scripts/dev/ci_changes.py', + ), + { + 'cargo-clippy', + 'cargo-machete', + 'forward-proxy', + 'build-documentation', + 'cargo-publish-dry-run', + 'xks-remote', + 'interop:pykmip', + }, + ) + + def test_classifier_config_change_runs_nothing(self) -> None: + self.assertEqual(run('.github/ci-paths.toml'), set()) + + def test_forward_proxy_workflow(self) -> None: + self.assertEqual(run('.github/workflows/forward_proxy.yml'), {'forward-proxy'}) + + def test_rust_only_workflows_run_nothing(self) -> None: + self.assertEqual( + run('.github/workflows/no-nix.yml', '.github/workflows/test_windows.yml'), + set(), + ) + + def test_no_nix_and_windows_cargo_test_need_rust_source(self) -> None: + for path in ( + '.github/workflows/main.yml', + '.github/workflows/test_all.yml', + '.mise/tasks/test/db/psql', + '.mise/tasks/test/interop/pykmip', + 'ui/src/App.tsx', + 'documentation/docs/index.md', + 'vcpkg.json', + '.github/actions/windows-vs-ninja/action.yml', + '.mise/scripts/windows/cargo_test.ps1', + '.mise/scripts/windows/test_ui.ps1', + ): + with self.subTest(path=path): + self.assertFalse(run(path) & {'no-nix', 'windows-cargo-test'}) + + def test_xks_remote_runs_on_xks_related_rust_source(self) -> None: + # The job builds and deploys cosmian_kms, so the route, its config and the server wiring all trigger it. + for path in ( + 'crate/server/src/routes/aws_xks/sigv4.rs', + 'crate/server/src/routes/aws_xks/encrypt_decrypt/encrypt_.rs', + 'crate/server/src/config/params/server_params.rs', + 'crate/server/src/config/command_line/clap_config.rs', + 'crate/server/src/start_kms_server.rs', + 'crate/server/src/middlewares/auth_verifier/token.rs', + 'crate/server/src/core/operations/key_ops/crypto_op.rs', + ): + with self.subTest(path=path): + self.assertIn('xks-remote', run(path)) + + def test_group_wrapper_runs_nothing(self) -> None: + self.assertEqual(run('.github/workflows/test-group.yml'), set()) + + +class Matrices(unittest.TestCase): + """outputs(): the legs and caller flags main.yml feeds to test_all.yml.""" + + def out(self, *files: str) -> dict[str, str]: + skipped, _ = ci_changes.classify(CFG, list(files)) + return ci_changes.outputs(CFG, skipped) + + def test_everything_runs_every_leg_in_toml_order(self) -> None: + for out in (self.out(), ci_changes.outputs(CFG, [])): + self.assertEqual(json.loads(out['suites-matrix']), FULL_SUITES) + self.assertEqual(len(FULL_SUITES), 38) + self.assertEqual((out['run-test'], out['run-windows']), ('true', 'true')) + + def test_workflow_only_pr(self) -> None: + out = self.out( + '.github/ci-paths.toml', + '.github/workflows/main.yml', + '.github/workflows/test_all.yml', + '.github/workflows/test-group.yml', + '.github/workflows/test_windows.yml', + '.mise/scripts/dev/ci_changes.py', + ) + self.assertEqual( + json.loads(out['suites-matrix']), leg('interop:pykmip', 'non-fips') + ) + self.assertEqual((out['run-test'], out['run-windows']), ('true', 'false')) + + def test_pg_store_change_keeps_only_the_legs_it_triggers(self) -> None: + out = self.out('crate/server_database/src/stores/sql/pgsql.rs') + self.assertEqual( + json.loads(out['suites-matrix']), + [ + *leg('db:sqlite', *BOTH), + *leg('db:psql', *BOTH), + *leg('db:openbao', *BOTH), + *leg('interop:ssh-secrets', *BOTH), + ], + ) + self.assertEqual((out['run-test'], out['run-windows']), ('true', 'true')) + + def test_ui_change_has_no_legs_but_still_runs_the_callers(self) -> None: + out = self.out('ui/src/App.tsx') + self.assertEqual(out['suites-matrix'], '[]') + self.assertEqual((out['run-test'], out['run-windows']), ('true', 'true')) + + def test_only_hsm_running_keeps_its_bench_models_per_variant(self) -> None: + out = ci_changes.outputs(CFG, sorted(EVERYTHING - {'hsm'})) + self.assertEqual( + json.loads(out['suites-matrix']), + [ + *leg('hsm', 'fips', bench=SOFT_HSMS), + *leg('hsm', 'non-fips', bench=SOFT_HSMS + ' kryoptic'), + ], + ) + + def test_change_that_triggers_no_unit_skips_both_callers(self) -> None: + out = self.out('clippy.toml') + self.assertEqual((out['run-test'], out['run-windows']), ('false', 'false')) + + +class Wiring(unittest.TestCase): + """Every unit is gated where the workflows test it, and its caller group lists it (else it would never run).""" + + GATE = re.compile( + r"contains\(fromJSON\((?:needs\.changes\.outputs\.skip|inputs\.skip-units \|\| '\[\]')\), '([a-z0-9:-]+)'\)" + ) + + def gated(self, name: str) -> set[str]: + text = (ci_changes.REPO / '.github' / 'workflows' / name).read_text() + return set(self.GATE.findall(text)) + + def test_units_callers_and_workflows_agree(self) -> None: + m, t, w = ( + self.gated(n) for n in ('main.yml', 'test_all.yml', 'test_windows.yml') + ) + v = set(CFG.variants) + self.assertEqual(m | t | w | v, EVERYTHING) + self.assertEqual( + t & v, {'pki'} + ) # the macOS sibling of the `pki` suite legs only + self.assertFalse( + {'cloud', 'ui'} & v + ) # their own jobs: secrets scoped by the job + self.assertEqual(m & (t | v | w), set()) + self.assertEqual(w & (t | v), set()) + self.assertEqual(set(CFG.callers['test']), t | v) + self.assertEqual(set(CFG.callers['windows']), w) + + +class FailSafe(unittest.TestCase): + def test_empty_diff_runs_everything(self) -> None: + self.assertEqual(run(), EVERYTHING) + + def test_unknown_path_runs_everything(self) -> None: + self.assertEqual(run('brand/new.txt'), EVERYTHING) + + def test_unknown_path_among_ignored_files_runs_everything(self) -> None: + self.assertEqual(run('README.md', 'brand/new.txt'), EVERYTHING) + + def test_full_patterns_run_everything(self) -> None: + for path in ( + 'Cargo.lock', + 'Cargo.toml', + 'rust-toolchain.toml', + 'mise.toml', + '.mise/lib/common.sh', + '.github/actions/install-mise/action.yml', + 'crate/crypto/build.rs', + 'test_data', + ): + with self.subTest(path=path): + self.assertEqual(run(path), EVERYTHING) + + def test_one_full_file_overrides_ignored_ones(self) -> None: + self.assertEqual(run('README.md', 'Cargo.lock'), EVERYTHING) + + +class MixedChanges(unittest.TestCase): + def test_ui_plus_docs(self) -> None: + self.assertEqual( + run('ui/src/App.tsx', 'documentation/docs/index.md'), + {'ui', 'windows-ui', 'build-documentation'}, + ) + + def test_union_of_independent_areas(self) -> None: + self.assertEqual( + run('ui/src/App.tsx', 'crate/server_database/src/stores/redis/findex.rs'), + WORKSPACE | {'ui', 'windows-ui', 'db:redis'}, + ) + + def test_core_plus_ui_is_server_wide_plus_ui(self) -> None: + self.assertEqual( + run('crate/crypto/src/lib.rs', 'ui/src/App.tsx'), + SERVER_WIDE | {'ui', 'windows-ui'}, + ) + + +# One file per unit that triggers it (and not by way of `full`). +UNIT_SAMPLES = { + 'build-documentation': 'documentation/docs/index.md', + 'cargo-clippy': 'clippy.toml', + 'cargo-machete': 'crate/server/src/lib.rs', + 'no-nix': 'crate/server/src/lib.rs', + 'forward-proxy': '.github/workflows/forward_proxy.yml', + 'cargo-publish-dry-run': '.github/workflows/cargo-publish.yml', + 'xks-remote': 'crate/server/src/routes/aws_xks/mod.rs', + 'db:sqlite': '.mise/tasks/test/db/sqlite', + 'db:psql': 'crate/server_database/src/stores/sql/pgsql.rs', + 'db:mysql': 'crate/server_database/src/stores/sql/mysql.rs', + 'db:mariadb': '.mise/tasks/test/db/mariadb', + 'db:percona': '.mise/tasks/test/db/percona', + 'db:redis': 'crate/server_database/src/stores/redis/findex.rs', + 'db:openbao': '.mise/scripts/test/openbao/bao_verifier.sh', + 'cloud': 'crate/server/src/routes/google_cse/mod.rs', + 'hsm': 'crate/hsm/utimaco/src/lib.rs', + 'pkcs11': 'crate/clients/pkcs11/module/src/pkcs11.rs', + 'obs': 'crate/server/src/core/otel_metrics.rs', + 'pki': 'crate/server/src/routes/est/mod.rs', + 'spire': '.mise/tasks/test/spire/_default', + 'ui': 'ui/src/App.tsx', + 'interop:ase': '.mise/tasks/test/interop/ase', + 'interop:db2': '.mise/tasks/test/interop/db2', + 'interop:edb-tde': '.mise/tasks/test/interop/edb-tde', + 'interop:iris': '.mise/tasks/test/interop/iris', + 'interop:jose': 'crate/server/src/routes/jose/mod.rs', + 'interop:kmip-go': '.mise/tasks/test/interop/kmip-go', + 'interop:kmipkit': '.mise/tasks/test/interop/kmipkit', + 'interop:openbao': '.mise/tasks/test/interop/openbao', + 'interop:openbao-auth-verifier': '.mise/tasks/test/interop/openbao-auth-verifier', + 'interop:openbao-kmip': '.mise/tasks/test/interop/openbao-kmip', + 'interop:pykmip': '.mise/tasks/test/interop/pykmip', + 'interop:ssh-secrets': '.mise/tasks/test/interop/ssh-secrets', + 'windows-cargo-test': 'crate/server/src/lib.rs', + 'windows-ui': '.mise/scripts/windows/test_ui.ps1', + 'windows-cng-ksp': '.mise/scripts/windows/test_cng_ksp.ps1', + 'windows-hsm-idemia': '.mise/scripts/windows/test_hsm_idemia.ps1', + 'windows-est': '.mise/scripts/windows/test_est_windows.ps1', +} + + +class ConfigIntegrity(unittest.TestCase): + def test_samples_cover_every_unit(self) -> None: + # A new or renamed unit fails here until it has a sample that triggers it. + self.assertEqual(set(UNIT_SAMPLES), EVERYTHING) + + def test_every_unit_is_reachable_without_running_everything(self) -> None: + for unit, path in UNIT_SAMPLES.items(): + with self.subTest(unit=unit): + ran = run(path) + self.assertIn(unit, ran) + self.assertNotEqual(ran, EVERYTHING, f"{path} hits full or an orphan") + + def test_classify_reports_skipped_units_sorted_and_disjoint_from_run(self) -> None: + skipped, _ = ci_changes.classify(CFG, ['ui/src/App.tsx']) + self.assertEqual(skipped, sorted(skipped)) + self.assertFalse(set(skipped) & {'ui', 'windows-ui'}) + + +def load(toml: str) -> ci_changes.Config: + with tempfile.TemporaryDirectory() as tmp: + path = Path(tmp) / 'ci-paths.toml' + path.write_text(textwrap.dedent(toml)) + return ci_changes.load_config(path) + + +MINI = """ + full = '^Cargo\\.lock$' + ignore = '\\.md$' + [sets] + core = '^lib/(?!feature/)' + [units.a] + sets = ["core"] + [units.b] + files = '^lib/feature/' + [units.c] + sets = ["core"] + files = ''' + ^extra/ # comments and whitespace are ignored (re.VERBOSE) + | ^more/ + ''' +""" + + +class ClassifyEngine(unittest.TestCase): + """classify() semantics on a small inline config: the fail-safe branches decide whether CI is skipped.""" + + def setUp(self) -> None: + self.cfg = load(MINI) + + def skipped(self, *files: str) -> list[str]: + return ci_changes.classify(self.cfg, list(files))[0] + + def test_empty_diff_skips_nothing(self) -> None: + self.assertEqual(self.skipped(), []) + + def test_full_hit_skips_nothing_even_with_ignored_files(self) -> None: + self.assertEqual(self.skipped('README.md', 'Cargo.lock'), []) + + def test_orphan_skips_nothing(self) -> None: + self.assertEqual(self.skipped('lib/feature/x.rs', 'orphan.bin'), []) + + def test_ignored_only_skips_everything(self) -> None: + self.assertEqual(self.skipped('README.md'), ['a', 'b', 'c']) + + def test_negative_lookahead_carves_feature_path_out_of_the_set(self) -> None: + self.assertEqual(self.skipped('lib/feature/x.rs'), ['a', 'c']) + + def test_set_path_triggers_every_unit_using_the_set(self) -> None: + self.assertEqual(self.skipped('lib/core.rs'), ['b']) + + def test_unit_files_pattern_is_verbose_alternation(self) -> None: + self.assertEqual(self.skipped('more/x', 'README.md'), ['a', 'b']) + self.assertEqual(self.skipped('extra/x'), ['a', 'b']) + + def test_union_over_changed_files_and_sorted_result(self) -> None: + self.assertEqual(self.skipped('lib/feature/x.rs', 'extra/y'), ['a']) + + def test_rename_old_and_new_path_both_count(self) -> None: + self.assertEqual(self.skipped('lib/core.rs', 'lib/feature/core.rs'), []) + + +class LoadConfig(unittest.TestCase): + def rejects(self, toml: str) -> None: + with contextlib.redirect_stderr(io.StringIO()), self.assertRaises(SystemExit): + load(toml) + + def test_unknown_set_is_rejected(self) -> None: + self.rejects("full = 'x'\nignore = 'y'\n[units.a]\nsets = ['nope']\n") + + def test_unit_without_sets_or_files_is_rejected(self) -> None: + self.rejects("full = 'x'\nignore = 'y'\n[units.a]\n") + + def test_unknown_unit_key_is_rejected(self) -> None: + self.rejects("full = 'x'\nignore = 'y'\n[units.a]\nfile = 'x'\n") + + def test_missing_full_is_rejected(self) -> None: + self.rejects("ignore = 'y'\n[units.a]\nfiles = 'x'\n") + + def test_invalid_regex_is_rejected(self) -> None: + self.rejects("full = '('\nignore = 'y'\n[units.a]\nfiles = 'x'\n") + + def test_non_string_pattern_is_rejected_with_its_key(self) -> None: + err = io.StringIO() + with contextlib.redirect_stderr(err), self.assertRaises(SystemExit) as ctx: + load("full = 1\nignore = 'y'\n[units.a]\nfiles = 'x'\n") + self.assertEqual(ctx.exception.code, 1) + self.assertIn('full: expected a regex string', err.getvalue()) + + def test_invalid_regex_message_names_the_key(self) -> None: + err = io.StringIO() + with contextlib.redirect_stderr(err), self.assertRaises(SystemExit): + load("full = 'x'\nignore = 'y'\n[units.a]\nfiles = '('\n") + self.assertIn('units.a.files: invalid regex', err.getvalue()) + + def test_missing_ignore_and_units_are_rejected(self) -> None: + self.rejects("full = 'x'\n[units.a]\nfiles = 'x'\n") + self.rejects("full = 'x'\nignore = 'y'\n") + + def test_set_may_be_used_by_several_units_and_units_keep_file_order(self) -> None: + cfg = load(MINI) + self.assertEqual(list(cfg.units), ['a', 'b', 'c']) + self.assertEqual(len(cfg.units['a']), 1) # set only + self.assertEqual(len(cfg.units['b']), 1) # files only + self.assertEqual(len(cfg.units['c']), 2) # set + files + + def test_bench_must_map_variants_of_the_unit(self) -> None: + head = "full = 'x'\nignore = 'y'\n[units.h]\nfiles = 'x'\n" + self.rejects(head + "bench = {fips = 'a'}\n") # no variants + self.rejects(head + "variants = ['fips']\nbench = {non-fips = 'a'}\n") + self.rejects(head + "variants = ['fips']\nbench = {fips = 1}\n") + + def test_invalid_variants_are_rejected(self) -> None: + for bad in ("['fips', 'fips']", '[]', "['x']"): + with self.subTest(variants=bad): + self.rejects( + f"full = 'x'\nignore = 'y'\n[units.'db:x']\nfiles = 'x'\nvariants = {bad}\n" + ) + + def test_unit_with_only_variants_is_rejected(self) -> None: + self.rejects("full = 'x'\nignore = 'y'\n[units.'db:x']\nvariants = ['fips']\n") + + def test_bad_callers_are_rejected(self) -> None: + head = "full = 'x'\nignore = 'y'\n[units.a]\nfiles = 'x'\n[callers]\n" + self.rejects(head + "t = ['nope*']\n") + self.rejects(head + "t = 'a'\n") + + def test_callers_expand_patterns_in_unit_order(self) -> None: + cfg = load( + "full = 'x'\nignore = 'y'\n[units.'db:b']\nfiles = 'x'\nvariants = ['fips']\n" + "[units.a]\nfiles = 'x'\n[units.'db:c']\nfiles = 'x'\nvariants = ['fips']\n" + "[callers]\nt = ['db:*', 'a']\n" + ) + self.assertEqual(cfg.callers['t'], ['db:b', 'a', 'db:c']) + + +# Temp repos must not see the runner's or the developer's git config (signing, hooks, identity) nor write the +# `changes` step's real $GITHUB_OUTPUT. +GIT_ENV = { + **{k: v for k, v in os.environ.items() if k != 'GITHUB_OUTPUT'}, + 'GIT_CONFIG_GLOBAL': os.devnull, + 'GIT_CONFIG_NOSYSTEM': '1', + 'GIT_AUTHOR_NAME': 't', + 'GIT_AUTHOR_EMAIL': 't@t', + 'GIT_COMMITTER_NAME': 't', + 'GIT_COMMITTER_EMAIL': 't@t', +} + + +def git(repo: Path, *args: str) -> str: + return subprocess.run( + ['git', '-c', 'commit.gpgsign=false', *args], + cwd=repo, + env=GIT_ENV, + check=True, + capture_output=True, + text=True, + ).stdout + + +def commit_files(repo: Path, message: str, **files: str | None) -> None: + """Write (or delete, when the content is None) `files` (keys use `__` for `/`) and commit.""" + for name, content in files.items(): + path = repo / name.replace('__', '/') + if content is None: + path.unlink() + else: + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(content) + git(repo, 'add', '-A') + git(repo, 'commit', '-q', '-m', message) + + +class ChangedFiles(unittest.TestCase): + """changed_files() lists what the PR branch changes since it forked from the base, as `git diff` sees it.""" + + def setUp(self) -> None: + tmp = tempfile.TemporaryDirectory() + self.addCleanup(tmp.cleanup) + self.repo = Path(tmp.name) + git(self.repo, 'init', '-q', '-b', 'main') + commit_files(self.repo, 'base', a_txt='1', b_txt='same content\n' * 20) + git(self.repo, 'switch', '-q', '-c', 'feature') + patcher = mock.patch.object(ci_changes, 'REPO', self.repo) + patcher.start() + self.addCleanup(patcher.stop) + + def test_modified_added_and_deleted_files(self) -> None: + commit_files(self.repo, 'pr', a_txt='2', c__d_txt='new') + commit_files(self.repo, 'pr2', b_txt=None) + self.assertEqual( + ci_changes.changed_files('main', 'feature'), ['a_txt', 'b_txt', 'c/d_txt'] + ) + + def test_rename_lists_old_and_new_path(self) -> None: + git(self.repo, 'mv', 'b_txt', 'moved_txt') + git(self.repo, 'commit', '-q', '-m', 'rename') + self.assertEqual( + ci_changes.changed_files('main', 'feature'), ['b_txt', 'moved_txt'] + ) + + def test_changes_made_on_the_base_after_the_fork_are_ignored(self) -> None: + commit_files(self.repo, 'pr', a_txt='2') + git(self.repo, 'switch', '-q', 'main') + commit_files(self.repo, 'base moves on', base_only_txt='x') + git(self.repo, 'switch', '-q', 'feature') + self.assertEqual(ci_changes.changed_files('main', 'feature'), ['a_txt']) + + def test_no_change_is_an_empty_list(self) -> None: + self.assertEqual(ci_changes.changed_files('main', 'feature'), []) + + def test_head_caret_one_is_the_pr_merge_commit_base(self) -> None: + # In CI the checkout is the test merge commit: HEAD^1 is the base tip, HEAD the merge. + commit_files(self.repo, 'pr', a_txt='2') + git(self.repo, 'switch', '-q', 'main') + git(self.repo, 'merge', '-q', '--no-ff', '-m', 'merge', 'feature') + self.assertEqual(ci_changes.changed_files('HEAD^1', 'HEAD'), ['a_txt']) + + def test_unknown_ref_raises(self) -> None: + with self.assertRaises(subprocess.CalledProcessError): + ci_changes.changed_files('does-not-exist', 'feature') + + +class Main(unittest.TestCase): + """main(): console report, `skip=` line and the $GITHUB_OUTPUT file the workflows read.""" + + def run_main( + self, files: list[str], *argv: str, output: Path | None + ) -> tuple[str, mock.MagicMock]: + env = {} if output is None else {'GITHUB_OUTPUT': str(output)} + out = io.StringIO() + with ( + mock.patch.dict(os.environ, env), + mock.patch.object(sys, 'argv', ['ci_changes.py', *argv]), + mock.patch.object(ci_changes, 'changed_files', return_value=files) as cf, + contextlib.redirect_stdout(out), + ): + if output is None: + os.environ.pop('GITHUB_OUTPUT', None) + ci_changes.main() + return out.getvalue(), cf + + def setUp(self) -> None: + tmp = tempfile.TemporaryDirectory() + self.addCleanup(tmp.cleanup) + self.output = Path(tmp.name) / 'github_output' + + def test_report_lists_files_reason_and_every_unit(self) -> None: + text, _ = self.run_main(['ui/src/App.tsx'], output=self.output) + lines = text.splitlines() + self.assertEqual(lines[0], 'Changed files (1):') + self.assertEqual(lines[1], ' ui/src/App.tsx') + self.assertEqual(lines[2], f"2 of {len(EVERYTHING)} units triggered") + marks = {line[5:]: line[:4] for line in lines[3:-4]} + self.assertEqual(set(marks), EVERYTHING) + self.assertEqual( + {u for u, m in marks.items() if m == 'RUN '}, {'ui', 'windows-ui'} + ) + self.assertTrue(all(m in ('RUN ', 'SKIP') for m in marks.values())) + + def test_output_lines_are_compact_json_in_order_and_appended_to_github_output( + self, + ) -> None: + text, _ = self.run_main(['ui/src/App.tsx'], output=self.output) + written = self.output.read_text().splitlines() + self.assertEqual(written, text.splitlines()[-4:]) + self.assertEqual( + [line.split('=', 1)[0] for line in written], + ['skip', 'suites-matrix', 'run-test', 'run-windows'], + ) + self.assertNotIn(' ', written[0]) + skipped = json.loads(written[0].removeprefix('skip=')) + self.assertEqual(skipped, sorted(EVERYTHING - {'ui', 'windows-ui'})) + + def test_github_output_is_appended_not_overwritten(self) -> None: + self.output.write_text('other=1\n') + self.run_main(['ui/src/App.tsx'], output=self.output) + lines = self.output.read_text().splitlines() + self.assertEqual(lines[0], 'other=1') + self.assertTrue(lines[1].startswith('skip=')) + + def test_without_github_output_only_prints(self) -> None: + text, _ = self.run_main(['ui/src/App.tsx'], output=None) + self.assertTrue(text.splitlines()[-4].startswith('skip=[')) + self.assertFalse(self.output.exists()) + + def assert_runs_everything(self, lines: list[str]) -> None: + got = dict(line.split('=', 1) for line in lines) + self.assertEqual(got['skip'], '[]') + self.assertEqual(json.loads(got['suites-matrix']), FULL_SUITES) + self.assertEqual((got['run-test'], got['run-windows']), ('true', 'true')) + + def test_empty_diff_reports_run_everything(self) -> None: + text, _ = self.run_main([], output=self.output) + self.assertIn('Changed files (0):', text) + self.assertIn('empty diff: run everything', text) + self.assert_runs_everything(self.output.read_text().splitlines()) + self.assertNotIn('SKIP', text) + + def test_full_match_reports_run_everything(self) -> None: + text, _ = self.run_main(['Cargo.lock', 'README.md'], output=self.output) + self.assertIn('Cargo.lock matches full: run everything', text) + self.assert_runs_everything(self.output.read_text().splitlines()) + + def test_orphan_reports_run_everything(self) -> None: + text, _ = self.run_main(['brand/new.txt'], output=self.output) + self.assertIn('brand/new.txt matches no unit and is not ignored', text) + self.assert_runs_everything(self.output.read_text().splitlines()) + + def test_all_flag_runs_everything_without_git(self) -> None: + out = io.StringIO() + with ( + mock.patch.object( + ci_changes, + 'changed_files', + side_effect=AssertionError('git was called'), + ), + mock.patch.dict(os.environ, {'GITHUB_OUTPUT': str(self.output)}), + mock.patch.object(sys, 'argv', ['ci_changes.py', '--all']), + contextlib.redirect_stdout(out), + ): + ci_changes.main() + self.assertIn('not a pull request: run everything', out.getvalue()) + self.assert_runs_everything(self.output.read_text().splitlines()) + + def test_docs_only_skips_every_unit(self) -> None: + text, _ = self.run_main(['README.md'], output=self.output) + got = dict(line.split('=', 1) for line in self.output.read_text().splitlines()) + self.assertEqual(json.loads(got['skip']), sorted(EVERYTHING)) + self.assertEqual(got['suites-matrix'], '[]') + self.assertEqual((got['run-test'], got['run-windows']), ('false', 'false')) + self.assertNotIn('RUN ', text) + + def test_default_refs_are_the_pr_merge_commit_parent_and_head(self) -> None: + _, cf = self.run_main(['README.md'], output=self.output) + cf.assert_called_once_with('HEAD^1', 'HEAD') + + def test_base_and_head_flags_are_forwarded(self) -> None: + _, cf = self.run_main( + ['README.md'], + '--base', + 'origin/develop', + '--head', + 'f00', + output=self.output, + ) + cf.assert_called_once_with('origin/develop', 'f00') + + +class CommandLine(unittest.TestCase): + def test_script_runs_as_a_program(self) -> None: + script = Path(ci_changes.__file__) + done = subprocess.run( + [sys.executable, str(script), '--base', 'HEAD', '--head', 'HEAD'], + cwd=ci_changes.REPO, + env=GIT_ENV, + capture_output=True, + text=True, + check=True, + ) + self.assertIn('empty diff: run everything', done.stdout) + self.assertIn('skip=[]', done.stdout.splitlines()) + + def test_unknown_flag_is_rejected(self) -> None: + script = Path(ci_changes.__file__) + done = subprocess.run( + [sys.executable, str(script), '--nope'], + env=GIT_ENV, + capture_output=True, + text=True, + ) + self.assertEqual(done.returncode, 2) + + +if __name__ == '__main__': + unittest.main() diff --git a/.mise/tasks/dev/ci-changes b/.mise/tasks/dev/ci-changes new file mode 100755 index 0000000000..ea7ae7d9f2 --- /dev/null +++ b/.mise/tasks/dev/ci-changes @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +#MISE description="Classify the files a PR changes with .github/ci-paths.toml: prints and appends skip, db-matrix, interop-matrix, run-test and run-windows to GITHUB_OUTPUT" +#USAGE flag "--base " help="Diff from the merge base of and --head (PR merge commit: HEAD^1 is the base tip)" default="HEAD^1" +#USAGE flag "--head " help="Changed side" default="HEAD" +#USAGE flag "--all" help="Not a pull request: run every unit and emit the full matrices (no git diff)" +#USAGE flag "--self-test" help="Run the unit tests of the classifier (.mise/scripts/dev/test_ci_changes.py) against .github/ci-paths.toml and exit" +set -euo pipefail +source "${MISE_CONFIG_ROOT}/.mise/lib/common.sh" + +REPO_ROOT="$(get_repo_root)" +PYTHON="$(pick_python312)" +print_header "CI changed-area classification" +if [ "${usage_self_test:-false}" = "true" ]; then + "${PYTHON}" -m unittest discover -s "${REPO_ROOT}/.mise/scripts/dev" -p 'test_ci_changes.py' +elif [ "${usage_all:-false}" = "true" ]; then + "${PYTHON}" "${REPO_ROOT}/.mise/scripts/dev/ci_changes.py" --all +else + "${PYTHON}" "${REPO_ROOT}/.mise/scripts/dev/ci_changes.py" --base "${usage_base:-HEAD^1}" --head "${usage_head:-HEAD}" +fi +print_success "Classification complete" diff --git a/CHANGELOG/ci_pr-path-gating.md b/CHANGELOG/ci_pr-path-gating.md new file mode 100644 index 0000000000..7a03d96621 --- /dev/null +++ b/CHANGELOG/ci_pr-path-gating.md @@ -0,0 +1,4 @@ +## CI + +- Run each pull-request CI job only when files related to it changed. `.github/ci-paths.toml` lists, per CI unit (clippy, machete, no-nix, forward-proxy, the documentation build, publish dry run, XKS remote, every `test-group.yml` suite, the Windows jobs and the macOS PKI job), the regexes of the files that trigger it; the new `changes` job of `main.yml` runs `mise run dev:ci-changes` (`.mise/scripts/dev/ci_changes.py`) and passes the skipped units down as `skip-units` to `test_all.yml` and `test_windows.yml`. Any `crate/**` change still runs the whole-workspace jobs (clippy, machete, no-nix, publish dry run, `db:sqlite`, Windows `cargo test`); code linked into the server also runs `spire`, `xks-remote` and `forward-proxy`. The other suites (`ui`, `interop:*`, `pki`, `pkcs11`, `obs`, `hsm`, `cloud`, `db:*` other than sqlite, and the Windows mirrors) run only on their own crates, paths and test scripts: the database suites on `server_database`, the KMIP interop suites on `kmip` and the `/kmip` route. `build-documentation` runs only on `documentation/`, `AGENTS.md`, `CONTRIBUTING.md`, the AI instruction and skill files and the docs tasks. A change to `main.yml` or `test_all.yml` runs only the units defined in or called directly by it, plus `interop:pykmip` for `test_all.yml` as the smoke leg of the suite matrix; `no-nix.yml`, `test_windows.yml`, `cargo_test.ps1`, `test-group.yml`, `ci-paths.toml` and `ci_changes.py` run no suite, so `no-nix` and the Windows `cargo test` need a Rust source change. A changed file that matches no unit and is not ignored, a file matching `full`, or an empty diff runs everything, as do tags, the nightly schedule and manual dispatch. +- Show fewer skipped rows in the pull-request run graph. `ci_changes.py` now also emits `suites-matrix` (the legs of the running suites, from the `variants` of each unit in `ci-paths.toml`) and `run-test` / `run-windows` (from its `[callers]` table). `test_all.yml` runs the `db`, `interop`, `hsm`, `obs`, `pkcs11`, `pki` and `spire` suites as legs of one `test-suites` matrix job, so a suite that does not run has no row (`test-db.yml` and `test-interop.yml` are gone, the database environment moved into `test-group.yml`, which no longer takes `skip-units` or `extra-env`); `test-cloud` and `test-ui` stay separate jobs so their secrets are scoped by the job, not by an expression. `main.yml` skips the whole `test` or `windows` call, as one row, when none of its units runs. `test_all.yml` loses its `workflow_dispatch` trigger (dispatch `main.yml`; `mise run dev:ci-changes --all` emits the full matrix for non-PR events). The nightly-only link check moved from `main.yml` to its own `linkcheck.yml` workflow, so pull requests no longer list it.