diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 1758238..6789a84 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -62,14 +62,6 @@ jobs: runs-on: docker container: image: rust:1.94-bookworm - # The agent's integration tests run against a real MongoDB (as the nightly - # does); without one they had rotted unnoticed since the M7.2 tenant split. - services: - mongo: - image: mongo:7 - env: - MONGO_INITDB_ROOT_USERNAME: root - MONGO_INITDB_ROOT_PASSWORD: example steps: - name: Checkout run: | @@ -150,10 +142,6 @@ jobs: # compliance-core's integration tests need no services. - name: Tests (core integration) run: cargo test -p compliance-core --tests - - name: Tests (agent integration) - run: cargo test -p compliance-agent --test '*' - env: - TEST_MONGODB_URI: mongodb://root:example@mongo:27017/?authSource=admin - name: Tests (dashboard server) run: cargo test -p compliance-dashboard --features server --no-default-features - name: Tests (dashboard web) @@ -163,6 +151,79 @@ jobs: run: sccache --show-stats if: always() + # The agent's integration tests against a real MongoDB (as the nightly). Its + # own job: as the last step of the long check job the mongo service had + # gone by the time the tests ran (server selection timeout, container + # already removed). Without one in CI they had rotted unnoticed since the + # M7.2 tenant split. + agent-integration: + name: Agent integration + if: github.event_name == 'pull_request' + runs-on: docker + container: + image: rust:1.94-bookworm + services: + mongo: + image: mongo:7 + env: + MONGO_INITDB_ROOT_USERNAME: root + MONGO_INITDB_ROOT_PASSWORD: example + steps: + - name: Checkout + run: | + git init + git remote add origin "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git" + git fetch --depth=1 origin "${GITHUB_SHA}" + git checkout FETCH_HEAD + # Resolve crates.io deps through the self-hosted Kellnr mirror (cached, + # crates.io-independent). Git deps (firmwerk-core) are unaffected — source + # replacement only applies to crates.io-sourced crates. + - name: Use Kellnr crates.io mirror + run: | + : "${CARGO_HOME:=/usr/local/cargo}" + mkdir -p "$CARGO_HOME" + { + echo '[source.crates-io]' + echo 'replace-with = "kellnr"' + echo '[registries.kellnr]' + echo 'index = "sparse+https://crates.breakpilot.com/api/v1/cratesio/"' + } >> "$CARGO_HOME/config.toml" + env: + RUSTC_WRAPPER: "" + - name: Install sccache + run: | + curl -fsSL https://github.com/mozilla/sccache/releases/download/v0.10.0/sccache-v0.10.0-x86_64-unknown-linux-musl.tar.gz \ + | tar xz --strip-components=1 -C /usr/local/bin/ sccache-v0.10.0-x86_64-unknown-linux-musl/sccache + chmod +x /usr/local/bin/sccache + env: + RUSTC_WRAPPER: "" + + # compliance-agent has a git dependency on firmwerk-core (a private repo on + # this Gitea instance). Rewrite its SSH URL to HTTPS + a PAT so the runner + # can fetch it. Uses the org secret PLATFORM_CI_TOKEN (bot `platform-ci`, + # read-only member of the platform org). + # (Honored on fetch because CARGO_NET_GIT_FETCH_WITH_CLI=true uses system git.) + - name: Configure git auth for the private firmwerk dependency + run: | + git config --global \ + url."https://platform-ci:${{ secrets.PLATFORM_CI_TOKEN }}@git.breakpilot.com/".insteadOf \ + "ssh://git@git.breakpilot.com:22222/" + env: + RUSTC_WRAPPER: "" + + - name: Wait for MongoDB + run: | + for i in $(seq 1 60); do + if (exec 3<>/dev/tcp/mongo/27017) 2>/dev/null; then echo "mongo:27017 is up"; exit 0; fi + sleep 2 + done + echo "::error::mongo:27017 not reachable after 120 s"; getent hosts mongo || echo "mongo does not resolve"; exit 1 + shell: bash + - name: Tests (agent integration) + run: cargo test -p compliance-agent --test '*' + env: + TEST_MONGODB_URI: mongodb://root:example@mongo:27017/?authSource=admin + # --------------------------------------------------------------------------- # Stage 2: Deploy (only on main, after checks pass) # Each service only deploys when its relevant files changed.