251 lines
11 KiB
YAML
251 lines
11 KiB
YAML
name: Nightly scan regression
|
|
|
|
# Scans the fixture corpus (fixtures/demo-targets and fixtures/nightly) with
|
|
# the agent image built from main and compares the results with the blessed
|
|
# baselines in fixtures/nightly/baselines (#188, epic #309). A regression
|
|
# anywhere between a tool bump and a parser change turns this red before a
|
|
# customer sees it.
|
|
#
|
|
# Run it by hand with "bless" ticked after an intended change: the job then
|
|
# rewrites the baselines instead of comparing, and the new files are in the
|
|
# `nightly-report` artifact to commit.
|
|
|
|
on:
|
|
schedule:
|
|
- cron: '0 3 * * *' # 3 AM UTC daily
|
|
workflow_dispatch:
|
|
inputs:
|
|
bless:
|
|
description: "Rewrite the baselines from this run (commit them from the artifact)"
|
|
type: boolean
|
|
default: false
|
|
|
|
env:
|
|
CARGO_TERM_COLOR: always
|
|
RUSTFLAGS: "-D warnings"
|
|
RUSTC_WRAPPER: /usr/local/bin/sccache
|
|
SCCACHE_BUCKET: bp-sccache
|
|
SCCACHE_ENDPOINT: https://nbg1.your-objectstorage.com
|
|
SCCACHE_REGION: auto
|
|
SCCACHE_S3_USE_SSL: "true"
|
|
SCCACHE_S3_KEY_PREFIX: compliance-scanner
|
|
AWS_ACCESS_KEY_ID: ${{ secrets.HETZNER_S3_ACCESS_KEY }}
|
|
AWS_SECRET_ACCESS_KEY: ${{ secrets.HETZNER_S3_SECRET_KEY }}
|
|
CARGO_NET_GIT_FETCH_WITH_CLI: "true"
|
|
CARGO_NET_RETRY: "10"
|
|
CARGO_HTTP_MULTIPLEXING: "false"
|
|
|
|
concurrency:
|
|
group: nightly-scans
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
scans:
|
|
name: Scan regression
|
|
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:-refs/heads/main}"
|
|
git checkout FETCH_HEAD
|
|
|
|
- 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: ""
|
|
|
|
# The harness links compliance-agent, which depends on the private
|
|
# firmwerk repo; same PAT rewrite as in ci.yml.
|
|
- 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: ""
|
|
|
|
# The real CODESYS sample is ~10 MB, so it is fetched at a pinned commit
|
|
# and checksum rather than committed. fixtures/nightly/targets.json skips
|
|
# its target where NIGHTLY_CODESYS_SAMPLE is unset.
|
|
- name: Fetch the CODESYS sample
|
|
run: |
|
|
curl -fsSL -o /tmp/csv-blackbox.projectarchive \
|
|
"https://github.com/Proemion/codesys-examples/raw/164d8eea7b7483f764b4959788fd2a733624e576/CSV-BlackBox-Writter/CSV-BlackBox-Writter.projectarchive"
|
|
echo "8e1150728e33fc0f5e2572bc060545497cfa64308c927c0d81ecda71873db265 /tmp/csv-blackbox.projectarchive" \
|
|
| sha256sum -c -
|
|
env:
|
|
RUSTC_WRAPPER: ""
|
|
|
|
# The upstream Zephyr example application, at a pinned commit so the
|
|
# result does not drift with upstream main. codeload zips are not
|
|
# byte-stable, so the commit pin (not a checksum) is the guarantee.
|
|
- name: Fetch the Zephyr example application
|
|
run: |
|
|
curl -fsSL -o /tmp/zephyr-example.zip \
|
|
"https://codeload.github.com/zephyrproject-rtos/example-application/zip/38a6d9b276ed434454900130cacc87d058d3ac62"
|
|
env:
|
|
RUSTC_WRAPPER: ""
|
|
|
|
# Public mobile apps at pinned commits (MIT, Apache-2.0): a current
|
|
# SwiftUI app and a large Android app, so the mobile checks meet real
|
|
# projects, not only the hand-written fixtures. Not committed, as with
|
|
# the Zephyr example.
|
|
- name: Fetch the public mobile samples
|
|
run: |
|
|
curl -fsSL -o /tmp/ios-sample.zip \
|
|
"https://codeload.github.com/nalexn/clean-architecture-swiftui/zip/9eca97b8cfff96a14084b564b1fefd949c93d232"
|
|
curl -fsSL -o /tmp/android-sample.zip \
|
|
"https://codeload.github.com/android/nowinandroid/zip/a49ed253d75e61a2b6ab80a8da677b57437b08eb"
|
|
env:
|
|
RUSTC_WRAPPER: ""
|
|
|
|
# The image main deployed, started here rather than as a service:
|
|
# act_runner 0.6.1 hands a service's registry credentials to the job
|
|
# container's own pull (map order decides which service wins), so the
|
|
# Harbor login reached docker.io about every other night. mongo, the
|
|
# only service left, has no credentials. The agent shares this
|
|
# container's network: it reaches mongo by name and listens on
|
|
# localhost here. The login lands in this container's ~/.docker, which
|
|
# goes with it.
|
|
# Dev mode (no Keycloak): the harness talks to the unauthenticated dev
|
|
# tenant; source_only matches staging.
|
|
- name: Start the agent
|
|
run: |
|
|
curl -fsSL -o /tmp/docker.tgz \
|
|
https://download.docker.com/linux/static/stable/x86_64/docker-27.5.1.tgz
|
|
echo "4f798b3ee1e0140eab5bf30b0edc4e84f4cdb53255a429dc3bbae9524845d640 /tmp/docker.tgz" \
|
|
| sha256sum -c -
|
|
tar xzf /tmp/docker.tgz --strip-components=1 -C /usr/local/bin docker/docker
|
|
echo "$REGISTRY_PASSWORD" | docker login repo.breakpilot.com -u "$REGISTRY_USERNAME" --password-stdin
|
|
# -e NAME without a value passes this step's variable, so no secret
|
|
# appears on the command line. The container runs on the runner's
|
|
# daemon, outside the job's own limits, so it has its own; the label
|
|
# finds one a cancelled job left behind.
|
|
docker run -d --pull always --name "nightly-agent-${GITHUB_RUN_ID}" \
|
|
--label pruefwerk-nightly --memory 4g --cpus 2 \
|
|
--network "container:$(hostname)" \
|
|
-e APP_ENV=dev \
|
|
-e MONGODB_URI=mongodb://root:example@mongo:27017/?authSource=admin \
|
|
-e MONGODB_DATABASE=nightly \
|
|
-e PW_FEATURES=source_only \
|
|
-e LITELLM_URL -e LITELLM_API_KEY \
|
|
-e LITELLM_EMBED_MODEL=bge-multilingual-gemma2 \
|
|
-e NVD_API_KEY \
|
|
repo.breakpilot.com/pruefwerk/compliance-agent:latest
|
|
env:
|
|
RUSTC_WRAPPER: ""
|
|
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
|
|
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
|
# No chat model: LLM triage, code review and the control judge are
|
|
# off (LlmClient sends nothing without LITELLM_MODEL, #575). Their
|
|
# output never gates the run, and with the model on, ~600 calls of
|
|
# 11 s on average (p99 147 s) on the gateway prod also uses kept
|
|
# every scan past NIGHTLY_TIMEOUT_SECS from 2026-10-30 on (#573).
|
|
# Embeddings stay on: the gateway's embedding model.
|
|
LITELLM_URL: ${{ secrets.NIGHTLY_LITELLM_URL }}
|
|
LITELLM_API_KEY: ${{ secrets.NIGHTLY_LITELLM_API_KEY }}
|
|
# Optional. The CODESYS CVE match queries NVD, which rate-limits
|
|
# unauthenticated clients; a key keeps those CVEs from going missing.
|
|
NVD_API_KEY: ${{ secrets.NIGHTLY_NVD_API_KEY }}
|
|
|
|
- name: Wait for the agent
|
|
run: |
|
|
for i in $(seq 1 90); do
|
|
curl -fsS http://localhost:3001/api/v1/health && exit 0
|
|
sleep 2
|
|
done
|
|
echo "agent did not become healthy" >&2
|
|
exit 1
|
|
env:
|
|
RUSTC_WRAPPER: ""
|
|
|
|
- name: Scan the corpus and compare with the baselines
|
|
run: cargo test -p compliance-agent --test nightly -- --nocapture
|
|
env:
|
|
NIGHTLY_AGENT_URL: http://localhost:3001
|
|
NIGHTLY_CODESYS_SAMPLE: /tmp/csv-blackbox.projectarchive
|
|
NIGHTLY_ZEPHYR_EXAMPLE: /tmp/zephyr-example.zip
|
|
NIGHTLY_IOS_SAMPLE: /tmp/ios-sample.zip
|
|
NIGHTLY_ANDROID_SAMPLE: /tmp/android-sample.zip
|
|
NIGHTLY_BLESS: ${{ inputs.bless && '1' || '0' }}
|
|
|
|
# The agent is not a service, so the runner does not remove it.
|
|
- name: Stop the agent
|
|
if: always()
|
|
run: docker rm -f "nightly-agent-${GITHUB_RUN_ID}" || true
|
|
env:
|
|
RUSTC_WRAPPER: ""
|
|
|
|
# upload-artifact is a Node action and the Rust image has no node.
|
|
- name: Install node for the artifact upload
|
|
if: always()
|
|
run: |
|
|
apt-get update -qq
|
|
apt-get install -y -qq --no-install-recommends nodejs >/dev/null
|
|
env:
|
|
RUSTC_WRAPPER: ""
|
|
|
|
- name: Keep the report and this run's snapshots
|
|
if: always()
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: nightly-report
|
|
path: |
|
|
target/nightly/
|
|
fixtures/nightly/baselines/
|
|
|
|
# One open issue tracks a red nightly: opened on the first failure,
|
|
# commented on while it stays red. Needs NIGHTLY_ALERT_TOKEN (issue write
|
|
# on this repo); without it the job still fails, just without the issue.
|
|
- name: Alert
|
|
if: failure() && github.event_name == 'schedule'
|
|
env:
|
|
RUSTC_WRAPPER: ""
|
|
TOKEN: ${{ secrets.NIGHTLY_ALERT_TOKEN }}
|
|
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
|
|
run: |
|
|
if [ -z "$TOKEN" ]; then
|
|
echo "::warning::NIGHTLY_ALERT_TOKEN is not set; not opening an issue"
|
|
exit 0
|
|
fi
|
|
api="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
|
|
title="Nightly scan regression is red"
|
|
body="The nightly scan regression failed: ${RUN_URL} (report in the nightly-report artifact)."
|
|
number=$(curl -fsS -H "Authorization: token $TOKEN" \
|
|
"$api/issues?state=open&type=issues&q=$(printf %s "$title" | sed 's/ /%20/g')" \
|
|
| python3 -c "import json,sys; print(next((i['number'] for i in json.load(sys.stdin) if i['title']==sys.argv[1]), ''))" "$title")
|
|
payload=$(python3 -c "import json,sys; print(json.dumps({'title': sys.argv[1], 'body': sys.argv[2]}))" "$title" "$body")
|
|
if [ -n "$number" ]; then
|
|
curl -fsS -X POST -H "Authorization: token $TOKEN" -H "Content-Type: application/json" \
|
|
"$api/issues/$number/comments" -d "$payload" >/dev/null
|
|
else
|
|
curl -fsS -X POST -H "Authorization: token $TOKEN" -H "Content-Type: application/json" \
|
|
"$api/issues" -d "$payload" >/dev/null
|
|
fi
|