CI / Lint (eslint) (push) Successful in 46s
CI / Security (npm audit) (push) Successful in 26s
CI / Integration (api) (push) Successful in 1m31s
CI / Test (jest) (pull_request) Successful in 50s
CI / UI (playwright) (push) Successful in 2m31s
CI / Integration (api) (pull_request) Successful in 1m58s
CI / Test (jest) (push) Successful in 13s
CI / Deploy (push) Skipped
CI / Notify (push) Skipped
CI / UI (playwright) (pull_request) Successful in 2m16s
CI / Lint (eslint) (pull_request) Successful in 15s
CI / Security (npm audit) (pull_request) Successful in 15s
CI / Deploy (pull_request) Skipped
CI / Notify (pull_request) Skipped
New CI job `Integration (api)` (#45 phase 3) runs the real server and three workers on Node 20 against MariaDB and tests them as a black box over HTTP and WebSocket (20 tests, about 12 s): - Gandalf contract: submit and poll, stdout from command_result, failures with exit code and stderr, 401 for wrong or missing key, 400 for missing fields or an unknown worker, 404 for an unknown execution - Auth: SSO identity, 401/403, heartbeat key, /healthz exposes only status; WebSocket upgrade refused without credentials, with a wrong key or a wrong group; live events reach a signed-in browser; a browser socket cannot forge a command result - Reliability: a worker killed mid-command fails the execution at once; a worker at capacity answers with a failure; an aborted execution stays failed when the late result arrives; a disconnected worker shows offline The last test found a bug from #42: the close handler deleted the worker's runtime-id entry before checking whether the socket was still live under its database id, and the two ids are normally the same key. So a disconnected worker was never marked offline and showed 'online' until the stale heartbeat sweep. Gandalf was unaffected (it checks live sockets). MariaDB setup for CI moves to scripts/ci/mariadb.sh, shared by both jobs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
209 lines
8.2 KiB
YAML
209 lines
8.2 KiB
YAML
name: CI
|
|
|
|
# One pipeline: lint, unit tests, audit, integration and UI tests must all pass before main deploys (#45).
|
|
# Actions are pinned to full commit SHAs (version in the trailing comment).
|
|
|
|
on:
|
|
push:
|
|
branches: ["**"]
|
|
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:20 matches production
|
|
# (CT 122) and the worker (CT 153).
|
|
|
|
jobs:
|
|
lint:
|
|
name: Lint (eslint)
|
|
runs-on: ubuntu-latest
|
|
container: node:20-bookworm
|
|
steps:
|
|
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
|
|
- name: Install dependencies (lockfile only)
|
|
run: npm ci
|
|
- name: Run ESLint
|
|
run: npm run lint
|
|
- name: No em or en dashes (house style)
|
|
run: |
|
|
# Pulse-owned files only: the vendored design system is fixed upstream.
|
|
if git grep -nP '[\x{2013}\x{2014}]|&[mn]dash;|\\u201[34]|̵[12];|ȁ[34];' \
|
|
-- . ':!public/web_template' ':!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
|
|
container: node:20-bookworm
|
|
steps:
|
|
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
|
|
- name: Install dependencies (lockfile only)
|
|
run: npm ci
|
|
- name: Run jest with coverage
|
|
run: npm test -- --ci
|
|
|
|
audit:
|
|
name: Security (npm audit)
|
|
runs-on: ubuntu-latest
|
|
container: node:20-bookworm
|
|
steps:
|
|
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
|
|
- name: Audit production and dev dependencies
|
|
run: npm audit --audit-level=high
|
|
|
|
integration:
|
|
name: Integration (api)
|
|
runs-on: ubuntu-latest
|
|
container: node:20-bookworm # the server and workers on production's Node
|
|
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
|
|
- 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
|
|
|
|
ui:
|
|
name: UI (playwright)
|
|
runs-on: ubuntu-latest
|
|
# 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
|
|
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
|
|
- 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
|
|
|
|
deploy:
|
|
name: Deploy
|
|
runs-on: ubuntu-latest
|
|
needs: [lint, test, audit, 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 i 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: |
|
|
TAG="deploy-$(date -u +%Y.%m.%d)-${{ github.run_number }}"
|
|
curl -sf -X POST \
|
|
-H "Authorization: token $GITHUB_TOKEN" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"tag_name\":\"${TAG}\",\"target\":\"${{ github.sha }}\",\"message\":\"Deployed to production\"}" \
|
|
"https://code.lotusguild.org/api/v1/repos/${{ github.repository }}/tags"
|
|
|
|
notify:
|
|
name: Notify
|
|
runs-on: ubuntu-latest
|
|
needs: [lint, test, audit, integration, ui, deploy]
|
|
# 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 }} integration=${{ needs.integration.result }} ui=${{ needs.ui.result }} deploy=${{ needs.deploy.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}\"}"
|