diff --git a/.gitea/workflows/baseline-pr-check.yml b/.gitea/workflows/baseline-pr-check.yml new file mode 100644 index 0000000..f1fa8a4 --- /dev/null +++ b/.gitea/workflows/baseline-pr-check.yml @@ -0,0 +1,99 @@ +# Forge standards baseline PR check (Hoppe.home, 2026-11-22). Copy to .gitea/workflows/baseline-pr-check.yml +# in a repo; see forge-standards/README.md and ROLLOUT.md. +# +# Required status check name (Gitea context): baseline-pr-check / baseline (pull_request) +# Keep BOTH the workflow `name:` and the job id `baseline` unchanged, or the required check never reports. +# +# Design: same pattern as the codebox-ci hygiene job (.gitea/workflows/ci.yml): label linux-python, treeless +# clone into /tmp/src with the job's own token (the job workspace is not writable and there is no checkout +# action), no third-party action, no repository secret, read-only. Looks only at files the PR adds or changes +# (trash patterns also at path level), so old debt never blocks an unrelated PR. +# Runner image (per ci.yml header, NOT re-verified here): python 3.12, git, ruff, detect-secrets 1.5.0. +name: baseline-pr-check + +on: + pull_request: + branches: [main] + +permissions: + contents: read + +concurrency: + group: baseline-pr-check-${{ github.ref }} + cancel-in-progress: true + +jobs: + baseline: + runs-on: linux-python + timeout-minutes: 5 + steps: + - name: checkout (treeless clone, diff against base) + working-directory: /tmp + env: + GIT_CONFIG_COUNT: "1" + GIT_CONFIG_KEY_0: http.extraHeader + GIT_CONFIG_VALUE_0: "Authorization: token ${{ github.token }}" + run: | + set -eu + git init -q /tmp/src && cd /tmp/src + git remote add origin "${{ github.server_url }}/${{ github.repository }}.git" + git fetch -q --filter=blob:none origin "${{ github.base_ref }}" "${{ github.sha }}" + git checkout -q FETCH_HEAD + git fetch -q origin "${{ github.base_ref }}:refs/remotes/origin/${{ github.base_ref }}" + git diff --name-only --diff-filter=ACMR "origin/${{ github.base_ref }}...HEAD" > /tmp/changed.txt + echo "changed or added files: $(wc -l < /tmp/changed.txt)" + + - name: trash check (files this PR adds or changes) + working-directory: /tmp/src + run: | + set -eu + # Patterns mirror CLAUDE.md rule 10 ("never commit trash") and the secret-file ban. + # Opt-out for a deliberate file: list its exact path in .gitea/baseline-allow.txt (one per line). + allow=/dev/null; [ -f .gitea/baseline-allow.txt ] && allow=.gitea/baseline-allow.txt + bad=0 + while IFS= read -r f; do + [ -z "$f" ] && continue + grep -qxF -- "$f" "$allow" && continue + case "$f" in + *.bak|*.bak.*|*.bak[0-9]*|*.orig|*.rej) why="backup/merge leftover" ;; + *.log) why="log file" ;; + *.pyc|*/__pycache__/*|__pycache__/*) why="python bytecode" ;; + node_modules/*|*/node_modules/*) why="node_modules" ;; + db/archive/*|*/db/archive/*|*.dump|*.sql.gz) why="database archive/dump" ;; + .env|*/.env|.env.*|*/.env.*) case "$f" in *.example|*.sample|*.template) continue ;; esac; why="env file" ;; + *.pem|*.key|*.pfx|*.p12) why="key or certificate material" ;; + *) continue ;; + esac + echo "::error file=$f::trash/secret file not allowed ($why)" + bad=1 + done < /tmp/changed.txt + if [ "$bad" -ne 0 ]; then + echo "Remove the file(s), or if deliberate list the exact path in .gitea/baseline-allow.txt." + exit 1 + fi + echo "trash check: clean" + + - name: secret scan (changed files) + working-directory: /tmp/src + run: | + set -eu + [ -s /tmp/changed.txt ] || { echo "no changed files"; exit 0; } + if command -v detect-secrets-hook >/dev/null 2>&1; then + # With the repo's baseline when present (known, audited findings are tolerated), else a plain scan. + base=""; [ -f .secrets.baseline ] && base="--baseline .secrets.baseline" + xargs -d '\n' detect-secrets-hook $base < /tmp/changed.txt + echo "detect-secrets: clean" + else + # Documented fallback (runner image without detect-secrets): high-confidence shapes only, + # so it fails on real findings, not on words like "password" in docs. + echo "detect-secrets not on this runner: using the grep fallback" + pat='-----BEGIN ((RSA|EC|DSA|OPENSSH|PGP) )?PRIVATE KEY-----|AKIA[0-9A-Z]{16}|gh[pousr]_[A-Za-z0-9]{36,}|xox[baprs]-[A-Za-z0-9-]{10,}|hvs\.[A-Za-z0-9]{20,}|sk-[A-Za-z0-9]{32,}|(password|passwd|secret|api[_-]?key|token)[A-Za-z0-9_]*[[:space:]]*[:=][[:space:]]*["'"'"'][A-Za-z0-9/+_.=-]{20,}["'"'"']' + hits=$(xargs -d '\n' grep -InEH -e "$pat" < /tmp/changed.txt 2>/dev/null || true) + if [ -n "$hits" ]; then + # Print file:line only, never the matched value. + echo "$hits" | cut -d: -f1,2 | sed 's/^/possible secret at /' + echo "If a hit is a false positive, add the repo's detect-secrets baseline instead of weakening this check." + exit 1 + fi + echo "grep fallback: clean" + fi