162 lines
6.3 KiB
YAML
162 lines
6.3 KiB
YAML
name: Nightly scan regression
|
|
|
|
# Scans the fixture corpus (fixtures/demo-targets) 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
|
|
# The image main deployed. Dev mode (no Keycloak): the harness talks to
|
|
# the unauthenticated dev tenant; source_only matches staging.
|
|
agent:
|
|
image: repo.breakpilot.com/pruefwerk/compliance-agent:latest
|
|
credentials:
|
|
username: ${{ secrets.REGISTRY_USERNAME }}
|
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
|
env:
|
|
APP_ENV: dev
|
|
MONGODB_URI: mongodb://root:example@mongo:27017/?authSource=admin
|
|
MONGODB_DATABASE: nightly
|
|
PW_FEATURES: source_only
|
|
# Optional. Without an LLM the control judge stamps no control refs,
|
|
# which the report lists as advisory; it never fails the run.
|
|
LITELLM_URL: ${{ secrets.NIGHTLY_LITELLM_URL }}
|
|
LITELLM_API_KEY: ${{ secrets.NIGHTLY_LITELLM_API_KEY }}
|
|
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: ""
|
|
|
|
- name: Wait for the agent
|
|
run: |
|
|
for i in $(seq 1 90); do
|
|
curl -fsS http://agent: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://agent:3001
|
|
NIGHTLY_BLESS: ${{ inputs.bless && '1' || '0' }}
|
|
|
|
- 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
|