Files
pulse/.gitea/workflows/ci.yml
T
jaredandClaude Opus 5.5 921d5f6540
CI / Lint (eslint) (pull_request) Successful in 27s
CI / Test (jest) (pull_request) Successful in 26s
CI / Test (Node 20) (pull_request) Successful in 31s
CI / Security (npm audit) (pull_request) Successful in 34s
CI / Integration (api) (pull_request) Successful in 2m19s
CI / Scan (secrets, workflows, shell) (pull_request) Successful in 2m32s
CI / UI screenshots (before/after) (pull_request) Successful in 8s
CI / UI (playwright) (pull_request) Successful in 2m52s
CI / Deploy (pull_request) Skipped
CI / Deploy worker (pull_request) Skipped
CI / Notify (pull_request) Skipped
CI: run on Node 22, keep a Node 20 job during the move (#45)
Every job's container moves to node:22-bookworm (pinned by digest), so
lint, unit, integration (real server and workers), security and scan all
run on the version production is moving to. The extra job becomes
Test (Node 20), not required, covering CT 122 and CT 153 until they are
upgraded; it goes once both run Node 22.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 22:02:18 -05:00

438 lines
20 KiB
YAML

name: CI
# One pipeline: lint, unit tests, audit, scans, integration and UI tests must all pass before main deploys (#45).
# Actions are pinned to full commit SHAs (version in the trailing comment).
# Pushes build only main (which deploys); branches are built through their pull
# request. Building both pushes and pull requests of a branch ran every job twice and
# doubled the runner queue.
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 comes from each job's container image, not actions/setup-node: the runner
# shares one tool cache volume between concurrent jobs, and parallel setup-node
# runs overwrote each other's Node install mid-job. Node 22 is the target for production
# (CT 122) and the worker (CT 153); Test (Node 20) covers them until they move (#45).
jobs:
lint:
name: Lint (eslint)
runs-on: ubuntu-latest
timeout-minutes: 20 # a hung step fails instead of blocking main
container: node:22-bookworm@sha256:e13726ca604184d7a91fcacab1fc09eefd642dc28e79ac34e85540dd93b78cfb
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
persist-credentials: false # no job pushes; keep the token out of .git/config
- name: Install dependencies (lockfile only)
run: npm ci
- name: Run ESLint
run: npm run lint
- name: No em or en dashes (house style)
run: |
# Includes the vendored design system: it has been dash-free upstream since web_template#3.
if git grep -nP '[\x{2013}\x{2014}]|&[mn]dash;|\\u201[34]|&#821[12];|&#x201[34];' \
-- . ':!package-lock.json'; then
echo "::error::Em or en dashes found (listed above). Use a hyphen, colon, comma or 'to'."
exit 1
fi
test:
name: Test (jest)
runs-on: ubuntu-latest
timeout-minutes: 20
container: node:22-bookworm@sha256:e13726ca604184d7a91fcacab1fc09eefd642dc28e79ac34e85540dd93b78cfb
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
persist-credentials: false # no job pushes; keep the token out of .git/config
- name: Install dependencies (lockfile only)
run: npm ci
- name: Run jest with coverage
run: npm test -- --ci
# The unit tests on Node 20 as well, while production (CT 122, CT 153) still runs it
# during the move to Node 22 (#45). Not a required check. Remove once both hosts are on 22.
test-node20:
name: Test (Node 20)
runs-on: ubuntu-latest
timeout-minutes: 20
container: node:20-bookworm@sha256:8f693eaa7e0a8e71560c9a82b55fd54c2ae920a2ba5d2cde28bac7d1c01c9ba5
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
persist-credentials: false # no job pushes; keep the token out of .git/config
- name: Install dependencies (lockfile only)
run: npm ci
- name: Run jest
run: npx jest --ci
audit:
name: Security (npm audit)
runs-on: ubuntu-latest
timeout-minutes: 10
container: node:22-bookworm@sha256:e13726ca604184d7a91fcacab1fc09eefd642dc28e79ac34e85540dd93b78cfb
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
persist-credentials: false # no job pushes; keep the token out of .git/config
- name: Audit production and dev dependencies
run: |
# Retry only when the registry itself fails (it has returned spurious 400s);
# a real advisory fails at once.
for attempt in 1 2 3; do
if out=$(npm audit --audit-level=high 2>&1); then echo "$out"; exit 0; fi
echo "$out"
echo "$out" | grep -q "audit endpoint returned an error" || exit 1
echo "npm registry error (attempt $attempt); retrying in 20s"
sleep 20
done
exit 1
- name: Install dependencies (lockfile only)
run: npm ci --ignore-scripts
- name: Registry signatures and provenance of every installed package
run: npm audit signatures
- name: Licences of production dependencies
run: node scripts/ci/licenses.js
- name: Software bill of materials (production dependencies)
run: npm sbom --sbom-format cyclonedx --omit dev --package-lock-only > sbom.cdx.json
- name: Keep the SBOM for each main build
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: actions/upload-artifact@c6a3b2bd78b3985e4b2f15397fec357f0fd808de # v3.2.2-node20 (v4 is unsupported on Gitea)
with:
name: sbom-cyclonedx
path: sbom.cdx.json
retention-days: 90
integration:
name: Integration (api)
runs-on: ubuntu-latest
timeout-minutes: 25
container: node:22-bookworm@sha256:e13726ca604184d7a91fcacab1fc09eefd642dc28e79ac34e85540dd93b78cfb # the server and workers on Node 22, production's target
env:
DB_HOST: 127.0.0.1
DB_PORT: '3306'
DB_NAME: pulse
DB_USER: pulse
DB_PASSWORD: ci-only # throwaway database inside the job container
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
persist-credentials: false # no job pushes; keep the token out of .git/config
- name: Install dependencies (lockfile only)
run: npm ci
- name: Start MariaDB
run: scripts/ci/mariadb.sh
- name: Start Pulse with three workers
run: scripts/ci/ui-stack.sh start
- name: Run integration tests (Gandalf contract, auth, reliability)
run: npm run test:integration -- --ci
- name: Server and worker logs
if: always()
run: tail -n 200 .ui-stack/*.log || true
scan:
name: Scan (secrets, workflows, shell)
runs-on: ubuntu-latest
timeout-minutes: 20
container: node:22-bookworm@sha256:e13726ca604184d7a91fcacab1fc09eefd642dc28e79ac34e85540dd93b78cfb
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
persist-credentials: false # no job pushes; keep the token out of .git/config
fetch-depth: 0 # gitleaks scans the whole history, not just this commit
- 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 # venv: zizmor and semgrep
- 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, so new rules can surface new
# findings: fix them, 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
# Pulse's own rules must still catch their test cases before they're trusted.
/tmp/semgrep/bin/semgrep --metrics=off --test --config .semgrep/pulse.yml .semgrep/pulse.js
/tmp/semgrep/bin/semgrep scan --metrics=off --error \
--config .semgrep/pulse.yml \
--config p/javascript --config p/nodejs --config p/expressjs \
--config p/secrets --config p/security-audit \
--exclude public/web_template --exclude node_modules --exclude .semgrep/pulse.js
ui:
name: UI (playwright)
runs-on: ubuntu-latest
timeout-minutes: 30
# Official image with Chromium and its system libraries; its version must match
# @playwright/test in package.json.
container: mcr.microsoft.com/playwright:v1.64.1-noble@sha256:2f05f8a734509a7b3f26a912639488ee08f58a7b292d14d62271bcff9038768f
env:
DB_HOST: 127.0.0.1
DB_PORT: '3306'
DB_NAME: pulse
DB_USER: pulse
DB_PASSWORD: ci-only # throwaway database inside the job container
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
persist-credentials: false # no job pushes; keep the token out of .git/config
- name: Install dependencies (lockfile only)
run: npm ci
- name: Start MariaDB
run: scripts/ci/mariadb.sh
- name: Start Pulse with three workers
run: scripts/ci/ui-stack.sh start
- name: Run Playwright (desktop and mobile)
run: npm run test:ui
- name: Server and worker logs
if: always()
run: tail -n 200 .ui-stack/*.log || true
- name: Upload report, traces and screenshots
if: failure()
uses: actions/upload-artifact@c6a3b2bd78b3985e4b2f15397fec357f0fd808de # v3.2.2-node20 (v4 is unsupported on Gitea)
with:
name: playwright-report
path: |
playwright-report/
test-results/
retention-days: 14
ui-screenshots:
name: UI screenshots (before/after)
runs-on: ubuntu-latest
timeout-minutes: 30
if: github.event_name == 'pull_request'
container: mcr.microsoft.com/playwright:v1.64.1-noble@sha256:2f05f8a734509a7b3f26a912639488ee08f58a7b292d14d62271bcff9038768f
env:
DB_HOST: 127.0.0.1
DB_PORT: '3306'
DB_NAME: pulse
DB_USER: pulse
DB_PASSWORD: ci-only
BASE_SHA: ${{ github.event.pull_request.base.sha }}
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
persist-credentials: false # no job pushes; keep the token out of .git/config
fetch-depth: 0
- name: Did this PR change the UI?
id: ui
run: |
if git diff --quiet "$BASE_SHA" HEAD -- public/ views/ lib/render.js lib/nav.js; then
echo "No UI files changed; no screenshots needed."
else
echo "changed=true" >> "$GITHUB_OUTPUT"
fi
- name: Start MariaDB
if: steps.ui.outputs.changed == 'true'
run: |
scripts/ci/mariadb.sh
mariadb -e "CREATE DATABASE pulse_base; GRANT ALL ON pulse_base.* TO 'pulse'@'127.0.0.1';"
- name: Start this PR's Pulse (port 8400)
if: steps.ui.outputs.changed == 'true'
run: npm ci && scripts/ci/ui-stack.sh start
- name: Start the base branch's Pulse (port 8401)
if: steps.ui.outputs.changed == 'true'
run: |
git worktree add /tmp/base "$BASE_SHA"
cd /tmp/base && npm ci
DB_NAME=pulse_base PULSE_UI_PORT=8401 scripts/ci/ui-stack.sh start
- name: Capture before/after screenshots
if: steps.ui.outputs.changed == 'true'
run: node scripts/ci/screenshots.js ui-screenshots before=http://127.0.0.1:8401 after=http://127.0.0.1:8400
- name: Upload screenshots
if: steps.ui.outputs.changed == 'true'
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, audit, scan, integration, ui]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
# Never run two deploys at once; queue instead of cancelling a deploy mid-way.
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: |
# sha and timestamp make every signature unique; the server starts
# verifying them in #45 phase 2 (until then it deploys origin/main).
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.65:9000/hooks/pulse-deploy"
- name: Verify production runs this commit
env:
GIT_SHA: ${{ github.sha }}
run: |
# The webhook returns at once; the server-side deploy script checks out
# this exact sha, runs npm ci and restarts, and rolls back if /healthz
# never reports it. Succeed only when production reports this sha with
# a working database (up to 4 minutes, covering npm ci).
for _ in $(seq 1 48); do
body=$(curl -fsS --connect-timeout 5 --max-time 5 http://10.10.10.65:8080/healthz || true)
if echo "$body" | grep -q "\"sha\":\"${GIT_SHA}\"" && echo "$body" | grep -q '"db":true'; then
echo "Production is healthy on ${GIT_SHA}: ${body}"
exit 0
fi
sleep 5
done
echo "::error::Production never reported ${GIT_SHA} as healthy (last /healthz: ${body:-no response}). The server rolls back automatically; see /var/log/pulse-deploy.log on CT 122."
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}"
curl -sf -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"
deploy-worker:
name: Deploy worker
runs-on: ubuntu-latest
timeout-minutes: 15
container: node:22-bookworm@sha256:e13726ca604184d7a91fcacab1fc09eefd642dc28e79ac34e85540dd93b78cfb
needs: [deploy] # the server first: it must understand anything new the worker sends
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
concurrency:
group: deploy-worker
cancel-in-progress: false
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
persist-credentials: false # no job pushes; keep the token out of .git/config
fetch-depth: 0 # to compare against the commit the worker runs now
- name: Did the worker change since the running version?
id: changed
env:
GIT_SHA: ${{ github.sha }}
run: |
# Restarting the worker briefly interrupts Gandalf's commands, so only
# deploy when worker code or its dependencies changed (#40). The lockfile
# changes with every dependency change; package.json alone (scripts) doesn't matter.
running=$(curl -fsS --max-time 5 http://10.10.10.65:8080/healthz \
| node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>console.log((JSON.parse(s).worker_versions||[]).join(" ")))')
echo "Workers run: ${running:-none}"
deploy=false
[ -n "$running" ] || deploy=true
for v in $running; do
if ! git cat-file -e "${v}^{commit}" 2>/dev/null \
|| ! git diff --quiet "$v" "$GIT_SHA" -- worker/ package-lock.json; then
deploy=true
fi
done
echo "deploy=$deploy" >> "$GITHUB_OUTPUT"
echo "Deploy the worker: $deploy"
- name: Trigger worker webhook
if: steps.changed.outputs.deploy == 'true'
env:
WEBHOOK_SECRET: ${{ secrets.WORKER_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.151:9000/hooks/pulse-worker-deploy"
- name: Verify the worker reconnected on this commit
if: steps.changed.outputs.deploy == 'true'
env:
GIT_SHA: ${{ github.sha }}
run: |
# deploy/pulse_worker_deploy.sh on CT 153 installs this sha, restarts the
# worker, and restores the previous files if it never reconnects.
for _ in $(seq 1 48); do
body=$(curl -fsS --connect-timeout 5 --max-time 5 http://10.10.10.65:8080/healthz || true)
if echo "$body" | grep -Eq "\"worker_versions\":\[[^]]*\"${GIT_SHA}\""; then
echo "Worker connected on ${GIT_SHA}: ${body}"
exit 0
fi
sleep 5
done
echo "::error::The worker never reconnected on ${GIT_SHA} (last /healthz: ${body:-no response}). See /var/log/pulse-worker-deploy.log on CT 153."
exit 1
notify:
name: Notify
runs-on: ubuntu-latest
timeout-minutes: 5
needs: [lint, test, audit, scan, integration, ui, deploy, deploy-worker]
# Alert on any failure on main or in the weekly audit, and on every deploy outcome.
if: >-
always() && (
(failure() && (github.ref == 'refs/heads/main' || github.event_name == 'schedule')) ||
needs.deploy.result == 'success'
)
steps:
- name: Send Matrix alert
env:
MATRIX_WEBHOOK_URL: ${{ secrets.MATRIX_WEBHOOK_URL }}
REPO: ${{ github.repository }}
BRANCH: ${{ github.ref_name }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
RESULTS: "lint=${{ needs.lint.result }} test=${{ needs.test.result }} audit=${{ needs.audit.result }} scan=${{ needs.scan.result }} integration=${{ needs.integration.result }} ui=${{ needs.ui.result }} deploy=${{ needs.deploy.result }} worker=${{ needs.deploy-worker.result }}"
DEPLOYED: ${{ needs.deploy.result == 'success' }}
run: |
if [ -z "$MATRIX_WEBHOOK_URL" ] || [ "$MATRIX_WEBHOOK_URL" = "CONFIGURE_ME" ]; then exit 0; fi
if [ "$DEPLOYED" = "true" ]; then MSG="DEPLOYED: ${REPO} @ ${BRANCH} (${GITHUB_SHA:0:7})"; else MSG="CI FAILED: ${REPO} @ ${BRANCH} [${RESULTS}]"; fi
curl -sf -X POST "$MATRIX_WEBHOOK_URL" \
-H "Content-Type: application/json" \
-d "{\"text\":\"${MSG}: ${RUN_URL}\"}"