Files
thor/.gitea/workflows/ci.yml
T
jaredandClaude Opus 5.5 2f7623840c
CI / Lint (flake8, house style) (pull_request) Successful in 1m26s
CI / Test (pytest) (pull_request) Successful in 1m28s
CI / Scan (secrets, workflows, shell, patterns) (pull_request) Successful in 1m31s
CI / Integration (MariaDB) (pull_request) Successful in 2m1s
CI / UI (screenshots) (pull_request) Successful in 3m2s
CI / Security (bandit, pip-audit) (pull_request) Successful in 1m13s
CI / Deploy (pull_request) Skipped
CI: run the UI screenshot job in the Node-based Playwright image
actions/checkout needs Node, which the Python-only image lacks. Use mcr.microsoft.com/playwright
(same browser build as the pip pin) and add Python in a venv; wait for the demo server with
Python instead of curl.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 13:07:25 -05:00

230 lines
10 KiB
YAML

name: CI
# One pipeline, modelled on Pulse's: lint, unit tests, integration tests against MariaDB,
# security checks and scans must all pass before main deploys. Actions are pinned to full
# commit SHAs and the job image to a digest (version in the trailing comment).
# Pushes build only main (which deploys); branches are built through their pull request.
on:
push:
branches: [main]
pull_request:
branches: ["**"]
schedule:
- cron: '0 6 * * 1' # weekly dependency audit against new advisories
permissions:
contents: read
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
# node:22-trixie: Node for the checkout action, Debian trixie for Python 3.13 (production).
jobs:
lint:
name: Lint (flake8, house style)
runs-on: ubuntu-latest
timeout-minutes: 15
container: node:22-trixie@sha256:f92a4668ece057eff6b83ed531b5f6277892b5c8fa8c1df4ea4ef470bf92b91e
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
persist-credentials: false
- name: Python environment
run: scripts/ci/python-env.sh
- name: flake8
run: /tmp/venv/bin/flake8 .
- name: No em or en dashes (house style)
run: |
if git grep -nP '[\x{2013}\x{2014}]|&[mn]dash;|\\u201[34]|&#821[12];|&#x201[34];' -- .; then
echo "::error::Em or en dashes found (listed above). Use a hyphen, colon, comma or 'to'."
exit 1
fi
test:
name: Test (pytest)
runs-on: ubuntu-latest
timeout-minutes: 15
container: node:22-trixie@sha256:f92a4668ece057eff6b83ed531b5f6277892b5c8fa8c1df4ea4ef470bf92b91e
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
persist-credentials: false
- name: Python environment
run: scripts/ci/python-env.sh
- name: pytest with coverage
run: /tmp/venv/bin/python -m pytest -W error::DeprecationWarning --cov=thor --cov-report=term-missing --cov-fail-under=90
integration:
name: Integration (MariaDB)
runs-on: ubuntu-latest
timeout-minutes: 20
container: node:22-trixie@sha256:f92a4668ece057eff6b83ed531b5f6277892b5c8fa8c1df4ea4ef470bf92b91e
env:
DB_NAME: thor
DB_USER: thor
DB_PASSWORD: ci-only # throwaway database inside the job container
THOR_TEST_DB_HOST: 127.0.0.1
THOR_TEST_DB_PASSWORD: ci-only
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
persist-credentials: false
- name: Python environment
run: scripts/ci/python-env.sh
- name: Start MariaDB
run: scripts/ci/mariadb.sh
- name: Database tests
run: /tmp/venv/bin/python -m pytest -W error::DeprecationWarning tests/test_db_mariadb.py -v
security:
name: Security (bandit, pip-audit)
runs-on: ubuntu-latest
timeout-minutes: 15
container: node:22-trixie@sha256:f92a4668ece057eff6b83ed531b5f6277892b5c8fa8c1df4ea4ef470bf92b91e
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
persist-credentials: false
- name: Python environment
run: scripts/ci/python-env.sh
- name: bandit
run: /tmp/venv/bin/bandit -q -r thor -ll
- name: pip-audit (runtime dependencies)
run: /tmp/venv/bin/pip-audit -r requirements.txt --progress-spinner off
scan:
name: Scan (secrets, workflows, shell, patterns)
runs-on: ubuntu-latest
timeout-minutes: 20
container: node:22-trixie@sha256:f92a4668ece057eff6b83ed531b5f6277892b5c8fa8c1df4ea4ef470bf92b91e
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
persist-credentials: false
fetch-depth: 0 # gitleaks scans the whole history
- name: Install scanners (pinned versions, verified checksums)
run: |
cd /tmp
curl -fsSLo gitleaks.tgz https://github.com/gitleaks/gitleaks/releases/download/v8.30.1/gitleaks_8.30.1_linux_x64.tar.gz
echo "551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb gitleaks.tgz" | sha256sum -c
curl -fsSLo actionlint.tgz https://github.com/rhysd/actionlint/releases/download/v1.7.12/actionlint_1.7.12_linux_amd64.tar.gz
echo "8aca8db96f1b94770f1b0d72b6dddcb1ebb8123cb3712530b08cc387b349a3d8 actionlint.tgz" | sha256sum -c
tar -xzf gitleaks.tgz -C /usr/local/bin gitleaks
tar -xzf actionlint.tgz -C /usr/local/bin actionlint
apt-get update -qq
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends shellcheck python3-venv >/dev/null
- name: Secrets in code and history (gitleaks)
run: gitleaks git --no-banner --redact --exit-code 1 .
- name: Workflow files (actionlint, with shellcheck on run scripts)
run: actionlint .gitea/workflows/*.yml
- name: Shell scripts (shellcheck)
run: git ls-files -z '*.sh' | xargs -0 shellcheck
- name: Workflow security (zizmor)
run: |
python3 -m venv /tmp/zizmor && /tmp/zizmor/bin/pip install -q zizmor==1.32.0
/tmp/zizmor/bin/zizmor --offline --format plain .gitea/workflows/*.yml
- name: Vendored design system matches upstream
run: scripts/ci/check-web-template.sh
- name: Code patterns (semgrep)
# Rule packs come from the semgrep registry. Fix new findings, or suppress one line
# with `nosemgrep: <rule id>` and a reason.
run: |
python3 -m venv /tmp/semgrep && /tmp/semgrep/bin/pip install -q semgrep==1.184.0
/tmp/semgrep/bin/semgrep scan --metrics=off --error \
--config p/python --config p/flask --config p/secrets --config p/security-audit \
--exclude tests
ui:
name: UI (screenshots)
runs-on: ubuntu-latest
timeout-minutes: 20
# Node (for the checkout action), Chromium and its system libraries. The browser build must
# match the playwright pip pin below; Python is added in the first step.
container: mcr.microsoft.com/playwright:v1.49.1-noble@sha256:70e367e0cbf60340a5b5fd562f6247a34eb3196efab9f88a3dd56482d9fe09d2
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
persist-credentials: false
- name: Python and dependencies
run: |
apt-get update -qq
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends python3 python3-venv >/dev/null
python3 -m venv /tmp/venv
/tmp/venv/bin/pip install --quiet --disable-pip-version-check -r requirements.txt playwright==1.49.1
- name: Every page renders with replay data (desktop and mobile, dark and light)
run: |
/tmp/venv/bin/python scripts/ui_demo.py 8811 > /tmp/ui-demo.log 2>&1 &
for _ in $(seq 1 60); do
/tmp/venv/bin/python -c 'import urllib.request; urllib.request.urlopen("http://127.0.0.1:8811/", timeout=2)' 2>/dev/null && break
sleep 1
done
/tmp/venv/bin/python scripts/screenshots.py http://127.0.0.1:8811 ui-screenshots
- name: Demo server log
if: always()
run: tail -n 100 /tmp/ui-demo.log || true
- name: Upload screenshots
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@c6a3b2bd78b3985e4b2f15397fec357f0fd808de # v3.2.2-node20 (v4 is unsupported on Gitea)
with:
name: ui-screenshots
path: ui-screenshots/
retention-days: 30
deploy:
name: Deploy
runs-on: ubuntu-latest
timeout-minutes: 15
needs: [lint, test, integration, security, scan, ui]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
concurrency:
group: deploy-production
cancel-in-progress: false
permissions:
contents: write # deploy tag
steps:
- name: Trigger webhook
env:
WEBHOOK_SECRET: ${{ secrets.WEBHOOK_SECRET }}
GIT_REF: ${{ github.ref }}
GIT_SHA: ${{ github.sha }}
run: |
PAYLOAD="{\"ref\":\"${GIT_REF}\",\"sha\":\"${GIT_SHA}\",\"ts\":$(date +%s)}"
SIG=$(echo -n "$PAYLOAD" | openssl dgst -sha256 -hmac "$WEBHOOK_SECRET" | awk '{print $2}')
curl -sf --connect-timeout 10 -X POST \
-H "Content-Type: application/json" \
-H "X-Gitea-Signature: ${SIG}" \
-d "$PAYLOAD" \
"http://10.10.10.86:9000/hooks/thor-deploy"
- name: Verify production runs this commit
env:
GIT_SHA: ${{ github.sha }}
run: |
# thor_deploy.sh checks out this sha, installs dependencies, restarts, and rolls
# back if /health never reports it with a working database.
for _ in $(seq 1 48); do
body=$(curl -sS --connect-timeout 5 --max-time 5 http://10.10.10.86/health || true)
if echo "$body" | grep -Eq "\"sha\": ?\"${GIT_SHA}\"" && echo "$body" | grep -Eq '"db": ?true'; then
echo "Production runs ${GIT_SHA}: ${body}"
exit 0
fi
sleep 5
done
echo "::error::Production never reported ${GIT_SHA} (last /health: ${body:-no response}). See /var/log/thor-deploy.log on CT 173."
exit 1
- name: Tag deployed commit
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RUN_NUMBER: ${{ github.run_number }}
GIT_SHA: ${{ github.sha }}
REPO: ${{ github.repository }}
run: |
TAG="deploy-$(date -u +%Y.%m.%d)-${RUN_NUMBER}"
code=$(curl -s -o /tmp/tag.json -w '%{http_code}' -X POST \
-H "Authorization: token $GITHUB_TOKEN" -H "Content-Type: application/json" \
-d "{\"tag_name\":\"${TAG}\",\"target\":\"${GIT_SHA}\",\"message\":\"Deployed to production\"}" \
"https://code.lotusguild.org/api/v1/repos/${REPO}/tags")
if [ "$code" = 201 ] || [ "$code" = 409 ]; then echo "Tag ${TAG}: HTTP ${code}"; exit 0; fi
cat /tmp/tag.json; exit 1