From f481a324af00860fb3bc8b38c17991e1a50fe0eb Mon Sep 17 00:00:00 2001 From: Manuthor Date: Sat, 21 Nov 2026 17:45:44 +0100 Subject: [PATCH 01/14] ci: gate pull-request jobs on the files they depend on - Add .github/ci-paths.toml: per-unit path regexes, full/ignore lists, fail-safe on unmatched files. - Add mise task dev:ci-changes (ci_changes.py) classifying a PR diff into skipped units. - Add the `changes` job to main.yml and pass skip-units through test_all, test-db, test-interop, test-group and test_windows. --- .github/ci-paths.toml | 321 +++++++++++++++++++++++++++++ .github/workflows/main.yml | 43 ++++ .github/workflows/test-db.yml | 7 + .github/workflows/test-group.yml | 6 + .github/workflows/test-interop.yml | 7 + .github/workflows/test_all.yml | 24 ++- .github/workflows/test_windows.yml | 10 + .mise/scripts/dev/ci_changes.py | 188 +++++++++++++++++ .mise/tasks/dev/ci-changes | 16 ++ CHANGELOG/ci_pr-path-gating.md | 3 + 10 files changed, 623 insertions(+), 2 deletions(-) create mode 100644 .github/ci-paths.toml create mode 100755 .mise/scripts/dev/ci_changes.py create mode 100755 .mise/tasks/dev/ci-changes create mode 100644 CHANGELOG/ci_pr-path-gating.md diff --git a/.github/ci-paths.toml b/.github/ci-paths.toml new file mode 100644 index 0000000000..74c19e799b --- /dev/null +++ b/.github/ci-paths.toml @@ -0,0 +1,321 @@ +# 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. +# Tags, schedule and workflow_dispatch ignore this file and run everything. + +full = ''' + ^\.github/workflows/(main|test_all|test-group)\.yml$ +| ^\.github/actions/(install-mise|install-rust|setup-nix|setup-nix-mise|cache-openssl-buildrs|cleanup-runner)/ +| ^\.github/ci-paths\.toml$ +| ^\.mise/tasks/dev/ci-changes$ +| ^\.mise/scripts/dev/ci_changes\.py$ +| ^\.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$ +| ^documentation/ +| ^CHANGELOG/ +| ^\.github/(skills|instructions)/ +| ^\.github/(dependabot\.yml|\.markdownlint\.yaml|scripts/patch-kube-apiserver\.py)$ +| ^\.github/workflows/(benchmark|build_windows|cla|flamegraph|github_cache_cleanup|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|docs|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|docs|git|package|pre-commit|release|sbom)/ +''' + +[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 every server-driven suite exercises (linked into cosmian_kms or the ckms / test_kms_server harness). +# The negative lookaheads carve out feature-owned paths: those trigger only the units listing them (+ `rust`). +# 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)$' + +# Every non-sqlite db leg also runs the lib tests of test_kms_server, ckms, cli_actions, cosmian_pkcs11, +# cosmian_kms_k8s_plugin and cosmian_cng (KMS_SHARED_SERVER_TEST_PACKAGES, .mise/lib/common.sh) + SoftHSM2 KEK tests. +db_shared = ''' + ^crate/clients/(pkcs11|cng|k8s)/ +| ^\.mise/tasks/test/db/_default$ +| ^\.mise/lib/softhsm2\.sh$ +| ^\.github/workflows/test-db\.yml$ +''' + +interop_shared = '^\.mise/tasks/test/interop/_default$ | ^\.github/workflows/test-interop\.yml$' + +windows = ''' + ^vcpkg(_fips)?\.json$ +| ^\.github/workflows/test_windows\.yml$ +| ^\.github/actions/(build-static-openssl|windows-vs-ninja)/ +| ^\.mise/scripts/windows/(common|install_ninja)\.ps1$ +''' + +# ── main.yml ──────────────────────────────────────────────────────────────────────────────── +[units.cargo-clippy] +sets = ["rust"] +files = '^clippy\.toml$' + +[units.cargo-machete] +sets = ["rust"] + +[units.no-nix] +sets = ["rust"] +files = '^\.github/workflows/no-nix\.yml$' + +[units.forward-proxy] +sets = ["server_core"] +files = '^\.github/workflows/forward_proxy\.yml$ | ^\.github/scripts/squid/' + +# ── test_all.yml (non test-group jobs) ────────────────────────────────────────────────────── +[units.cargo-publish-dry-run] +sets = ["rust"] +files = '^\.github/workflows/cargo-publish\.yml$' + +[units.xks-remote] +sets = ["server_core"] +files = '^crate/server/src/routes/aws_xks/ | ^\.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$' + +[units."db:psql"] +sets = ["server_core", "db_shared", "pg_store"] +files = '^\.mise/tasks/test/db/psql$' + +[units."db:mysql"] +sets = ["server_core", "db_shared", "mysql_store"] +files = '^\.mise/tasks/test/db/mysql$' + +[units."db:mariadb"] +sets = ["server_core", "db_shared", "mysql_store"] +files = '^\.mise/tasks/test/db/mariadb$' + +[units."db:percona"] +sets = ["server_core", "db_shared", "mysql_store"] +files = '^\.mise/tasks/test/db/percona$' + +[units."db:redis"] +sets = ["server_core", "db_shared"] +files = '^crate/server_database/src/stores/redis/ | ^\.mise/tasks/test/db/redis$' + +[units."db:openbao"] +sets = ["server_core", "pg_store", "mysql_store"] +files = ''' + ^\.mise/tasks/test/db/(_default|openbao)$ +| ^\.mise/tasks/test/interop/openbao$ +| ^\.mise/scripts/test/openbao/ +| ^\.github/workflows/test-db\.yml$ +''' + +[units.cloud] +sets = ["server_core"] +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] +sets = ["server_core"] +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)$ +''' + +[units.pkcs11] +sets = ["server_core"] +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)$ +''' + +[units.obs] +sets = ["server_core"] +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/ +''' + +[units.pki] +sets = ["server_core"] +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$ +''' + +[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$ +''' + +[units.ui] +sets = ["server_core"] +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 = ["server_core", "interop_shared"] +files = '^crate/clients/pkcs11/ | ^\.mise/tasks/test/interop/ase$ | ^\.mise/scripts/test/test_ase_tde\.sh$ | ^\.mise/scripts/docker/ase/' + +[units."interop:db2"] +sets = ["server_core", "interop_shared"] +files = '^\.mise/tasks/test/interop/db2$ | ^\.mise/scripts/test/test_db2_tde\.sh$' + +[units."interop:edb-tde"] +sets = ["server_core", "interop_shared"] +files = '^\.mise/tasks/test/interop/edb-tde$ | ^\.mise/scripts/test/test_edb_tde\.sh$ | ^\.mise/scripts/(edb_tde|pykmip)/' + +[units."interop:iris"] +sets = ["server_core", "interop_shared"] +files = '^\.mise/tasks/test/interop/iris$ | ^\.mise/scripts/test/test_iris\.sh$' + +[units."interop:jose"] +sets = ["server_core", "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))$ +''' + +[units."interop:kmip-go"] +sets = ["server_core", "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$ +''' + +[units."interop:kmipkit"] +sets = ["server_core", "interop_shared"] +files = '^\.mise/tasks/test/interop/kmipkit$ | ^\.mise/scripts/kmipkit-fixes\.patch$' + +[units."interop:openbao"] +sets = ["server_core", "interop_shared"] +files = '^\.mise/tasks/test/interop/openbao$ | ^\.mise/scripts/test/openbao/' + +[units."interop:openbao-auth-verifier"] +sets = ["server_core", "interop_shared"] +files = '^authentication$ | ^\.mise/tasks/test/interop/openbao-auth-verifier$ | ^\.mise/lib/spire_test\.sh$ | ^\.mise/scripts/test/openbao/' + +[units."interop:openbao-kmip"] +sets = ["server_core", "interop_shared"] +files = '^\.mise/tasks/test/interop/openbao-kmip$ | ^\.mise/scripts/test/openbao/' + +[units."interop:pykmip"] +sets = ["server_core", "interop_shared"] +files = '^\.mise/tasks/test/interop/pykmip$ | ^\.mise/scripts/test/test_pykmip\.sh$ | ^\.mise/scripts/pykmip/' + +[units."interop:ssh-secrets"] +sets = ["server_core", "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$ +''' + +# ── test_windows.yml ──────────────────────────────────────────────────────────────────────── +[units.windows-cargo-test] +sets = ["rust", "windows"] +files = '^\.mise/scripts/windows/cargo_test\.ps1$' + +[units.windows-ui] +sets = ["server_core", "windows"] +files = '^ui/ | ^crate/clients/wasm/ | ^crate/server/src/routes/ui_auth\.rs$ | ^\.mise/scripts/windows/test_ui\.ps1$' + +[units.windows-cng-ksp] +sets = ["server_core", "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 = ["server_core", "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 = ["server_core", "windows"] +files = '^crate/server/src/routes/est/ | ^\.mise/scripts/windows/test_est_windows\.ps1$ | ^\.mise/scripts/kmip-go/go\.mod$' diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5ea7fd8236..46a05e9178 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,8 +25,40 @@ 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 }} + 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 + echo 'skip=[]' >> "$GITHUB_OUTPUT" + 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,19 +66,26 @@ 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]') || startsWith(github.ref, 'refs/tags/') || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') @@ -56,12 +95,16 @@ jobs: 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) + 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' uses: ./.github/workflows/test_all.yml secrets: inherit + with: + skip-units: ${{ needs.changes.outputs.skip }} build-documentation: name: Build documentation diff --git a/.github/workflows/test-db.yml b/.github/workflows/test-db.yml index 019eb18c0f..998093976a 100644 --- a/.github/workflows/test-db.yml +++ b/.github/workflows/test-db.yml @@ -4,6 +4,12 @@ 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: + inputs: + skip-units: + description: JSON list of skipped CI units, passed to test-group.yml + required: false + type: string + default: '[]' secrets: DOCKERHUB_USERNAME: {required: false} DOCKERHUB_TOKEN: {required: false} @@ -34,6 +40,7 @@ jobs: with: suite: db:${{ matrix.leaf }} variant: ${{ matrix.variant }} + skip-units: ${{ inputs.skip-units }} extra-env: | POSTGRES_USER=kms PGUSER=kms diff --git a/.github/workflows/test-group.yml b/.github/workflows/test-group.yml index 454e26336b..35c0da141e 100644 --- a/.github/workflows/test-group.yml +++ b/.github/workflows/test-group.yml @@ -27,6 +27,11 @@ on: required: false type: string default: '' + skip-units: + description: JSON list of skipped CI units (.github/ci-paths.toml); the job is skipped when it contains `suite` + required: false + type: string + default: '[]' secrets: DOCKERHUB_USERNAME: {required: false} DOCKERHUB_TOKEN: {required: false} @@ -53,6 +58,7 @@ on: jobs: test: name: test:${{ inputs.suite }} - ${{ inputs.variant }} + if: ${{ !contains(fromJSON(inputs.skip-units || '[]'), inputs.suite) }} runs-on: ubuntu-24.04 permissions: contents: read diff --git a/.github/workflows/test-interop.yml b/.github/workflows/test-interop.yml index 48926ff202..220078c249 100644 --- a/.github/workflows/test-interop.yml +++ b/.github/workflows/test-interop.yml @@ -5,6 +5,12 @@ name: Test interop # hang, leftover state or missing secret never affects another. Leaves that need non-FIPS only run there. on: workflow_call: + inputs: + skip-units: + description: JSON list of skipped CI units, passed to test-group.yml + required: false + type: string + default: '[]' secrets: DOCKERHUB_USERNAME: {required: false} DOCKERHUB_TOKEN: {required: false} @@ -39,6 +45,7 @@ jobs: with: suite: interop:${{ matrix.leaf }} variant: ${{ matrix.variant }} + skip-units: ${{ inputs.skip-units }} secrets: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} diff --git a/.github/workflows/test_all.yml b/.github/workflows/test_all.yml index 4a3d341c45..3451346c57 100644 --- a/.github/workflows/test_all.yml +++ b/.github/workflows/test_all.yml @@ -3,6 +3,12 @@ name: Build all on: workflow_call: + 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: '[]' workflow_dispatch: jobs: @@ -93,6 +99,7 @@ jobs: with: suite: cloud variant: ${{ matrix.variant }} + skip-units: ${{ inputs.skip-units }} secrets: TEST_GOOGLE_OAUTH_CLIENT_ID: ${{ secrets.TEST_GOOGLE_OAUTH_CLIENT_ID }} TEST_GOOGLE_OAUTH_CLIENT_SECRET: ${{ secrets.TEST_GOOGLE_OAUTH_CLIENT_SECRET }} @@ -110,6 +117,8 @@ jobs: name: Test db needs: - nix-dev-shell-cache + with: + skip-units: ${{ inputs.skip-units }} uses: ./.github/workflows/test-db.yml secrets: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} @@ -132,6 +141,7 @@ jobs: # real HSMs: test-hsm-hardware skip: hsm:crypt2pay hsm:proteccio bench: ${{ matrix.bench }} + skip-units: ${{ inputs.skip-units }} secrets: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} @@ -140,6 +150,8 @@ jobs: name: Test interop needs: - nix-dev-shell-cache + with: + skip-units: ${{ inputs.skip-units }} uses: ./.github/workflows/test-interop.yml secrets: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} @@ -159,6 +171,7 @@ jobs: with: suite: obs variant: ${{ matrix.variant }} + skip-units: ${{ inputs.skip-units }} secrets: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} @@ -177,6 +190,7 @@ jobs: with: suite: pkcs11 variant: ${{ matrix.variant }} + skip-units: ${{ inputs.skip-units }} secrets: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} @@ -193,6 +207,7 @@ jobs: with: suite: pki variant: ${{ matrix.variant }} + skip-units: ${{ inputs.skip-units }} secrets: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} @@ -210,6 +225,7 @@ jobs: with: suite: spire variant: ${{ matrix.variant }} + skip-units: ${{ inputs.skip-units }} secrets: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} @@ -230,6 +246,7 @@ jobs: with: suite: ui variant: ${{ matrix.variant }} + skip-units: ${{ inputs.skip-units }} # 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 @@ -283,7 +300,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: @@ -331,6 +349,7 @@ jobs: # 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 +391,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 }} 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..9b463aefdd --- /dev/null +++ b/.mise/scripts/dev/ci_changes.py @@ -0,0 +1,188 @@ +#!/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 `skip=` + ci_changes.py --self-test assert the real config on representative change sets + +The output line `skip=[...]` is appended to $GITHUB_OUTPUT when set (and always printed) so workflow jobs can +gate themselves with `!contains(fromJSON(...), '')`. 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 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' + + +@dataclass(frozen=True) +class Config: + full: re.Pattern[str] + ignore: re.Pattern[str] + units: dict[str, list[re.Pattern[str]]] + + +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]]] = {} + for unit, spec in raw['units'].items(): + unknown = set(spec) - {'sets', 'files'} + if unknown: + fail(f'units.{unit}: unknown key(s) {sorted(unknown)}') + if not spec: + fail(f'units.{unit}: needs `sets` or `files`') + 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 + return Config( + full=compile_pattern('full', raw['full']), + ignore=compile_pattern('ignore', raw['ignore']), + units=units, + ) + + +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 self_test() -> None: + cfg = load_config(CONFIG) + everything = set(cfg.units) + + def run(files: list[str]) -> set[str]: + return everything - set(classify(cfg, files)[0]) + + assert classify(cfg, [])[0] == [] + assert run(['documentation/docs/index.md', 'CHANGELOG/x.md']) == set() + assert run(['ui/src/App.tsx']) == {'ui', 'windows-ui'} + assert run(['.mise/scripts/test/test_iris.sh']) == {'interop:iris'} + for files in ( + ['crate/kmip/src/lib.rs'], + ['crate/server_database/src/stores/sql/query.sql'], + ['.mise/lib/common.sh'], + ['test_data'], + ['brand/new.txt'], + ): + assert run(files) == everything, files + + xks = run(['crate/server/src/routes/aws_xks/mod.rs']) + assert { + 'cloud', + 'xks-remote', + 'db:sqlite', + 'no-nix', + 'cargo-clippy', + 'windows-cargo-test', + } <= xks + assert not {'db:psql', 'hsm', 'ui'} & xks + + pg = run(['crate/server_database/src/stores/sql/pgsql.rs']) + assert {'db:psql', 'db:openbao', 'interop:ssh-secrets', 'db:sqlite'} <= pg + assert not {'db:mysql', 'interop:ase'} & pg + + utimaco = run(['crate/hsm/utimaco/src/lib.rs']) + assert {'hsm', 'windows-hsm-idemia'} <= utimaco + assert not {'pkcs11', 'db:psql'} & utimaco + print('self-test OK') + + +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('--self-test', action='store_true') + args = parser.parse_args() + if args.self_test: + self_test() + return + + cfg = load_config(CONFIG) + 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}') + + line = f'skip={json.dumps(skipped, separators=(",", ":"))}' + output = os.environ.get('GITHUB_OUTPUT') + if output: + with open(output, 'a', encoding='utf-8') as handle: + handle.write(line + '\n') + print(line) + + +if __name__ == '__main__': + main() diff --git a/.mise/tasks/dev/ci-changes b/.mise/tasks/dev/ci-changes new file mode 100755 index 0000000000..c4998b0eef --- /dev/null +++ b/.mise/tasks/dev/ci-changes @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +#MISE description="Classify the files a PR changes with .github/ci-paths.toml: prints and appends skip= 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 "--self-test" help="Run the built-in asserts 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)" +ARGS=(--base "${usage_base:-HEAD^1}" --head "${usage_head:-HEAD}") +[ "${usage_self_test:-false}" = "true" ] && ARGS+=(--self-test) + +print_header "CI changed-area classification" +"${PYTHON}" "${REPO_ROOT}/.mise/scripts/dev/ci_changes.py" "${ARGS[@]}" +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..41797487e9 --- /dev/null +++ b/CHANGELOG/ci_pr-path-gating.md @@ -0,0 +1,3 @@ +## 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, 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`, `test-db.yml`, `test-interop.yml`, `test-group.yml` and `test_windows.yml`. Code linked into every server-driven suite triggers all of them; any `crate/**` change still runs the whole-workspace jobs. 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. From 384dff0a737fb1dd9c944ddd315edf08573d1624 Mon Sep 17 00:00:00 2001 From: Manuthor Date: Sat, 21 Nov 2026 18:31:15 +0100 Subject: [PATCH 02/14] ci: run PR test groups only on their own crates and scripts - ci-paths.toml: drop server_core from ui, interop:*, pki, pkcs11, obs, hsm, db:*, cloud and the Windows mirrors; add db_core and kmip_wire sets and feature-owned paths - ci_changes.py: update self_test for the narrower gating - CHANGELOG: describe the narrower PR gating --- .github/ci-paths.toml | 79 ++++++++++++++++++--------------- .mise/scripts/dev/ci_changes.py | 27 ++++++++++- CHANGELOG/ci_pr-path-gating.md | 2 +- 3 files changed, 69 insertions(+), 39 deletions(-) diff --git a/.github/ci-paths.toml b/.github/ci-paths.toml index 74c19e799b..7d7d558adf 100644 --- a/.github/ci-paths.toml +++ b/.github/ci-paths.toml @@ -50,8 +50,8 @@ ignore = ''' # 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 every server-driven suite exercises (linked into cosmian_kms or the ckms / test_kms_server harness). -# The negative lookaheads carve out feature-owned paths: those trigger only the units listing them (+ `rust`). +# 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)/ @@ -70,11 +70,15 @@ server_core = ''' pg_store = '^crate/server_database/src/stores/sql/pgsql\.rs$' mysql_store = '^crate/server_database/src/stores/sql/(mysql\.rs|query_mysql\.sql)$' -# Every non-sqlite db leg also runs the lib tests of test_kms_server, ckms, cli_actions, cosmian_pkcs11, -# cosmian_kms_k8s_plugin and cosmian_cng (KMS_SHARED_SERVER_TEST_PACKAGES, .mise/lib/common.sh) + SoftHSM2 KEK tests. +# 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, workflow). db_shared = ''' - ^crate/clients/(pkcs11|cng|k8s)/ -| ^\.mise/tasks/test/db/_default$ + ^\.mise/tasks/test/db/_default$ | ^\.mise/lib/softhsm2\.sh$ | ^\.github/workflows/test-db\.yml$ ''' @@ -119,36 +123,36 @@ sets = ["rust", "db_shared"] files = '^\.mise/tasks/test/db/sqlite$' [units."db:psql"] -sets = ["server_core", "db_shared", "pg_store"] +sets = ["db_core", "db_shared", "pg_store"] files = '^\.mise/tasks/test/db/psql$' [units."db:mysql"] -sets = ["server_core", "db_shared", "mysql_store"] +sets = ["db_core", "db_shared", "mysql_store"] files = '^\.mise/tasks/test/db/mysql$' [units."db:mariadb"] -sets = ["server_core", "db_shared", "mysql_store"] +sets = ["db_core", "db_shared", "mysql_store"] files = '^\.mise/tasks/test/db/mariadb$' [units."db:percona"] -sets = ["server_core", "db_shared", "mysql_store"] +sets = ["db_core", "db_shared", "mysql_store"] files = '^\.mise/tasks/test/db/percona$' [units."db:redis"] -sets = ["server_core", "db_shared"] +sets = ["db_core", "db_shared"] files = '^crate/server_database/src/stores/redis/ | ^\.mise/tasks/test/db/redis$' [units."db:openbao"] -sets = ["server_core", "pg_store", "mysql_store"] +sets = ["db_core", "pg_store", "mysql_store"] files = ''' ^\.mise/tasks/test/db/(_default|openbao)$ | ^\.mise/tasks/test/interop/openbao$ | ^\.mise/scripts/test/openbao/ | ^\.github/workflows/test-db\.yml$ +| ^crate/server/src/routes/kv/ ''' [units.cloud] -sets = ["server_core"] files = ''' ^crate/server/src/(routes/(aws_xks|azure_ekm|google_cse)/|tests/) | ^crate/clients/clap/src/actions/(google|aws|azure)/ @@ -159,7 +163,6 @@ files = ''' ''' [units.hsm] -sets = ["server_core"] files = ''' ^crate/hsm/ | ^crate/clients/pkcs11/ @@ -170,7 +173,6 @@ files = ''' ''' [units.pkcs11] -sets = ["server_core"] files = ''' ^crate/clients/pkcs11/ | ^crate/clients/clap/src/actions/pkcs11/ @@ -179,10 +181,10 @@ files = ''' | ^\.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$ ''' [units.obs] -sets = ["server_core"] files = ''' ^crate/server/src/(core/otel_metrics\.rs$|middlewares/otel_http_middleware\.rs$|tests/) | ^crate/clients/clap/src/actions/audit\.rs$ @@ -194,16 +196,21 @@ files = ''' |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/ ''' [units.pki] -sets = ["server_core"] 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/ ''' [units.spire] @@ -217,7 +224,6 @@ files = ''' ''' [units.ui] -sets = ["server_core"] files = ''' ^ui/ | ^crate/clients/wasm/ @@ -230,23 +236,23 @@ files = ''' ''' [units."interop:ase"] -sets = ["server_core", "interop_shared"] +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/' [units."interop:db2"] -sets = ["server_core", "interop_shared"] +sets = ["kmip_wire", "interop_shared"] files = '^\.mise/tasks/test/interop/db2$ | ^\.mise/scripts/test/test_db2_tde\.sh$' [units."interop:edb-tde"] -sets = ["server_core", "interop_shared"] +sets = ["kmip_wire", "interop_shared"] files = '^\.mise/tasks/test/interop/edb-tde$ | ^\.mise/scripts/test/test_edb_tde\.sh$ | ^\.mise/scripts/(edb_tde|pykmip)/' [units."interop:iris"] -sets = ["server_core", "interop_shared"] +sets = ["kmip_wire", "interop_shared"] files = '^\.mise/tasks/test/interop/iris$ | ^\.mise/scripts/test/test_iris\.sh$' [units."interop:jose"] -sets = ["server_core", "interop_shared"] +sets = ["interop_shared"] files = ''' ^crate/server/src/(routes/(jose/|jwks\.rs$)|tests/) | ^crate/hsm/kryoptic/ @@ -256,7 +262,7 @@ files = ''' ''' [units."interop:kmip-go"] -sets = ["server_core", "interop_shared"] +sets = ["kmip_wire", "interop_shared"] files = ''' ^kmip$ | ^\.mise/tasks/test/interop/kmip-go$ @@ -266,31 +272,32 @@ files = ''' ''' [units."interop:kmipkit"] -sets = ["server_core", "interop_shared"] +sets = ["kmip_wire", "interop_shared"] files = '^\.mise/tasks/test/interop/kmipkit$ | ^\.mise/scripts/kmipkit-fixes\.patch$' [units."interop:openbao"] -sets = ["server_core", "interop_shared"] -files = '^\.mise/tasks/test/interop/openbao$ | ^\.mise/scripts/test/openbao/' +sets = ["interop_shared"] +files = '^\.mise/tasks/test/interop/openbao$ | ^\.mise/scripts/test/openbao/ | ^crate/server/src/routes/kv/' [units."interop:openbao-auth-verifier"] -sets = ["server_core", "interop_shared"] -files = '^authentication$ | ^\.mise/tasks/test/interop/openbao-auth-verifier$ | ^\.mise/lib/spire_test\.sh$ | ^\.mise/scripts/test/openbao/' +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/' [units."interop:openbao-kmip"] -sets = ["server_core", "interop_shared"] +sets = ["kmip_wire", "interop_shared"] files = '^\.mise/tasks/test/interop/openbao-kmip$ | ^\.mise/scripts/test/openbao/' [units."interop:pykmip"] -sets = ["server_core", "interop_shared"] +sets = ["kmip_wire", "interop_shared"] files = '^\.mise/tasks/test/interop/pykmip$ | ^\.mise/scripts/test/test_pykmip\.sh$ | ^\.mise/scripts/pykmip/' [units."interop:ssh-secrets"] -sets = ["server_core", "interop_shared", "pg_store", "mysql_store"] +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)/ ''' # ── test_windows.yml ──────────────────────────────────────────────────────────────────────── @@ -299,15 +306,15 @@ sets = ["rust", "windows"] files = '^\.mise/scripts/windows/cargo_test\.ps1$' [units.windows-ui] -sets = ["server_core", "windows"] +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 = ["server_core", "windows"] +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 = ["server_core", "windows"] +sets = ["windows"] files = ''' ^crate/hsm/ | ^crate/server/src/tests/ @@ -317,5 +324,5 @@ files = ''' ''' [units.windows-est] -sets = ["server_core", "windows"] +sets = ["windows"] files = '^crate/server/src/routes/est/ | ^\.mise/scripts/windows/test_est_windows\.ps1$ | ^\.mise/scripts/kmip-go/go\.mod$' diff --git a/.mise/scripts/dev/ci_changes.py b/.mise/scripts/dev/ci_changes.py index 9b463aefdd..2604a88b7a 100755 --- a/.mise/scripts/dev/ci_changes.py +++ b/.mise/scripts/dev/ci_changes.py @@ -126,8 +126,6 @@ def run(files: list[str]) -> set[str]: assert run(['ui/src/App.tsx']) == {'ui', 'windows-ui'} assert run(['.mise/scripts/test/test_iris.sh']) == {'interop:iris'} for files in ( - ['crate/kmip/src/lib.rs'], - ['crate/server_database/src/stores/sql/query.sql'], ['.mise/lib/common.sh'], ['test_data'], ['brand/new.txt'], @@ -152,6 +150,31 @@ def run(files: list[str]) -> set[str]: utimaco = run(['crate/hsm/utimaco/src/lib.rs']) assert {'hsm', 'windows-hsm-idemia'} <= utimaco assert not {'pkcs11', 'db:psql'} & utimaco + + server_wide = { + 'cargo-clippy', + 'cargo-machete', + 'no-nix', + 'cargo-publish-dry-run', + 'db:sqlite', + 'windows-cargo-test', + 'forward-proxy', + 'xks-remote', + 'spire', + } + assert run(['crate/server/src/core/operations/encrypt.rs']) == server_wide + + kmip = run(['crate/kmip/src/lib.rs']) + assert {'interop:pykmip', 'interop:kmip-go', 'interop:iris'} <= kmip + assert not {'ui', 'db:psql', 'hsm', 'pki', 'interop:jose'} & kmip + + query = run(['crate/server_database/src/stores/sql/query.sql']) + assert {'db:psql', 'db:mysql', 'db:redis', 'db:openbao', 'db:sqlite'} <= query + assert not {'ui', 'hsm', 'interop:iris', 'windows-ui'} & query + + p11 = run(['crate/clients/pkcs11/module/src/pkcs11.rs']) + assert {'pkcs11', 'hsm', 'interop:ase', 'windows-cng-ksp'} <= p11 + assert not {'db:psql', 'ui'} & p11 print('self-test OK') diff --git a/CHANGELOG/ci_pr-path-gating.md b/CHANGELOG/ci_pr-path-gating.md index 41797487e9..6231a06c01 100644 --- a/CHANGELOG/ci_pr-path-gating.md +++ b/CHANGELOG/ci_pr-path-gating.md @@ -1,3 +1,3 @@ ## 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, 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`, `test-db.yml`, `test-interop.yml`, `test-group.yml` and `test_windows.yml`. Code linked into every server-driven suite triggers all of them; any `crate/**` change still runs the whole-workspace jobs. 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. +- 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, 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`, `test-db.yml`, `test-interop.yml`, `test-group.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. 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. From 7e41bacd9485cd25f290124f14c2cb57aa6f6002 Mon Sep 17 00:00:00 2001 From: Manuthor Date: Sat, 21 Nov 2026 18:49:15 +0100 Subject: [PATCH 03/14] ci: gate workflow-only PRs on their direct units - ci-paths.toml: drop workflow, ci-paths.toml and ci_changes.py from `full`; each reusable workflow triggers its direct units plus one representative leg - ci_changes.py: self-test a workflow-only change set (9 units instead of 37) --- .github/ci-paths.toml | 33 +++++++++++++++------------------ .mise/scripts/dev/ci_changes.py | 24 ++++++++++++++++++++++++ CHANGELOG/ci_pr-path-gating.md | 2 +- 3 files changed, 40 insertions(+), 19 deletions(-) diff --git a/.github/ci-paths.toml b/.github/ci-paths.toml index 7d7d558adf..f6093da23a 100644 --- a/.github/ci-paths.toml +++ b/.github/ci-paths.toml @@ -10,11 +10,7 @@ # Tags, schedule and workflow_dispatch ignore this file and run everything. full = ''' - ^\.github/workflows/(main|test_all|test-group)\.yml$ -| ^\.github/actions/(install-mise|install-rust|setup-nix|setup-nix-mise|cache-openssl-buildrs|cleanup-runner)/ -| ^\.github/ci-paths\.toml$ -| ^\.mise/tasks/dev/ci-changes$ -| ^\.mise/scripts/dev/ci_changes\.py$ + ^\.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)$ @@ -43,6 +39,7 @@ ignore = ''' | ^\.mise/tasks/test/(k8s|pkg)/ | ^\.mise/lib/(k8s|package_build|package_smoke|bench_helpers)\.sh$ | ^\.mise/scripts/(audit|bench|demo|dev|docs|git|package|pre-commit|release|sbom)/ +| ^\.github/ci-paths\.toml$ # validated by the `--self-test` run of the `changes` job ''' [sets] @@ -76,18 +73,16 @@ db_core = '^crate/server_database/(?!src/stores/(sql/(pgsql\.rs|mysql\.rs|query_ # 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, workflow). +# Shared plumbing of every non-sqlite db leg (task, SoftHSM2 KEK helper). db_shared = ''' ^\.mise/tasks/test/db/_default$ | ^\.mise/lib/softhsm2\.sh$ -| ^\.github/workflows/test-db\.yml$ ''' -interop_shared = '^\.mise/tasks/test/interop/_default$ | ^\.github/workflows/test-interop\.yml$' +interop_shared = '^\.mise/tasks/test/interop/_default$' windows = ''' ^vcpkg(_fips)?\.json$ -| ^\.github/workflows/test_windows\.yml$ | ^\.github/actions/(build-static-openssl|windows-vs-ninja)/ | ^\.mise/scripts/windows/(common|install_ninja)\.ps1$ ''' @@ -95,32 +90,35 @@ windows = ''' # ── main.yml ──────────────────────────────────────────────────────────────────────────────── [units.cargo-clippy] sets = ["rust"] -files = '^clippy\.toml$' +files = '^clippy\.toml$ | ^\.github/workflows/main\.yml$' [units.cargo-machete] sets = ["rust"] +files = '^\.github/workflows/main\.yml$' [units.no-nix] sets = ["rust"] -files = '^\.github/workflows/no-nix\.yml$' +files = '^\.github/workflows/(main|no-nix)\.yml$' [units.forward-proxy] sets = ["server_core"] -files = '^\.github/workflows/forward_proxy\.yml$ | ^\.github/scripts/squid/' +files = '^\.github/workflows/(main|forward_proxy)\.yml$ | ^\.github/scripts/squid/' # ── test_all.yml (non test-group jobs) ────────────────────────────────────────────────────── [units.cargo-publish-dry-run] sets = ["rust"] -files = '^\.github/workflows/cargo-publish\.yml$' +files = '^\.github/workflows/(test_all|cargo-publish)\.yml$' [units.xks-remote] sets = ["server_core"] -files = '^crate/server/src/routes/aws_xks/ | ^\.mise/scripts/test/(deploy_xks_remote|test_xks_remote|test_xks_aws_e2e)\.sh$' +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$' +# The reusable workflows are exercised by one representative leg: main -> test_all -> test-group, and test-db. +# shortcut: a leg stands for its whole workflow; add the file to `full` if a wiring change must prove every suite. +files = '^\.mise/tasks/test/db/sqlite$ | ^\.github/workflows/(main|test_all|test-group|test-db)\.yml$' [units."db:psql"] sets = ["db_core", "db_shared", "pg_store"] @@ -148,7 +146,6 @@ files = ''' ^\.mise/tasks/test/db/(_default|openbao)$ | ^\.mise/tasks/test/interop/openbao$ | ^\.mise/scripts/test/openbao/ -| ^\.github/workflows/test-db\.yml$ | ^crate/server/src/routes/kv/ ''' @@ -289,7 +286,7 @@ files = '^\.mise/tasks/test/interop/openbao-kmip$ | ^\.mise/scripts/test/openbao [units."interop:pykmip"] sets = ["kmip_wire", "interop_shared"] -files = '^\.mise/tasks/test/interop/pykmip$ | ^\.mise/scripts/test/test_pykmip\.sh$ | ^\.mise/scripts/pykmip/' +files = '^\.mise/tasks/test/interop/pykmip$ | ^\.mise/scripts/test/test_pykmip\.sh$ | ^\.mise/scripts/pykmip/ | ^\.github/workflows/test-interop\.yml$' [units."interop:ssh-secrets"] sets = ["interop_shared", "pg_store", "mysql_store"] @@ -303,7 +300,7 @@ files = ''' # ── test_windows.yml ──────────────────────────────────────────────────────────────────────── [units.windows-cargo-test] sets = ["rust", "windows"] -files = '^\.mise/scripts/windows/cargo_test\.ps1$' +files = '^\.mise/scripts/windows/cargo_test\.ps1$ | ^\.github/workflows/test_windows\.yml$' [units.windows-ui] sets = ["windows"] diff --git a/.mise/scripts/dev/ci_changes.py b/.mise/scripts/dev/ci_changes.py index 2604a88b7a..450a043a1e 100755 --- a/.mise/scripts/dev/ci_changes.py +++ b/.mise/scripts/dev/ci_changes.py @@ -175,6 +175,30 @@ def run(files: list[str]) -> set[str]: p11 = run(['crate/clients/pkcs11/module/src/pkcs11.rs']) assert {'pkcs11', 'hsm', 'interop:ase', 'windows-cng-ksp'} <= p11 assert not {'db:psql', 'ui'} & p11 + + workflows = run( + [ + '.github/ci-paths.toml', + '.github/workflows/main.yml', + '.github/workflows/test_all.yml', + '.github/workflows/test-group.yml', + '.github/workflows/test-db.yml', + '.github/workflows/test-interop.yml', + '.github/workflows/test_windows.yml', + '.mise/scripts/dev/ci_changes.py', + ] + ) + assert workflows == { + 'cargo-clippy', + 'cargo-machete', + 'no-nix', + 'forward-proxy', + 'cargo-publish-dry-run', + 'xks-remote', + 'db:sqlite', + 'interop:pykmip', + 'windows-cargo-test', + } print('self-test OK') diff --git a/CHANGELOG/ci_pr-path-gating.md b/CHANGELOG/ci_pr-path-gating.md index 6231a06c01..f645fec406 100644 --- a/CHANGELOG/ci_pr-path-gating.md +++ b/CHANGELOG/ci_pr-path-gating.md @@ -1,3 +1,3 @@ ## 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, 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`, `test-db.yml`, `test-interop.yml`, `test-group.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. 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. +- 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, 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`, `test-db.yml`, `test-interop.yml`, `test-group.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. A change to a reusable workflow (`main.yml`, `test_all.yml`, `test-group.yml`, `test-db.yml`, `test-interop.yml`, `test_windows.yml`) runs only the units that call it directly plus one representative suite leg, not every suite; `ci-paths.toml` and `ci_changes.py` are validated by the self-test of the `changes` job. 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. From 1cecbe9940f385c1e2c1907d8562ad898699f122 Mon Sep 17 00:00:00 2001 From: Manuthor Date: Sat, 21 Nov 2026 18:52:22 +0100 Subject: [PATCH 04/14] test: unit-test the CI changed-area classifier - test_ci_changes.py: 43 scenarios (docs, ui, rust core, db backends, feature crates, workflows, fail-safes) on the real ci-paths.toml - dev:ci-changes --self-test also runs them, so the `changes` job gates on them --- .mise/scripts/dev/test_ci_changes.py | 328 +++++++++++++++++++++++++++ .mise/tasks/dev/ci-changes | 3 + 2 files changed, 331 insertions(+) create mode 100755 .mise/scripts/dev/test_ci_changes.py diff --git a/.mise/scripts/dev/test_ci_changes.py b/.mise/scripts/dev/test_ci_changes.py new file mode 100755 index 0000000000..e19390f90b --- /dev/null +++ b/.mise/scripts/dev/test_ci_changes.py @@ -0,0 +1,328 @@ +#!/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 sys +import unittest +from pathlib import Path + +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 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_docs_only_runs_nothing(self) -> None: + self.assertEqual( + run( + 'documentation/docs/index.md', + 'CHANGELOG/x.md', + 'README.md', + '.github/skills/foo/SKILL.md', + ), + set(), + ) + + 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_one_leg_per_workflow(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-db.yml', + '.github/workflows/test-interop.yml', + '.github/workflows/test_windows.yml', + '.mise/scripts/dev/ci_changes.py', + ), + { + 'cargo-clippy', + 'cargo-machete', + 'no-nix', + 'forward-proxy', + 'cargo-publish-dry-run', + 'xks-remote', + 'db:sqlite', + 'interop:pykmip', + 'windows-cargo-test', + }, + ) + + 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'}) + + +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'} + ) + + 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'}, + ) + + +class ConfigIntegrity(unittest.TestCase): + def test_every_unit_is_reachable(self) -> None: + # A unit no changed file can trigger would silently never run on PRs. + samples = { + 'cargo-clippy': 'clippy.toml', + 'ui': 'ui/src/App.tsx', + 'db:psql': 'crate/server_database/src/stores/sql/pgsql.rs', + 'interop:jose': 'crate/server/src/routes/jose/mod.rs', + 'windows-est': 'crate/server/src/routes/est/mod.rs', + } + for unit, path in samples.items(): + with self.subTest(unit=unit): + self.assertIn(unit, run(path)) + + 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'}) + + +if __name__ == '__main__': + unittest.main() diff --git a/.mise/tasks/dev/ci-changes b/.mise/tasks/dev/ci-changes index c4998b0eef..4b4101f4c1 100755 --- a/.mise/tasks/dev/ci-changes +++ b/.mise/tasks/dev/ci-changes @@ -13,4 +13,7 @@ ARGS=(--base "${usage_base:-HEAD^1}" --head "${usage_head:-HEAD}") print_header "CI changed-area classification" "${PYTHON}" "${REPO_ROOT}/.mise/scripts/dev/ci_changes.py" "${ARGS[@]}" +if [ "${usage_self_test:-false}" = "true" ]; then + "${PYTHON}" -m unittest discover -s "${REPO_ROOT}/.mise/scripts/dev" -p 'test_ci_changes.py' +fi print_success "Classification complete" From c3683399b1bb7852a788a55b8e487aa7b5f9eab6 Mon Sep 17 00:00:00 2001 From: Manuthor Date: Sat, 21 Nov 2026 18:53:39 +0100 Subject: [PATCH 05/14] test: cover every CI unit and the classifier fail-safes - test_ci_changes.py: one triggering sample per unit (asserts full unit coverage and that no sample hits full) - test_ci_changes.py: classify()/load_config() on an inline TOML (empty diff, full, orphan, ignore, lookahead, invalid config) - ci_changes.py: drop self_test(), now fully covered by the unit tests; --self-test only runs them via the task --- .mise/scripts/dev/ci_changes.py | 94 +---------------- .mise/scripts/dev/test_ci_changes.py | 150 +++++++++++++++++++++++++-- .mise/tasks/dev/ci-changes | 8 +- 3 files changed, 143 insertions(+), 109 deletions(-) diff --git a/.mise/scripts/dev/ci_changes.py b/.mise/scripts/dev/ci_changes.py index 450a043a1e..249975cebd 100755 --- a/.mise/scripts/dev/ci_changes.py +++ b/.mise/scripts/dev/ci_changes.py @@ -3,7 +3,7 @@ """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 `skip=` - ci_changes.py --self-test assert the real config on representative change sets + test_ci_changes.py unit tests of this module on the real config (`mise run dev:ci-changes --self-test`) The output line `skip=[...]` is appended to $GITHUB_OUTPUT when set (and always printed) so workflow jobs can gate themselves with `!contains(fromJSON(...), '')`. Fail-safe: an empty diff, a file matching `full`, or a @@ -114,103 +114,11 @@ def classify(cfg: Config, files: list[str]) -> tuple[list[str], str]: ) -def self_test() -> None: - cfg = load_config(CONFIG) - everything = set(cfg.units) - - def run(files: list[str]) -> set[str]: - return everything - set(classify(cfg, files)[0]) - - assert classify(cfg, [])[0] == [] - assert run(['documentation/docs/index.md', 'CHANGELOG/x.md']) == set() - assert run(['ui/src/App.tsx']) == {'ui', 'windows-ui'} - assert run(['.mise/scripts/test/test_iris.sh']) == {'interop:iris'} - for files in ( - ['.mise/lib/common.sh'], - ['test_data'], - ['brand/new.txt'], - ): - assert run(files) == everything, files - - xks = run(['crate/server/src/routes/aws_xks/mod.rs']) - assert { - 'cloud', - 'xks-remote', - 'db:sqlite', - 'no-nix', - 'cargo-clippy', - 'windows-cargo-test', - } <= xks - assert not {'db:psql', 'hsm', 'ui'} & xks - - pg = run(['crate/server_database/src/stores/sql/pgsql.rs']) - assert {'db:psql', 'db:openbao', 'interop:ssh-secrets', 'db:sqlite'} <= pg - assert not {'db:mysql', 'interop:ase'} & pg - - utimaco = run(['crate/hsm/utimaco/src/lib.rs']) - assert {'hsm', 'windows-hsm-idemia'} <= utimaco - assert not {'pkcs11', 'db:psql'} & utimaco - - server_wide = { - 'cargo-clippy', - 'cargo-machete', - 'no-nix', - 'cargo-publish-dry-run', - 'db:sqlite', - 'windows-cargo-test', - 'forward-proxy', - 'xks-remote', - 'spire', - } - assert run(['crate/server/src/core/operations/encrypt.rs']) == server_wide - - kmip = run(['crate/kmip/src/lib.rs']) - assert {'interop:pykmip', 'interop:kmip-go', 'interop:iris'} <= kmip - assert not {'ui', 'db:psql', 'hsm', 'pki', 'interop:jose'} & kmip - - query = run(['crate/server_database/src/stores/sql/query.sql']) - assert {'db:psql', 'db:mysql', 'db:redis', 'db:openbao', 'db:sqlite'} <= query - assert not {'ui', 'hsm', 'interop:iris', 'windows-ui'} & query - - p11 = run(['crate/clients/pkcs11/module/src/pkcs11.rs']) - assert {'pkcs11', 'hsm', 'interop:ase', 'windows-cng-ksp'} <= p11 - assert not {'db:psql', 'ui'} & p11 - - workflows = run( - [ - '.github/ci-paths.toml', - '.github/workflows/main.yml', - '.github/workflows/test_all.yml', - '.github/workflows/test-group.yml', - '.github/workflows/test-db.yml', - '.github/workflows/test-interop.yml', - '.github/workflows/test_windows.yml', - '.mise/scripts/dev/ci_changes.py', - ] - ) - assert workflows == { - 'cargo-clippy', - 'cargo-machete', - 'no-nix', - 'forward-proxy', - 'cargo-publish-dry-run', - 'xks-remote', - 'db:sqlite', - 'interop:pykmip', - 'windows-cargo-test', - } - print('self-test OK') - - 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('--self-test', action='store_true') args = parser.parse_args() - if args.self_test: - self_test() - return cfg = load_config(CONFIG) files = changed_files(args.base, args.head) diff --git a/.mise/scripts/dev/test_ci_changes.py b/.mise/scripts/dev/test_ci_changes.py index e19390f90b..3b2121d806 100755 --- a/.mise/scripts/dev/test_ci_changes.py +++ b/.mise/scripts/dev/test_ci_changes.py @@ -8,6 +8,10 @@ from __future__ import annotations +import contextlib +import io +import tempfile +import textwrap import sys import unittest from pathlib import Path @@ -304,19 +308,59 @@ def test_core_plus_ui_is_server_wide_plus_ui(self) -> None: ) +# One file per unit that triggers it (and not by way of `full`). +UNIT_SAMPLES = { + 'cargo-clippy': 'clippy.toml', + 'cargo-machete': 'crate/server/src/lib.rs', + 'no-nix': '.github/workflows/no-nix.yml', + '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': '.mise/scripts/windows/cargo_test.ps1', + '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_every_unit_is_reachable(self) -> None: - # A unit no changed file can trigger would silently never run on PRs. - samples = { - 'cargo-clippy': 'clippy.toml', - 'ui': 'ui/src/App.tsx', - 'db:psql': 'crate/server_database/src/stores/sql/pgsql.rs', - 'interop:jose': 'crate/server/src/routes/jose/mod.rs', - 'windows-est': 'crate/server/src/routes/est/mod.rs', - } - for unit, path in samples.items(): + 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): - self.assertIn(unit, run(path)) + 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']) @@ -324,5 +368,89 @@ def test_classify_reports_skipped_units_sorted_and_disjoint_from_run(self) -> No 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") + + if __name__ == '__main__': unittest.main() diff --git a/.mise/tasks/dev/ci-changes b/.mise/tasks/dev/ci-changes index 4b4101f4c1..9a83606594 100755 --- a/.mise/tasks/dev/ci-changes +++ b/.mise/tasks/dev/ci-changes @@ -2,18 +2,16 @@ #MISE description="Classify the files a PR changes with .github/ci-paths.toml: prints and appends skip= 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 "--self-test" help="Run the built-in asserts against .github/ci-paths.toml and exit" +#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)" -ARGS=(--base "${usage_base:-HEAD^1}" --head "${usage_head:-HEAD}") -[ "${usage_self_test:-false}" = "true" ] && ARGS+=(--self-test) - print_header "CI changed-area classification" -"${PYTHON}" "${REPO_ROOT}/.mise/scripts/dev/ci_changes.py" "${ARGS[@]}" if [ "${usage_self_test:-false}" = "true" ]; then "${PYTHON}" -m unittest discover -s "${REPO_ROOT}/.mise/scripts/dev" -p 'test_ci_changes.py' +else + "${PYTHON}" "${REPO_ROOT}/.mise/scripts/dev/ci_changes.py" --base "${usage_base:-HEAD^1}" --head "${usage_head:-HEAD}" fi print_success "Classification complete" From 33aede2ec867745f5b91262dfc92b66c5314361d Mon Sep 17 00:00:00 2001 From: Manuthor Date: Sat, 21 Nov 2026 19:34:22 +0100 Subject: [PATCH 06/14] ci: never run db:sqlite for workflow-only changes - ci-paths.toml: db:sqlite triggers only on its task script and the workspace set, not on workflow files - test-db.yml and test-group.yml are ignored wrappers; main.yml and test_all.yml keep their direct units - test_ci_changes.py: workflow-only set is 8 units; wrappers alone run nothing --- .github/ci-paths.toml | 5 ++--- .mise/scripts/dev/test_ci_changes.py | 9 +++++++-- CHANGELOG/ci_pr-path-gating.md | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/ci-paths.toml b/.github/ci-paths.toml index f6093da23a..f5228a5b52 100644 --- a/.github/ci-paths.toml +++ b/.github/ci-paths.toml @@ -40,6 +40,7 @@ ignore = ''' | ^\.mise/lib/(k8s|package_build|package_smoke|bench_helpers)\.sh$ | ^\.mise/scripts/(audit|bench|demo|dev|docs|git|package|pre-commit|release|sbom)/ | ^\.github/ci-paths\.toml$ # validated by the `--self-test` run of the `changes` job +| ^\.github/workflows/(test-db|test-group)\.yml$ # reusable wrappers: no suite leg stands for them, any run of another suite exercises them ''' [sets] @@ -116,9 +117,7 @@ files = '^crate/server/src/routes/aws_xks/ | ^\.github/workflows/test_all\.yml$ # ── test-group.yml suites (key = `suite` input; `pki` also gates the macOS job interop-macos) ── [units."db:sqlite"] sets = ["rust", "db_shared"] -# The reusable workflows are exercised by one representative leg: main -> test_all -> test-group, and test-db. -# shortcut: a leg stands for its whole workflow; add the file to `full` if a wiring change must prove every suite. -files = '^\.mise/tasks/test/db/sqlite$ | ^\.github/workflows/(main|test_all|test-group|test-db)\.yml$' +files = '^\.mise/tasks/test/db/sqlite$' [units."db:psql"] sets = ["db_core", "db_shared", "pg_store"] diff --git a/.mise/scripts/dev/test_ci_changes.py b/.mise/scripts/dev/test_ci_changes.py index 3b2121d806..5ca7636c73 100755 --- a/.mise/scripts/dev/test_ci_changes.py +++ b/.mise/scripts/dev/test_ci_changes.py @@ -229,7 +229,7 @@ def test_hsm_task_script(self) -> None: class CiWorkflows(unittest.TestCase): - def test_workflow_only_pr_runs_one_leg_per_workflow(self) -> None: + def test_workflow_only_pr_runs_direct_units_and_never_db_sqlite(self) -> None: self.assertEqual( run( '.github/ci-paths.toml', @@ -248,7 +248,6 @@ def test_workflow_only_pr_runs_one_leg_per_workflow(self) -> None: 'forward-proxy', 'cargo-publish-dry-run', 'xks-remote', - 'db:sqlite', 'interop:pykmip', 'windows-cargo-test', }, @@ -260,6 +259,12 @@ def test_classifier_config_change_runs_nothing(self) -> None: def test_forward_proxy_workflow(self) -> None: self.assertEqual(run('.github/workflows/forward_proxy.yml'), {'forward-proxy'}) + def test_db_and_group_wrappers_run_nothing(self) -> None: + self.assertEqual( + run('.github/workflows/test-db.yml', '.github/workflows/test-group.yml'), + set(), + ) + class FailSafe(unittest.TestCase): def test_empty_diff_runs_everything(self) -> None: diff --git a/CHANGELOG/ci_pr-path-gating.md b/CHANGELOG/ci_pr-path-gating.md index f645fec406..e281441c6c 100644 --- a/CHANGELOG/ci_pr-path-gating.md +++ b/CHANGELOG/ci_pr-path-gating.md @@ -1,3 +1,3 @@ ## 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, 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`, `test-db.yml`, `test-interop.yml`, `test-group.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. A change to a reusable workflow (`main.yml`, `test_all.yml`, `test-group.yml`, `test-db.yml`, `test-interop.yml`, `test_windows.yml`) runs only the units that call it directly plus one representative suite leg, not every suite; `ci-paths.toml` and `ci_changes.py` are validated by the self-test of the `changes` job. 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. +- 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, 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`, `test-db.yml`, `test-interop.yml`, `test-group.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. A change to `main.yml`, `test_all.yml`, `test-interop.yml` or `test_windows.yml` runs only the units defined in or called directly by it (`test-interop.yml` and `test_windows.yml` through `interop:pykmip` and `windows-cargo-test`); `test-db.yml`, `test-group.yml`, `ci-paths.toml` and `ci_changes.py` run no suite, the last two being covered by the unit tests the `changes` job runs. 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. From a4033fce38465e3ab6f00c98ca351a3d1950183f Mon Sep 17 00:00:00 2001 From: Manuthor Date: Sat, 21 Nov 2026 20:25:51 +0100 Subject: [PATCH 07/14] ci: run no-nix and Windows cargo test only on Rust source changes - ci-paths.toml: drop main.yml, no-nix.yml and test_windows.yml from the no-nix and windows-cargo-test triggers; the two workflow files are ignored - test_ci_changes.py: workflow-only set is 6 units; assert xks-remote triggers on XKS-related Rust sources --- .github/ci-paths.toml | 4 +-- .mise/scripts/dev/test_ci_changes.py | 37 +++++++++++++++++++++++++--- CHANGELOG/ci_pr-path-gating.md | 2 +- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/.github/ci-paths.toml b/.github/ci-paths.toml index f5228a5b52..8a69014bbe 100644 --- a/.github/ci-paths.toml +++ b/.github/ci-paths.toml @@ -41,6 +41,7 @@ ignore = ''' | ^\.mise/scripts/(audit|bench|demo|dev|docs|git|package|pre-commit|release|sbom)/ | ^\.github/ci-paths\.toml$ # validated by the `--self-test` run of the `changes` job | ^\.github/workflows/(test-db|test-group)\.yml$ # reusable wrappers: no suite leg stands for them, any run of another suite exercises them +| ^\.github/workflows/(no-nix|test_windows)\.yml$ # Rust-only jobs: they run on crate changes, not on their own workflow files ''' [sets] @@ -99,7 +100,6 @@ files = '^\.github/workflows/main\.yml$' [units.no-nix] sets = ["rust"] -files = '^\.github/workflows/(main|no-nix)\.yml$' [units.forward-proxy] sets = ["server_core"] @@ -299,7 +299,7 @@ files = ''' # ── test_windows.yml ──────────────────────────────────────────────────────────────────────── [units.windows-cargo-test] sets = ["rust", "windows"] -files = '^\.mise/scripts/windows/cargo_test\.ps1$ | ^\.github/workflows/test_windows\.yml$' +files = '^\.mise/scripts/windows/cargo_test\.ps1$' [units.windows-ui] sets = ["windows"] diff --git a/.mise/scripts/dev/test_ci_changes.py b/.mise/scripts/dev/test_ci_changes.py index 5ca7636c73..77cc212ece 100755 --- a/.mise/scripts/dev/test_ci_changes.py +++ b/.mise/scripts/dev/test_ci_changes.py @@ -244,12 +244,10 @@ def test_workflow_only_pr_runs_direct_units_and_never_db_sqlite(self) -> None: { 'cargo-clippy', 'cargo-machete', - 'no-nix', 'forward-proxy', 'cargo-publish-dry-run', 'xks-remote', 'interop:pykmip', - 'windows-cargo-test', }, ) @@ -259,6 +257,39 @@ def test_classifier_config_change_runs_nothing(self) -> None: 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', + '.github/workflows/test-interop.yml', + '.mise/tasks/test/db/psql', + '.mise/tasks/test/interop/pykmip', + 'ui/src/App.tsx', + 'documentation/docs/index.md', + ): + 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_db_and_group_wrappers_run_nothing(self) -> None: self.assertEqual( run('.github/workflows/test-db.yml', '.github/workflows/test-group.yml'), @@ -317,7 +348,7 @@ def test_core_plus_ui_is_server_wide_plus_ui(self) -> None: UNIT_SAMPLES = { 'cargo-clippy': 'clippy.toml', 'cargo-machete': 'crate/server/src/lib.rs', - 'no-nix': '.github/workflows/no-nix.yml', + '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', diff --git a/CHANGELOG/ci_pr-path-gating.md b/CHANGELOG/ci_pr-path-gating.md index e281441c6c..ebe81c23fa 100644 --- a/CHANGELOG/ci_pr-path-gating.md +++ b/CHANGELOG/ci_pr-path-gating.md @@ -1,3 +1,3 @@ ## 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, 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`, `test-db.yml`, `test-interop.yml`, `test-group.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. A change to `main.yml`, `test_all.yml`, `test-interop.yml` or `test_windows.yml` runs only the units defined in or called directly by it (`test-interop.yml` and `test_windows.yml` through `interop:pykmip` and `windows-cargo-test`); `test-db.yml`, `test-group.yml`, `ci-paths.toml` and `ci_changes.py` run no suite, the last two being covered by the unit tests the `changes` job runs. 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. +- 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, 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`, `test-db.yml`, `test-interop.yml`, `test-group.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. A change to `main.yml` or `test_all.yml` runs only the units defined in or called directly by it, and one to `test-interop.yml` runs `interop:pykmip`; `no-nix.yml`, `test_windows.yml`, `test-db.yml`, `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. From 4da430a0d52b79b94f7576793292bcb9d510ea4e Mon Sep 17 00:00:00 2001 From: Manuthor Date: Sat, 21 Nov 2026 20:26:34 +0100 Subject: [PATCH 08/14] ci: windows-cargo-test triggers only on Rust source - ci-paths.toml: drop the windows toolchain set and cargo_test.ps1 from windows-cargo-test (ps1 now ignored); other windows-* units keep their feature triggers - test_ci_changes.py: vcpkg, windows actions and the ps1 scripts never trigger no-nix or windows-cargo-test --- .github/ci-paths.toml | 4 ++-- .mise/scripts/dev/test_ci_changes.py | 6 +++++- CHANGELOG/ci_pr-path-gating.md | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/ci-paths.toml b/.github/ci-paths.toml index 8a69014bbe..7b78d799bc 100644 --- a/.github/ci-paths.toml +++ b/.github/ci-paths.toml @@ -42,6 +42,7 @@ ignore = ''' | ^\.github/ci-paths\.toml$ # validated by the `--self-test` run of the `changes` job | ^\.github/workflows/(test-db|test-group)\.yml$ # reusable wrappers: no suite leg stands for them, any run of another suite exercises them | ^\.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] @@ -298,8 +299,7 @@ files = ''' # ── test_windows.yml ──────────────────────────────────────────────────────────────────────── [units.windows-cargo-test] -sets = ["rust", "windows"] -files = '^\.mise/scripts/windows/cargo_test\.ps1$' +sets = ["rust"] [units.windows-ui] sets = ["windows"] diff --git a/.mise/scripts/dev/test_ci_changes.py b/.mise/scripts/dev/test_ci_changes.py index 77cc212ece..ca8b5e8fd7 100755 --- a/.mise/scripts/dev/test_ci_changes.py +++ b/.mise/scripts/dev/test_ci_changes.py @@ -272,6 +272,10 @@ def test_no_nix_and_windows_cargo_test_need_rust_source(self) -> None: '.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'}) @@ -378,7 +382,7 @@ def test_core_plus_ui_is_server_wide_plus_ui(self) -> None: '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': '.mise/scripts/windows/cargo_test.ps1', + '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', diff --git a/CHANGELOG/ci_pr-path-gating.md b/CHANGELOG/ci_pr-path-gating.md index ebe81c23fa..33178b4163 100644 --- a/CHANGELOG/ci_pr-path-gating.md +++ b/CHANGELOG/ci_pr-path-gating.md @@ -1,3 +1,3 @@ ## 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, 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`, `test-db.yml`, `test-interop.yml`, `test-group.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. A change to `main.yml` or `test_all.yml` runs only the units defined in or called directly by it, and one to `test-interop.yml` runs `interop:pykmip`; `no-nix.yml`, `test_windows.yml`, `test-db.yml`, `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. +- 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, 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`, `test-db.yml`, `test-interop.yml`, `test-group.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. A change to `main.yml` or `test_all.yml` runs only the units defined in or called directly by it, and one to `test-interop.yml` runs `interop:pykmip`; `no-nix.yml`, `test_windows.yml`, `cargo_test.ps1`, `test-db.yml`, `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. From 1762956873649f8b2c6e424e39100e205ff3ced5 Mon Sep 17 00:00:00 2001 From: Manuthor Date: Sat, 21 Nov 2026 20:29:58 +0100 Subject: [PATCH 09/14] test: cover git diffing, main() output and error paths of ci_changes - ChangedFiles: temp git repo (modify/add/delete, renames, merge-base, merge-commit HEAD^1, unknown ref) - Main: report, compact skip= JSON, $GITHUB_OUTPUT append, fail-safe reasons, default and forwarded refs - CommandLine and LoadConfig error messages; 84 tests, every statement of ci_changes.py executed --- .mise/scripts/dev/test_ci_changes.py | 235 ++++++++++++++++++++++++++- 1 file changed, 234 insertions(+), 1 deletion(-) diff --git a/.mise/scripts/dev/test_ci_changes.py b/.mise/scripts/dev/test_ci_changes.py index ca8b5e8fd7..8fa8e1a501 100755 --- a/.mise/scripts/dev/test_ci_changes.py +++ b/.mise/scripts/dev/test_ci_changes.py @@ -10,11 +10,15 @@ import contextlib import io +import json +import os +import subprocess +import sys import tempfile import textwrap -import sys import unittest from pathlib import Path +from unittest import mock sys.path.insert(0, str(Path(__file__).parent)) import ci_changes # noqa: E402 @@ -491,6 +495,235 @@ def test_missing_full_is_rejected(self) -> None: 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 git(repo: Path, *args: str) -> str: + return subprocess.run( + [ + 'git', + '-c', + 'user.name=t', + '-c', + 'user.email=t@t', + '-c', + 'commit.gpgsign=false', + *args, + ], + cwd=repo, + 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:-1]} + 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_skip_line_is_compact_sorted_json_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(len(written), 1) + self.assertEqual(written[0], text.splitlines()[-1]) + self.assertTrue(written[0].startswith('skip=[')) + 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()[-1].startswith('skip=[')) + self.assertFalse(self.output.exists()) + + 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.assertEqual(self.output.read_text(), 'skip=[]\n') + 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.assertEqual(self.output.read_text(), 'skip=[]\n') + + 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.assertEqual(self.output.read_text(), 'skip=[]\n') + + def test_docs_only_skips_every_unit(self) -> None: + text, _ = self.run_main(['README.md'], output=self.output) + self.assertEqual( + json.loads(self.output.read_text().removeprefix('skip=')), + sorted(EVERYTHING), + ) + 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, + capture_output=True, + text=True, + check=True, + ) + self.assertIn('empty diff: run everything', done.stdout) + self.assertEqual(done.stdout.splitlines()[-1], 'skip=[]') + + def test_unknown_flag_is_rejected(self) -> None: + script = Path(ci_changes.__file__) + done = subprocess.run( + [sys.executable, str(script), '--nope'], capture_output=True, text=True + ) + self.assertEqual(done.returncode, 2) + if __name__ == '__main__': unittest.main() From 410da084b9a900d14f1c713d0d2d4e2be83e6251 Mon Sep 17 00:00:00 2001 From: Manuthor Date: Sat, 21 Nov 2026 20:30:49 +0100 Subject: [PATCH 10/14] test: isolate ci_changes tests from git config and GITHUB_OUTPUT - temp-repo git runs with no global/system config and a fixed identity (no signing, hooks or missing-identity failure on runners) - the subprocess runs drop GITHUB_OUTPUT so the self-test cannot add a stray skip= line to the changes step output --- .mise/scripts/dev/test_ci_changes.py | 31 ++++++++++++++++++---------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/.mise/scripts/dev/test_ci_changes.py b/.mise/scripts/dev/test_ci_changes.py index 8fa8e1a501..6f8dad2aa8 100755 --- a/.mise/scripts/dev/test_ci_changes.py +++ b/.mise/scripts/dev/test_ci_changes.py @@ -520,19 +520,24 @@ def test_set_may_be_used_by_several_units_and_units_keep_file_order(self) -> Non self.assertEqual(len(cfg.units['c']), 2) # set + files +# 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', - 'user.name=t', - '-c', - 'user.email=t@t', - '-c', - 'commit.gpgsign=false', - *args, - ], + ['git', '-c', 'commit.gpgsign=false', *args], cwd=repo, + env=GIT_ENV, check=True, capture_output=True, text=True, @@ -710,6 +715,7 @@ def test_script_runs_as_a_program(self) -> None: 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, @@ -720,7 +726,10 @@ def test_script_runs_as_a_program(self) -> None: def test_unknown_flag_is_rejected(self) -> None: script = Path(ci_changes.__file__) done = subprocess.run( - [sys.executable, str(script), '--nope'], capture_output=True, text=True + [sys.executable, str(script), '--nope'], + env=GIT_ENV, + capture_output=True, + text=True, ) self.assertEqual(done.returncode, 2) From 77eff848f2683492be2013e2ae24351564484e47 Mon Sep 17 00:00:00 2001 From: Manuthor Date: Sat, 21 Nov 2026 20:41:20 +0100 Subject: [PATCH 11/14] ci: drop gated jobs from the PR run graph instead of skipping them - ci_changes.py emits db-matrix, interop-matrix, run-test and run-windows next to skip; --all for non-PR events - ci-paths.toml: `variants` per db:*/interop:* unit and a [callers] table - test-db.yml / test-interop.yml build their matrix from the emitted legs; test_all.yml gates suites itself - main.yml skips the whole test / windows call when none of its units runs --- .github/ci-paths.toml | 29 ++++ .github/workflows/main.yml | 19 ++- .github/workflows/test-db.yml | 25 +--- .github/workflows/test-group.yml | 6 - .github/workflows/test-interop.yml | 27 +--- .github/workflows/test_all.yml | 32 +++-- .mise/scripts/dev/ci_changes.py | 86 ++++++++++-- .mise/scripts/dev/test_ci_changes.py | 193 +++++++++++++++++++++++++-- .mise/tasks/dev/ci-changes | 5 +- CHANGELOG/ci_pr-path-gating.md | 1 + 10 files changed, 331 insertions(+), 92 deletions(-) diff --git a/.github/ci-paths.toml b/.github/ci-paths.toml index 7b78d799bc..870e03bcf8 100644 --- a/.github/ci-paths.toml +++ b/.github/ci-paths.toml @@ -7,6 +7,8 @@ # - 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` (db:* and interop:* units only, required there): the legs of the test-db.yml / test-interop.yml matrix that ci_changes.py builds; only running units get legs. +# - [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 = ''' @@ -90,6 +92,12 @@ windows = ''' | ^\.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"] @@ -119,26 +127,33 @@ files = '^crate/server/src/routes/aws_xks/ | ^\.github/workflows/test_all\.yml$ [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"] @@ -148,6 +163,8 @@ files = ''' | ^\.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 = ''' @@ -235,18 +252,22 @@ files = ''' [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"] @@ -257,6 +278,7 @@ files = ''' | ^\.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"] @@ -267,26 +289,32 @@ files = ''' | ^\.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-interop\.yml$' +variants = ["non-fips"] [units."interop:ssh-secrets"] sets = ["interop_shared", "pg_store", "mysql_store"] @@ -296,6 +324,7 @@ files = ''' | ^\.mise/scripts/test/openbao/bao_verifier\.sh$ | ^crate/server/src/routes/(ssh|kv)/ ''' +variants = ["fips", "non-fips"] # ── test_windows.yml ──────────────────────────────────────────────────────────────────────── [units.windows-cargo-test] diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 46a05e9178..3b69fe375c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -33,6 +33,10 @@ jobs: contents: read outputs: skip: ${{ steps.classify.outputs.skip }} + db-matrix: ${{ steps.classify.outputs.db-matrix }} + interop-matrix: ${{ steps.classify.outputs.interop-matrix }} + run-test: ${{ steps.classify.outputs.run-test }} + run-windows: ${{ steps.classify.outputs.run-windows }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: @@ -52,7 +56,7 @@ jobs: if [ "${EVENT_NAME}" = "pull_request" ]; then mise run dev:ci-changes --base HEAD^1 else - echo 'skip=[]' >> "$GITHUB_OUTPUT" + mise run dev:ci-changes --all fi cargo-clippy: @@ -87,9 +91,10 @@ jobs: # 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 @@ -99,12 +104,16 @@ jobs: test: # Run all tests (PRs, tags and the nightly schedule / manual 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' + 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 }} + db-matrix: ${{ needs.changes.outputs.db-matrix }} + interop-matrix: ${{ needs.changes.outputs.interop-matrix }} build-documentation: name: Build documentation diff --git a/.github/workflows/test-db.yml b/.github/workflows/test-db.yml index 998093976a..31724899e7 100644 --- a/.github/workflows/test-db.yml +++ b/.github/workflows/test-db.yml @@ -5,11 +5,10 @@ name: Test db on: workflow_call: inputs: - skip-units: - description: JSON list of skipped CI units, passed to test-group.yml - required: false + matrix: + description: JSON include list [{leaf, variant}] of the legs to run, built by ci_changes.py from the ci-paths.toml `variants` + required: true type: string - default: '[]' secrets: DOCKERHUB_USERNAME: {required: false} DOCKERHUB_TOKEN: {required: false} @@ -20,27 +19,11 @@ jobs: 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} + include: ${{ fromJSON(inputs.matrix) }} uses: ./.github/workflows/test-group.yml with: suite: db:${{ matrix.leaf }} variant: ${{ matrix.variant }} - skip-units: ${{ inputs.skip-units }} extra-env: | POSTGRES_USER=kms PGUSER=kms diff --git a/.github/workflows/test-group.yml b/.github/workflows/test-group.yml index 35c0da141e..454e26336b 100644 --- a/.github/workflows/test-group.yml +++ b/.github/workflows/test-group.yml @@ -27,11 +27,6 @@ on: required: false type: string default: '' - skip-units: - description: JSON list of skipped CI units (.github/ci-paths.toml); the job is skipped when it contains `suite` - required: false - type: string - default: '[]' secrets: DOCKERHUB_USERNAME: {required: false} DOCKERHUB_TOKEN: {required: false} @@ -58,7 +53,6 @@ on: jobs: test: name: test:${{ inputs.suite }} - ${{ inputs.variant }} - if: ${{ !contains(fromJSON(inputs.skip-units || '[]'), inputs.suite) }} runs-on: ubuntu-24.04 permissions: contents: read diff --git a/.github/workflows/test-interop.yml b/.github/workflows/test-interop.yml index 220078c249..9193e78781 100644 --- a/.github/workflows/test-interop.yml +++ b/.github/workflows/test-interop.yml @@ -6,11 +6,10 @@ name: Test interop on: workflow_call: inputs: - skip-units: - description: JSON list of skipped CI units, passed to test-group.yml - required: false + matrix: + description: JSON include list [{leaf, variant}] of the legs to run, built by ci_changes.py from the ci-paths.toml `variants` + required: true type: string - default: '[]' secrets: DOCKERHUB_USERNAME: {required: false} DOCKERHUB_TOKEN: {required: false} @@ -23,29 +22,11 @@ jobs: 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} + include: ${{ fromJSON(inputs.matrix) }} uses: ./.github/workflows/test-group.yml with: suite: interop:${{ matrix.leaf }} variant: ${{ matrix.variant }} - skip-units: ${{ inputs.skip-units }} secrets: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} diff --git a/.github/workflows/test_all.yml b/.github/workflows/test_all.yml index 3451346c57..e391cd50d0 100644 --- a/.github/workflows/test_all.yml +++ b/.github/workflows/test_all.yml @@ -9,7 +9,14 @@ on: required: false type: string default: '[]' - workflow_dispatch: + db-matrix: + description: JSON include list [{leaf, variant}] of the test-db.yml legs to run (ci_changes.py) + required: true + type: string + interop-matrix: + description: JSON include list [{leaf, variant}] of the test-interop.yml legs to run (ci_changes.py) + required: true + type: string jobs: # Builds the source-built Nix inputs of shell.nix (OpenSSL 3.1.2 / 3.6.5, FIPS bootstrap, SoftHSM2, @@ -82,6 +89,7 @@ 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. + # A job whose suite is skipped (ci-paths.toml) shows one skipped row; db and interop legs come from ci_changes.py matrices. # 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 }}) @@ -90,7 +98,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: @@ -99,7 +108,6 @@ jobs: with: suite: cloud variant: ${{ matrix.variant }} - skip-units: ${{ inputs.skip-units }} secrets: TEST_GOOGLE_OAUTH_CLIENT_ID: ${{ secrets.TEST_GOOGLE_OAUTH_CLIENT_ID }} TEST_GOOGLE_OAUTH_CLIENT_SECRET: ${{ secrets.TEST_GOOGLE_OAUTH_CLIENT_SECRET }} @@ -117,8 +125,9 @@ jobs: name: Test db needs: - nix-dev-shell-cache + if: inputs.db-matrix != '[]' with: - skip-units: ${{ inputs.skip-units }} + matrix: ${{ inputs.db-matrix }} uses: ./.github/workflows/test-db.yml secrets: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} @@ -128,6 +137,7 @@ jobs: name: Test hsm (${{ matrix.variant }}) needs: - nix-dev-shell-cache + if: ${{ !contains(fromJSON(inputs.skip-units || '[]'), 'hsm') }} strategy: fail-fast: false matrix: @@ -141,7 +151,6 @@ jobs: # real HSMs: test-hsm-hardware skip: hsm:crypt2pay hsm:proteccio bench: ${{ matrix.bench }} - skip-units: ${{ inputs.skip-units }} secrets: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} @@ -150,8 +159,9 @@ jobs: name: Test interop needs: - nix-dev-shell-cache + if: inputs.interop-matrix != '[]' with: - skip-units: ${{ inputs.skip-units }} + matrix: ${{ inputs.interop-matrix }} uses: ./.github/workflows/test-interop.yml secrets: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} @@ -163,6 +173,7 @@ jobs: name: Test obs (${{ matrix.variant }}) needs: - nix-dev-shell-cache + if: ${{ !contains(fromJSON(inputs.skip-units || '[]'), 'obs') }} strategy: fail-fast: false matrix: @@ -171,7 +182,6 @@ jobs: with: suite: obs variant: ${{ matrix.variant }} - skip-units: ${{ inputs.skip-units }} secrets: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} @@ -182,6 +192,7 @@ jobs: name: Test pkcs11 (${{ matrix.variant }}) needs: - nix-dev-shell-cache + if: ${{ !contains(fromJSON(inputs.skip-units || '[]'), 'pkcs11') }} strategy: fail-fast: false matrix: @@ -190,7 +201,6 @@ jobs: with: suite: pkcs11 variant: ${{ matrix.variant }} - skip-units: ${{ inputs.skip-units }} secrets: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} @@ -199,6 +209,7 @@ jobs: name: Test pki (${{ matrix.variant }}) needs: - nix-dev-shell-cache + if: ${{ !contains(fromJSON(inputs.skip-units || '[]'), 'pki') }} strategy: fail-fast: false matrix: @@ -207,7 +218,6 @@ jobs: with: suite: pki variant: ${{ matrix.variant }} - skip-units: ${{ inputs.skip-units }} secrets: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} @@ -217,6 +227,7 @@ jobs: name: Test spire (${{ matrix.variant }}) needs: - nix-dev-shell-cache + if: ${{ !contains(fromJSON(inputs.skip-units || '[]'), 'spire') }} strategy: fail-fast: false matrix: @@ -225,7 +236,6 @@ jobs: with: suite: spire variant: ${{ matrix.variant }} - skip-units: ${{ inputs.skip-units }} secrets: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} @@ -236,6 +246,7 @@ jobs: name: Test ui (${{ matrix.variant }}) needs: - nix-dev-shell-cache + if: ${{ !contains(fromJSON(inputs.skip-units || '[]'), 'ui') }} permissions: contents: read strategy: @@ -246,7 +257,6 @@ jobs: with: suite: ui variant: ${{ matrix.variant }} - skip-units: ${{ inputs.skip-units }} # 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 diff --git a/.mise/scripts/dev/ci_changes.py b/.mise/scripts/dev/ci_changes.py index 249975cebd..c4ef35d1c4 100755 --- a/.mise/scripts/dev/ci_changes.py +++ b/.mise/scripts/dev/ci_changes.py @@ -2,17 +2,21 @@ # -*- 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 `skip=` + 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 output line `skip=[...]` is appended to $GITHUB_OUTPUT when set (and always printed) so workflow jobs can -gate themselves with `!contains(fromJSON(...), '')`. Fail-safe: an empty diff, a file matching `full`, or a -file matching no unit and not `ignore`d skips nothing. +The lines `skip=[...]`, `db-matrix=[...]`, `interop-matrix=[...]`, `run-test=` and `run-windows=` are +appended to $GITHUB_OUTPUT when set (and always printed): workflow jobs gate themselves with +`!contains(fromJSON(skip), '')`, test-db.yml / test-interop.yml take their legs from the matrices 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 @@ -27,12 +31,18 @@ ) CONFIG = REPO / '.github' / 'ci-paths.toml' +# Units named `:` of these groups carry the `variants` of their test-db.yml / test-interop.yml matrix legs. +MATRIX_GROUPS = ('db', 'interop') +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]] # unit -> matrix variants, in unit order + callers: dict[str, list[str]] # main.yml caller job -> its unit keys, in unit order def fail(message: str) -> None: @@ -61,12 +71,30 @@ def load_config(path: Path) -> Config: for name, value in raw.get('sets', {}).items() } units: dict[str, list[re.Pattern[str]]] = {} + variants: dict[str, list[str]] = {} for unit, spec in raw['units'].items(): - unknown = set(spec) - {'sets', 'files'} + unknown = set(spec) - {'sets', 'files', 'variants'} if unknown: fail(f'units.{unit}: unknown key(s) {sorted(unknown)}') - if not spec: + if not {'sets', 'files'} & set(spec): fail(f'units.{unit}: needs `sets` or `files`') + in_matrix = unit.split(':', 1)[0] in MATRIX_GROUPS if ':' in unit else False + if in_matrix != ('variants' in spec): + fail( + f'units.{unit}: `variants` is required on {"/".join(MATRIX_GROUPS)} units and allowed only there' + ) + if in_matrix: + 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) patterns = [] for name in spec.get('sets', []): if name not in sets: @@ -75,10 +103,22 @@ def load_config(path: Path) -> Config: 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, + callers=callers, ) @@ -114,15 +154,38 @@ def classify(cfg: Config, files: list[str]) -> tuple[list[str], str]: ) +def outputs(cfg: Config, skipped: list[str]) -> dict[str, str]: + """$GITHUB_OUTPUT values: `skip`, one `-matrix` per MATRIX_GROUPS group, one `run-` per caller.""" + compact = {'separators': (',', ':')} + result = {'skip': json.dumps(skipped, **compact)} + for group in MATRIX_GROUPS: + legs = [ + {'leaf': unit.split(':', 1)[1], 'variant': variant} + for unit, variants in cfg.variants.items() + if unit.startswith(f'{group}:') and unit not in skipped + for variant in variants + ] + result[f'{group}-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) - files = changed_files(args.base, args.head) - skipped, reason = classify(cfg, files) + 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: @@ -131,12 +194,13 @@ def main() -> None: for unit in cfg.units: print(f'{"SKIP" if unit in skipped else "RUN "} {unit}') - line = f'skip={json.dumps(skipped, separators=(",", ":"))}' + 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(line + '\n') - print(line) + handle.write('\n'.join(lines) + '\n') + for line in lines: + print(line) if __name__ == '__main__': diff --git a/.mise/scripts/dev/test_ci_changes.py b/.mise/scripts/dev/test_ci_changes.py index 6f8dad2aa8..32f4a3543f 100755 --- a/.mise/scripts/dev/test_ci_changes.py +++ b/.mise/scripts/dev/test_ci_changes.py @@ -12,6 +12,7 @@ import io import json import os +import re import subprocess import sys import tempfile @@ -50,6 +51,37 @@ } +def leaves(leaf: str, *variants: str) -> list[dict[str, str]]: + return [{'leaf': leaf, 'variant': v} for v in variants] + + +BOTH = ('fips', 'non-fips') +# Every leg, in ci-paths.toml unit order (what `ci_changes.py --all` emits). +FULL_DB = [ + *leaves('sqlite', *BOTH), + *leaves('psql', *BOTH), + *leaves('mysql', *BOTH), + *leaves('mariadb', *BOTH), + *leaves('percona', *BOTH), + *leaves('redis', 'non-fips'), + *leaves('openbao', *BOTH), +] +FULL_INTEROP = [ + *leaves('ase', 'non-fips'), + *leaves('db2', 'non-fips'), + *leaves('edb-tde', 'non-fips'), + *leaves('iris', 'non-fips'), + *leaves('jose', 'non-fips'), + *leaves('kmip-go', *BOTH), + *leaves('kmipkit', 'non-fips'), + *leaves('openbao', *BOTH), + *leaves('openbao-auth-verifier', *BOTH), + *leaves('openbao-kmip', *BOTH), + *leaves('pykmip', 'non-fips'), + *leaves('ssh-secrets', *BOTH), +] + + def run(*files: str) -> set[str]: """Units that run for a PR changing `files`.""" skipped, _ = ci_changes.classify(CFG, list(files)) @@ -305,6 +337,85 @@ def test_db_and_group_wrappers_run_nothing(self) -> None: ) +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['db-matrix']), FULL_DB) + self.assertEqual(json.loads(out['interop-matrix']), FULL_INTEROP) + self.assertEqual((len(FULL_DB), len(FULL_INTEROP)), (13, 17)) + 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-db.yml', + '.github/workflows/test-interop.yml', + '.github/workflows/test_windows.yml', + '.mise/scripts/dev/ci_changes.py', + ) + self.assertEqual(json.loads(out['db-matrix']), []) + self.assertEqual( + json.loads(out['interop-matrix']), leaves('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['db-matrix']), + [ + *leaves('sqlite', *BOTH), + *leaves('psql', *BOTH), + *leaves('openbao', *BOTH), + ], + ) + self.assertEqual( + json.loads(out['interop-matrix']), leaves('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['db-matrix'], '[]') + self.assertEqual(out['interop-matrix'], '[]') + self.assertEqual((out['run-test'], out['run-windows']), ('true', 'true')) + + 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(len(m) + len(t) + len(w) + len(v), len(EVERYTHING)) + 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) @@ -519,6 +630,35 @@ def test_set_may_be_used_by_several_units_and_units_keep_file_order(self) -> Non self.assertEqual(len(cfg.units['b']), 1) # files only self.assertEqual(len(cfg.units['c']), 2) # set + files + def test_variants_are_required_on_matrix_units_and_only_there(self) -> None: + self.rejects( + "full = 'x'\nignore = 'y'\n[units.a]\nfiles = 'x'\nvariants = ['fips']\n" + ) + self.rejects("full = 'x'\nignore = 'y'\n[units.'db:x']\nfiles = 'x'\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. @@ -637,21 +777,23 @@ def test_report_lists_files_reason_and_every_unit(self) -> None: 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:-1]} + marks = {line[5:]: line[:4] for line in lines[3:-5]} 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_skip_line_is_compact_sorted_json_and_appended_to_github_output( + 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(len(written), 1) - self.assertEqual(written[0], text.splitlines()[-1]) - self.assertTrue(written[0].startswith('skip=[')) + self.assertEqual(written, text.splitlines()[-5:]) + self.assertEqual( + [line.split('=', 1)[0] for line in written], + ['skip', 'db-matrix', 'interop-matrix', 'run-test', 'run-windows'], + ) self.assertNotIn(' ', written[0]) skipped = json.loads(written[0].removeprefix('skip=')) self.assertEqual(skipped, sorted(EVERYTHING - {'ui', 'windows-ui'})) @@ -665,32 +807,55 @@ def test_github_output_is_appended_not_overwritten(self) -> None: def test_without_github_output_only_prints(self) -> None: text, _ = self.run_main(['ui/src/App.tsx'], output=None) - self.assertTrue(text.splitlines()[-1].startswith('skip=[')) + self.assertTrue(text.splitlines()[-5].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['db-matrix']), FULL_DB) + self.assertEqual(json.loads(got['interop-matrix']), FULL_INTEROP) + 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.assertEqual(self.output.read_text(), 'skip=[]\n') + 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.assertEqual(self.output.read_text(), 'skip=[]\n') + 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.assertEqual(self.output.read_text(), 'skip=[]\n') + 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) - self.assertEqual( - json.loads(self.output.read_text().removeprefix('skip=')), - sorted(EVERYTHING), - ) + got = dict(line.split('=', 1) for line in self.output.read_text().splitlines()) + self.assertEqual(json.loads(got['skip']), sorted(EVERYTHING)) + self.assertEqual((got['db-matrix'], got['interop-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: @@ -721,7 +886,7 @@ def test_script_runs_as_a_program(self) -> None: check=True, ) self.assertIn('empty diff: run everything', done.stdout) - self.assertEqual(done.stdout.splitlines()[-1], 'skip=[]') + self.assertIn('skip=[]', done.stdout.splitlines()) def test_unknown_flag_is_rejected(self) -> None: script = Path(ci_changes.__file__) diff --git a/.mise/tasks/dev/ci-changes b/.mise/tasks/dev/ci-changes index 9a83606594..ea7ae7d9f2 100755 --- a/.mise/tasks/dev/ci-changes +++ b/.mise/tasks/dev/ci-changes @@ -1,7 +1,8 @@ #!/usr/bin/env bash -#MISE description="Classify the files a PR changes with .github/ci-paths.toml: prints and appends skip= to GITHUB_OUTPUT" +#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" @@ -11,6 +12,8 @@ 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 diff --git a/CHANGELOG/ci_pr-path-gating.md b/CHANGELOG/ci_pr-path-gating.md index 33178b4163..b029363e68 100644 --- a/CHANGELOG/ci_pr-path-gating.md +++ b/CHANGELOG/ci_pr-path-gating.md @@ -1,3 +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, 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`, `test-db.yml`, `test-interop.yml`, `test-group.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. A change to `main.yml` or `test_all.yml` runs only the units defined in or called directly by it, and one to `test-interop.yml` runs `interop:pykmip`; `no-nix.yml`, `test_windows.yml`, `cargo_test.ps1`, `test-db.yml`, `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 `db-matrix`, `interop-matrix` (the running legs, from the `variants` of each `db:*` / `interop:*` unit in `ci-paths.toml`) and `run-test` / `run-windows` (from its `[callers]` table); `test-db.yml` and `test-interop.yml` build their matrix from them, `test_all.yml` gates each suite job itself (`test-group.yml` no longer takes `skip-units`), and `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 matrices for non-PR events). From 28c363e33686fc6c94040e4392791006823290e5 Mon Sep 17 00:00:00 2001 From: Manuthor Date: Sat, 21 Nov 2026 20:52:28 +0100 Subject: [PATCH 12/14] ci: gate the documentation build on docs changes and move the nightly link check out of main.yml - ci-paths.toml: new build-documentation unit (documentation/, AGENTS.md, AI instruction files, docs tasks); main.yml build-documentation job gated on it - linkcheck.yml: schedule-only workflow, so PRs no longer list a skipped link-check row - CHANGELOG: fix the skip-units sentence that db/interop no longer take --- .github/ci-paths.toml | 18 +++++++++++----- .github/workflows/linkcheck.yml | 23 +++++++++++++++++++++ .github/workflows/main.yml | 18 ++-------------- .mise/scripts/dev/test_ci_changes.py | 31 ++++++++++++++++++---------- CHANGELOG/ci_pr-path-gating.md | 4 ++-- 5 files changed, 60 insertions(+), 34 deletions(-) create mode 100644 .github/workflows/linkcheck.yml diff --git a/.github/ci-paths.toml b/.github/ci-paths.toml index 870e03bcf8..2327a35bf5 100644 --- a/.github/ci-paths.toml +++ b/.github/ci-paths.toml @@ -26,21 +26,19 @@ full = ''' # Changed files that legitimately trigger nothing (docs, packaging, release, ungated jobs' inputs). ignore = ''' \.md$ -| ^documentation/ | ^CHANGELOG/ -| ^\.github/(skills|instructions)/ | ^\.github/(dependabot\.yml|\.markdownlint\.yaml|scripts/patch-kube-apiserver\.py)$ -| ^\.github/workflows/(benchmark|build_windows|cla|flamegraph|github_cache_cleanup|nightly|nix-update-hashes +| ^\.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|docs|git|package|release|sbom)/ +| ^\.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|docs|git|package|pre-commit|release|sbom)/ +| ^\.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-db|test-group)\.yml$ # reusable wrappers: no suite leg stands for them, any run of another suite exercises them | ^\.github/workflows/(no-nix|test_windows)\.yml$ # Rust-only jobs: they run on crate changes, not on their own workflow files @@ -114,6 +112,16 @@ sets = ["rust"] 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"] diff --git a/.github/workflows/linkcheck.yml b/.github/workflows/linkcheck.yml new file mode 100644 index 0000000000..559f7baa59 --- /dev/null +++ b/.github/workflows/linkcheck.yml @@ -0,0 +1,23 @@ +--- +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 + 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 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3b69fe375c..c983b7c732 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -117,6 +117,8 @@ jobs: 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 @@ -136,22 +138,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/.mise/scripts/dev/test_ci_changes.py b/.mise/scripts/dev/test_ci_changes.py index 32f4a3543f..d27396722b 100755 --- a/.mise/scripts/dev/test_ci_changes.py +++ b/.mise/scripts/dev/test_ci_changes.py @@ -89,16 +89,22 @@ def run(*files: str) -> set[str]: class DocsAndIgnored(unittest.TestCase): - def test_docs_only_runs_nothing(self) -> None: - self.assertEqual( - run( - 'documentation/docs/index.md', - 'CHANGELOG/x.md', - 'README.md', - '.github/skills/foo/SKILL.md', - ), - set(), - ) + 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( @@ -281,6 +287,7 @@ def test_workflow_only_pr_runs_direct_units_and_never_db_sqlite(self) -> None: 'cargo-clippy', 'cargo-machete', 'forward-proxy', + 'build-documentation', 'cargo-publish-dry-run', 'xks-remote', 'interop:pykmip', @@ -447,7 +454,8 @@ def test_one_full_file_overrides_ignored_ones(self) -> None: 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'} + run('ui/src/App.tsx', 'documentation/docs/index.md'), + {'ui', 'windows-ui', 'build-documentation'}, ) def test_union_of_independent_areas(self) -> None: @@ -465,6 +473,7 @@ def test_core_plus_ui_is_server_wide_plus_ui(self) -> None: # 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', diff --git a/CHANGELOG/ci_pr-path-gating.md b/CHANGELOG/ci_pr-path-gating.md index b029363e68..ef93aaf1d5 100644 --- a/CHANGELOG/ci_pr-path-gating.md +++ b/CHANGELOG/ci_pr-path-gating.md @@ -1,4 +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, 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`, `test-db.yml`, `test-interop.yml`, `test-group.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. A change to `main.yml` or `test_all.yml` runs only the units defined in or called directly by it, and one to `test-interop.yml` runs `interop:pykmip`; `no-nix.yml`, `test_windows.yml`, `cargo_test.ps1`, `test-db.yml`, `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 `db-matrix`, `interop-matrix` (the running legs, from the `variants` of each `db:*` / `interop:*` unit in `ci-paths.toml`) and `run-test` / `run-windows` (from its `[callers]` table); `test-db.yml` and `test-interop.yml` build their matrix from them, `test_all.yml` gates each suite job itself (`test-group.yml` no longer takes `skip-units`), and `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 matrices for non-PR events). +- 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, and one to `test-interop.yml` runs `interop:pykmip`; `no-nix.yml`, `test_windows.yml`, `cargo_test.ps1`, `test-db.yml`, `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 `db-matrix`, `interop-matrix` (the running legs, from the `variants` of each `db:*` / `interop:*` unit in `ci-paths.toml`) and `run-test` / `run-windows` (from its `[callers]` table); `test-db.yml` and `test-interop.yml` build their matrix from them, `test_all.yml` gates each suite job itself (`test-group.yml` no longer takes `skip-units`), and `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 matrices 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. From 94305dabbce5a9eb41a2e01712c5f6e0dde30025 Mon Sep 17 00:00:00 2001 From: Manuthor Date: Sat, 21 Nov 2026 20:57:57 +0100 Subject: [PATCH 13/14] ci: run the Docker-Hub-only suites as legs of one dynamic matrix job - ci_changes.py emits a single suites-matrix [{suite, variant, bench}] built from the `variants` / `bench` of ci-paths.toml units; db-matrix and interop-matrix are gone - test_all.yml: test-suites replaces test-db, test-interop, test-hsm, test-obs, test-pkcs11, test-pki and test-spire; per-leg secrets expressions limit EDB/IRIS to interop and Splunk to obs - test-cloud and test-ui stay separate jobs so their secret scope is set by the job - test-group.yml carries the database environment; test-db.yml and test-interop.yml are removed --- .github/ci-paths.toml | 15 ++- .github/instructions/hsm.instructions.md | 2 +- .github/workflows/README_main.md | 18 ++- .github/workflows/main.yml | 6 +- .github/workflows/test-db.yml | 52 --------- .github/workflows/test-group.yml | 37 ++++-- .github/workflows/test-interop.yml | 34 ------ .github/workflows/test_all.yml | 139 +++-------------------- .mise/scripts/dev/ci_changes.py | 100 +++++++++------- .mise/scripts/dev/test_ci_changes.py | 131 ++++++++++----------- CHANGELOG/ci_pr-path-gating.md | 4 +- 11 files changed, 194 insertions(+), 344 deletions(-) delete mode 100644 .github/workflows/test-db.yml delete mode 100644 .github/workflows/test-interop.yml diff --git a/.github/ci-paths.toml b/.github/ci-paths.toml index 2327a35bf5..468ca03890 100644 --- a/.github/ci-paths.toml +++ b/.github/ci-paths.toml @@ -7,7 +7,9 @@ # - 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` (db:* and interop:* units only, required there): the legs of the test-db.yml / test-interop.yml matrix that ci_changes.py builds; only running units get legs. +# - `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. @@ -40,7 +42,7 @@ ignore = ''' | ^\.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-db|test-group)\.yml$ # reusable wrappers: no suite leg stands for them, any run of another suite exercises them +| ^\.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 ''' @@ -193,6 +195,8 @@ files = ''' | ^\.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 = ''' @@ -205,6 +209,8 @@ files = ''' |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 = ''' @@ -221,6 +227,7 @@ files = ''' | ^crate/server/src/(core/audit/|middlewares/audit/|routes/kmip/audit\.rs$) | ^crate/server_database/src/stores/audit/ ''' +variants = ["fips", "non-fips"] [units.pki] files = ''' @@ -234,6 +241,7 @@ files = ''' | ^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"] @@ -244,6 +252,7 @@ files = ''' | ^\.mise/lib/spire_test\.sh$ | ^\.mise/scripts/test/grant_spire_pki_certify\.sh$ ''' +variants = ["non-fips"] [units.ui] files = ''' @@ -321,7 +330,7 @@ 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-interop\.yml$' +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"] 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/main.yml b/.github/workflows/main.yml index c983b7c732..6714916b05 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -33,8 +33,7 @@ jobs: contents: read outputs: skip: ${{ steps.classify.outputs.skip }} - db-matrix: ${{ steps.classify.outputs.db-matrix }} - interop-matrix: ${{ steps.classify.outputs.interop-matrix }} + suites-matrix: ${{ steps.classify.outputs.suites-matrix }} run-test: ${{ steps.classify.outputs.run-test }} run-windows: ${{ steps.classify.outputs.run-windows }} steps: @@ -112,8 +111,7 @@ jobs: secrets: inherit with: skip-units: ${{ needs.changes.outputs.skip }} - db-matrix: ${{ needs.changes.outputs.db-matrix }} - interop-matrix: ${{ needs.changes.outputs.interop-matrix }} + suites-matrix: ${{ needs.changes.outputs.suites-matrix }} build-documentation: name: Build documentation diff --git a/.github/workflows/test-db.yml b/.github/workflows/test-db.yml deleted file mode 100644 index 31724899e7..0000000000 --- a/.github/workflows/test-db.yml +++ /dev/null @@ -1,52 +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: - inputs: - matrix: - description: JSON include list [{leaf, variant}] of the legs to run, built by ci_changes.py from the ci-paths.toml `variants` - required: true - type: string - secrets: - DOCKERHUB_USERNAME: {required: false} - DOCKERHUB_TOKEN: {required: false} - -jobs: - leaf: - name: Test db ${{ matrix.leaf }} (${{ matrix.variant }}) - strategy: - fail-fast: false - matrix: - include: ${{ fromJSON(inputs.matrix) }} - 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 9193e78781..0000000000 --- a/.github/workflows/test-interop.yml +++ /dev/null @@ -1,34 +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: - inputs: - matrix: - description: JSON include list [{leaf, variant}] of the legs to run, built by ci_changes.py from the ci-paths.toml `variants` - required: true - type: string - 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: ${{ fromJSON(inputs.matrix) }} - 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 e391cd50d0..cab4122327 100644 --- a/.github/workflows/test_all.yml +++ b/.github/workflows/test_all.yml @@ -9,12 +9,8 @@ on: required: false type: string default: '[]' - db-matrix: - description: JSON include list [{leaf, variant}] of the test-db.yml legs to run (ci_changes.py) - required: true - type: string - interop-matrix: - description: JSON include list [{leaf, variant}] of the test-interop.yml legs to run (ci_changes.py) + 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 @@ -89,7 +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. - # A job whose suite is skipped (ci-paths.toml) shows one skipped row; db and interop legs come from ci_changes.py matrices. + # `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 }}) @@ -121,124 +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 - if: inputs.db-matrix != '[]' - with: - matrix: ${{ inputs.db-matrix }} - 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: ${{ !contains(fromJSON(inputs.skip-units || '[]'), 'hsm') }} + 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 - if: inputs.interop-matrix != '[]' - with: - matrix: ${{ inputs.interop-matrix }} - 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 - if: ${{ !contains(fromJSON(inputs.skip-units || '[]'), 'obs') }} - 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 - if: ${{ !contains(fromJSON(inputs.skip-units || '[]'), 'pkcs11') }} - 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 - if: ${{ !contains(fromJSON(inputs.skip-units || '[]'), 'pki') }} - 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 - if: ${{ !contains(fromJSON(inputs.skip-units || '[]'), 'spire') }} - 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. @@ -259,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 @@ -355,7 +258,7 @@ 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) @@ -410,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/.mise/scripts/dev/ci_changes.py b/.mise/scripts/dev/ci_changes.py index c4ef35d1c4..98b68f16ef 100755 --- a/.mise/scripts/dev/ci_changes.py +++ b/.mise/scripts/dev/ci_changes.py @@ -6,9 +6,9 @@ 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=[...]`, `db-matrix=[...]`, `interop-matrix=[...]`, `run-test=` and `run-windows=` are -appended to $GITHUB_OUTPUT when set (and always printed): workflow jobs gate themselves with -`!contains(fromJSON(skip), '')`, test-db.yml / test-interop.yml take their legs from the matrices and main.yml +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. """ @@ -31,8 +31,6 @@ ) CONFIG = REPO / '.github' / 'ci-paths.toml' -# Units named `:` of these groups carry the `variants` of their test-db.yml / test-interop.yml matrix legs. -MATRIX_GROUPS = ('db', 'interop') VARIANTS = ('fips', 'non-fips') @@ -41,22 +39,27 @@ class Config: full: re.Pattern[str] ignore: re.Pattern[str] units: dict[str, list[re.Pattern[str]]] - variants: dict[str, list[str]] # unit -> matrix variants, in unit order + 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) + 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') + 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}') + fail(f"{key}: invalid regex: {exc}") raise # unreachable, fail() exits @@ -65,25 +68,21 @@ def load_config(path: Path) -> Config: raw = tomllib.load(handle) for key in ('full', 'ignore', 'units'): if key not in raw: - fail(f'{path.name}: missing `{key}`') + fail(f"{path.name}: missing `{key}`") sets = { - name: compile_pattern(f'sets.{name}', value) + 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'} + unknown = set(spec) - {'sets', 'files', 'variants', 'bench'} if unknown: - fail(f'units.{unit}: unknown key(s) {sorted(unknown)}') + fail(f"units.{unit}: unknown key(s) {sorted(unknown)}") if not {'sets', 'files'} & set(spec): - fail(f'units.{unit}: needs `sets` or `files`') - in_matrix = unit.split(':', 1)[0] in MATRIX_GROUPS if ':' in unit else False - if in_matrix != ('variants' in spec): - fail( - f'units.{unit}: `variants` is required on {"/".join(MATRIX_GROUPS)} units and allowed only there' - ) - if in_matrix: + fail(f"units.{unit}: needs `sets` or `files`") + if 'variants' in spec: legs = spec['variants'] if ( not isinstance(legs, list) @@ -92,24 +91,35 @@ def load_config(path: Path) -> Config: or len(set(legs)) != len(legs) ): fail( - f'units.{unit}: `variants` must be a non-empty list of distinct values among {list(VARIANTS)}' + 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}`') + 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'])) + 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') + 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') + 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) ] @@ -118,6 +128,7 @@ def load_config(path: Path) -> Config: ignore=compile_pattern('ignore', raw['ignore']), units=units, variants=variants, + bench=bench, callers=callers, ) @@ -138,7 +149,7 @@ def classify(cfg: Config, files: list[str]) -> tuple[list[str], str]: return [], 'empty diff: run everything' for f in files: if cfg.full.search(f): - return [], f'{f} matches full: run everything' + return [], f"{f} matches full: run everything" triggered: set[str] = set() orphans = [] for f in files: @@ -147,27 +158,32 @@ def classify(cfg: Config, files: list[str]) -> tuple[list[str], str]: 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 [], 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', + f"{len(triggered)} of {len(cfg.units)} units triggered", ) def outputs(cfg: Config, skipped: list[str]) -> dict[str, str]: - """$GITHUB_OUTPUT values: `skip`, one `-matrix` per MATRIX_GROUPS group, one `run-` per caller.""" + """$GITHUB_OUTPUT values: `skip`, `suites-matrix` (legs of the running suite units) and one `run-` per caller.""" compact = {'separators': (',', ':')} - result = {'skip': json.dumps(skipped, **compact)} - for group in MATRIX_GROUPS: - legs = [ - {'leaf': unit.split(':', 1)[1], 'variant': variant} - for unit, variants in cfg.variants.items() - if unit.startswith(f'{group}:') and unit not in skipped - for variant in variants - ] - result[f'{group}-matrix'] = json.dumps(legs, **compact) + 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() + result[f"run-{caller}"] = str(any(u not in skipped for u in units)).lower() return result @@ -187,14 +203,14 @@ def main() -> None: files = changed_files(args.base, args.head) skipped, reason = classify(cfg, files) - print(f'Changed files ({len(files)}):') + print(f"Changed files ({len(files)}):") for f in files: - print(f' {f}') + 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()] + 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: diff --git a/.mise/scripts/dev/test_ci_changes.py b/.mise/scripts/dev/test_ci_changes.py index d27396722b..574afb50fb 100755 --- a/.mise/scripts/dev/test_ci_changes.py +++ b/.mise/scripts/dev/test_ci_changes.py @@ -51,34 +51,39 @@ } -def leaves(leaf: str, *variants: str) -> list[dict[str, str]]: - return [{'leaf': leaf, 'variant': v} for v in variants] +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') -# Every leg, in ci-paths.toml unit order (what `ci_changes.py --all` emits). -FULL_DB = [ - *leaves('sqlite', *BOTH), - *leaves('psql', *BOTH), - *leaves('mysql', *BOTH), - *leaves('mariadb', *BOTH), - *leaves('percona', *BOTH), - *leaves('redis', 'non-fips'), - *leaves('openbao', *BOTH), -] -FULL_INTEROP = [ - *leaves('ase', 'non-fips'), - *leaves('db2', 'non-fips'), - *leaves('edb-tde', 'non-fips'), - *leaves('iris', 'non-fips'), - *leaves('jose', 'non-fips'), - *leaves('kmip-go', *BOTH), - *leaves('kmipkit', 'non-fips'), - *leaves('openbao', *BOTH), - *leaves('openbao-auth-verifier', *BOTH), - *leaves('openbao-kmip', *BOTH), - *leaves('pykmip', 'non-fips'), - *leaves('ssh-secrets', *BOTH), +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), ] @@ -278,8 +283,6 @@ def test_workflow_only_pr_runs_direct_units_and_never_db_sqlite(self) -> None: '.github/workflows/main.yml', '.github/workflows/test_all.yml', '.github/workflows/test-group.yml', - '.github/workflows/test-db.yml', - '.github/workflows/test-interop.yml', '.github/workflows/test_windows.yml', '.mise/scripts/dev/ci_changes.py', ), @@ -310,7 +313,6 @@ 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', - '.github/workflows/test-interop.yml', '.mise/tasks/test/db/psql', '.mise/tasks/test/interop/pykmip', 'ui/src/App.tsx', @@ -337,11 +339,8 @@ def test_xks_remote_runs_on_xks_related_rust_source(self) -> None: with self.subTest(path=path): self.assertIn('xks-remote', run(path)) - def test_db_and_group_wrappers_run_nothing(self) -> None: - self.assertEqual( - run('.github/workflows/test-db.yml', '.github/workflows/test-group.yml'), - set(), - ) + def test_group_wrapper_runs_nothing(self) -> None: + self.assertEqual(run('.github/workflows/test-group.yml'), set()) class Matrices(unittest.TestCase): @@ -353,9 +352,8 @@ def out(self, *files: str) -> dict[str, str]: 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['db-matrix']), FULL_DB) - self.assertEqual(json.loads(out['interop-matrix']), FULL_INTEROP) - self.assertEqual((len(FULL_DB), len(FULL_INTEROP)), (13, 17)) + 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: @@ -364,38 +362,42 @@ def test_workflow_only_pr(self) -> None: '.github/workflows/main.yml', '.github/workflows/test_all.yml', '.github/workflows/test-group.yml', - '.github/workflows/test-db.yml', - '.github/workflows/test-interop.yml', '.github/workflows/test_windows.yml', '.mise/scripts/dev/ci_changes.py', ) - self.assertEqual(json.loads(out['db-matrix']), []) self.assertEqual( - json.loads(out['interop-matrix']), leaves('pykmip', 'non-fips') + 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['db-matrix']), + json.loads(out['suites-matrix']), [ - *leaves('sqlite', *BOTH), - *leaves('psql', *BOTH), - *leaves('openbao', *BOTH), + *leg('db:sqlite', *BOTH), + *leg('db:psql', *BOTH), + *leg('db:openbao', *BOTH), + *leg('interop:ssh-secrets', *BOTH), ], ) - self.assertEqual( - json.loads(out['interop-matrix']), leaves('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['db-matrix'], '[]') - self.assertEqual(out['interop-matrix'], '[]') + 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')) @@ -418,7 +420,9 @@ def test_units_callers_and_workflows_agree(self) -> None: ) v = set(CFG.variants) self.assertEqual(m | t | w | v, EVERYTHING) - self.assertEqual(len(m) + len(t) + len(w) + len(v), len(EVERYTHING)) + self.assertEqual( + len(m) + len(w) + len(t | v), len(EVERYTHING) + ) # `pki` is in t and v self.assertEqual(set(CFG.callers['test']), t | v) self.assertEqual(set(CFG.callers['windows']), w) @@ -524,7 +528,7 @@ def test_every_unit_is_reachable_without_running_everything(self) -> None: with self.subTest(unit=unit): ran = run(path) self.assertIn(unit, ran) - self.assertNotEqual(ran, EVERYTHING, f'{path} hits full or an orphan') + 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']) @@ -639,11 +643,11 @@ def test_set_may_be_used_by_several_units_and_units_keep_file_order(self) -> Non self.assertEqual(len(cfg.units['b']), 1) # files only self.assertEqual(len(cfg.units['c']), 2) # set + files - def test_variants_are_required_on_matrix_units_and_only_there(self) -> None: - self.rejects( - "full = 'x'\nignore = 'y'\n[units.a]\nfiles = 'x'\nvariants = ['fips']\n" - ) - self.rejects("full = 'x'\nignore = 'y'\n[units.'db:x']\nfiles = 'x'\n") + 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']"): @@ -785,8 +789,8 @@ def test_report_lists_files_reason_and_every_unit(self) -> None: 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:-5]} + 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'} @@ -798,10 +802,10 @@ def test_output_lines_are_compact_json_in_order_and_appended_to_github_output( ) -> None: text, _ = self.run_main(['ui/src/App.tsx'], output=self.output) written = self.output.read_text().splitlines() - self.assertEqual(written, text.splitlines()[-5:]) + self.assertEqual(written, text.splitlines()[-4:]) self.assertEqual( [line.split('=', 1)[0] for line in written], - ['skip', 'db-matrix', 'interop-matrix', 'run-test', 'run-windows'], + ['skip', 'suites-matrix', 'run-test', 'run-windows'], ) self.assertNotIn(' ', written[0]) skipped = json.loads(written[0].removeprefix('skip=')) @@ -816,14 +820,13 @@ def test_github_output_is_appended_not_overwritten(self) -> None: def test_without_github_output_only_prints(self) -> None: text, _ = self.run_main(['ui/src/App.tsx'], output=None) - self.assertTrue(text.splitlines()[-5].startswith('skip=[')) + 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['db-matrix']), FULL_DB) - self.assertEqual(json.loads(got['interop-matrix']), FULL_INTEROP) + 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: @@ -863,7 +866,7 @@ 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['db-matrix'], got['interop-matrix']), ('[]', '[]')) + self.assertEqual(got['suites-matrix'], '[]') self.assertEqual((got['run-test'], got['run-windows']), ('false', 'false')) self.assertNotIn('RUN ', text) diff --git a/CHANGELOG/ci_pr-path-gating.md b/CHANGELOG/ci_pr-path-gating.md index ef93aaf1d5..7a03d96621 100644 --- a/CHANGELOG/ci_pr-path-gating.md +++ b/CHANGELOG/ci_pr-path-gating.md @@ -1,4 +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, and one to `test-interop.yml` runs `interop:pykmip`; `no-nix.yml`, `test_windows.yml`, `cargo_test.ps1`, `test-db.yml`, `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 `db-matrix`, `interop-matrix` (the running legs, from the `variants` of each `db:*` / `interop:*` unit in `ci-paths.toml`) and `run-test` / `run-windows` (from its `[callers]` table); `test-db.yml` and `test-interop.yml` build their matrix from them, `test_all.yml` gates each suite job itself (`test-group.yml` no longer takes `skip-units`), and `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 matrices 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. +- 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. From 6c30f669a6250636225c6fac65099b1ea1e7a231 Mon Sep 17 00:00:00 2001 From: Manuthor Date: Sat, 21 Nov 2026 21:04:40 +0100 Subject: [PATCH 14/14] ci: assert suite isolation in the wiring test, least-privilege linkcheck - Wiring test: only `pki` may be both a test_all.yml job and a suites leg; `cloud` and `ui` must never get variants - linkcheck.yml: job-level contents: read, persist-credentials: false --- .github/workflows/linkcheck.yml | 3 +++ .mise/scripts/dev/test_ci_changes.py | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/linkcheck.yml b/.github/workflows/linkcheck.yml index 559f7baa59..0954e565d5 100644 --- a/.github/workflows/linkcheck.yml +++ b/.github/workflows/linkcheck.yml @@ -11,10 +11,13 @@ 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 diff --git a/.mise/scripts/dev/test_ci_changes.py b/.mise/scripts/dev/test_ci_changes.py index 574afb50fb..6eb9affb6b 100755 --- a/.mise/scripts/dev/test_ci_changes.py +++ b/.mise/scripts/dev/test_ci_changes.py @@ -421,8 +421,13 @@ def test_units_callers_and_workflows_agree(self) -> None: v = set(CFG.variants) self.assertEqual(m | t | w | v, EVERYTHING) self.assertEqual( - len(m) + len(w) + len(t | v), len(EVERYTHING) - ) # `pki` is in t and v + 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)