CI / Lint (PHP 8.4, phpcs, eslint) (pull_request) Successful in 1m17s
CI / Scan (secrets, workflows, shell, patterns) (pull_request) Successful in 1m58s
CI / API and MCP (PHP 8.4, MariaDB) (pull_request) Successful in 1m56s
CI / UI (playwright) (pull_request) Successful in 2m10s
CI / Security (composer and npm audit) (pull_request) Successful in 1m42s
CI / Deploy (pull_request) Skipped
CI / Notify (pull_request) Skipped
CI / UI screenshots (before/after) (pull_request) Successful in 5m3s
Replaces lint.yml and security.yml with .gitea/workflows/ci.yml, following the shared CI standard (wiki: Infrastructure/ci-standard, modelled on Pulse and Thor). Deploys now wait for every check. Jobs: - Lint: php -l on every file and scripts/check_requirements.php under PHP 8.4 (node:22-trixie, Debian 13's packages, as on CT 132); phpcs 4.0.4 pinned with SHA-256 (was the abandoned squizlabs build, unpinned); eslint 8.57.1 from tests/lint/ (lockfile, was `npm install eslint@8`) with --max-warnings=66, today's count, so warnings can only go down. - Security: composer validate --strict, composer audit --locked --abandoned=fail, npm audit (high) and audit signatures for the test tooling. The audit found symfony/http-client advisories (fixed by the lock bump, #137) and mcp/sdk GHSA-f4rf-6ghj-mhr6, ignored with its reason in composer.json until #138 (Tinker uses neither affected middleware). - Scan: gitleaks over the full history (#134; the five findings in 527 commits were the YOUR_API_KEY placeholder on the API keys page, allowlisted for that file only in .gitleaks.toml), actionlint, shellcheck, zizmor, and semgrep with p/javascript, p/secrets and p/security-audit added to the existing packs (no new findings). - API and MCP: fresh MariaDB, migrations, seed, fixtures; then tests/api/mcp_test.php (MCP comment and link tools, 30 checks) and tests/api/test_api.py (the Bearer API contract automated reporters rely on, 132 checks: dedup by key and title, escalation, the reopen window under three Workflow Designer setups, recurrence chains, concurrent creates, lookup by dedup_key, source filter, link API). These were the local checks of #124/#131 and #121/#124. - UI and UI screenshots as before (#120). - API and UI fail on any PHP warning, notice or deprecation in the server log (tests/ci/php-warnings.sh): #130's warnings logged while every page still rendered. - Every job has a timeout; runs are grouped per ref; deploys queue and are never cancelled; the weekly run re-audits and re-scans. - Notify: Matrix alert on any failure on a deploy branch or in the weekly run, and on every deploy (was: lint failures only). tests/ui/setup.sh moves to tests/ci/setup.sh (the lint, audit and API jobs use it too) and takes WITH_DB=0 and EXTRA_PKGS. Co-Authored-By: Claude Opus 5.5 <[email protected]>
335 lines
16 KiB
YAML
335 lines
16 KiB
YAML
name: CI
|
|
|
|
# One pipeline (#136; the standard is wiki: Infrastructure/ci-standard, modelled
|
|
# on Pulse and Thor): lint, dependency audit, scans, API and MCP tests against
|
|
# MariaDB, and Playwright UI tests must all pass before beta or production
|
|
# deploys. Actions are pinned to full commit SHAs (version in the trailing comment).
|
|
|
|
# Pushes build only the two deploy branches (development -> beta, main ->
|
|
# production); other branches build through their pull request, so nothing
|
|
# runs twice. The weekly run catches new advisories and re-scans the history.
|
|
on:
|
|
push:
|
|
branches: [main, development]
|
|
pull_request:
|
|
branches: ["**"]
|
|
schedule:
|
|
- cron: '0 6 * * 1'
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
concurrency:
|
|
group: ci-${{ github.ref }}
|
|
cancel-in-progress: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/development' }}
|
|
|
|
# Job images: node:22-trixie is Debian 13, whose PHP 8.4 packages are the ones
|
|
# production runs (CT 132), and it has the Node that actions/checkout needs.
|
|
# No setup-node/setup-php: the runner shares one tool cache between concurrent
|
|
# jobs, and parallel setup actions overwrite each other's installs.
|
|
|
|
jobs:
|
|
lint:
|
|
name: Lint (PHP 8.4, phpcs, eslint)
|
|
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 # no job pushes; keep the token out of .git/config
|
|
- name: Install PHP 8.4
|
|
run: WITH_DB=0 tests/ci/setup.sh
|
|
- name: Every PHP file parses on PHP 8.4 (production's version)
|
|
run: |
|
|
git config --global --add safe.directory "$PWD"
|
|
git ls-files -z '*.php' | xargs -0 -n1 -P4 php -l -d display_errors=stderr > /dev/null
|
|
- name: Runtime requirements (version and extensions)
|
|
run: php scripts/check_requirements.php
|
|
- name: phpcs (pinned, verified checksum)
|
|
run: |
|
|
curl -fsSLo /tmp/phpcs.phar https://github.com/PHPCSStandards/PHP_CodeSniffer/releases/download/4.0.4/phpcs.phar
|
|
echo "4b010cd21d8bc8a17e2504792e3c77ef8259126f24caf7eafe7eddef1fa871e9 /tmp/phpcs.phar" | sha256sum -c
|
|
php /tmp/phpcs.phar --standard=.phpcs.xml .
|
|
- name: eslint (lockfile only; warnings may only go down)
|
|
working-directory: tests/lint
|
|
run: |
|
|
npm ci --no-audit --no-fund
|
|
npm run lint
|
|
|
|
audit:
|
|
name: Security (composer and npm 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 # no job pushes; keep the token out of .git/config
|
|
- name: Install PHP 8.4 and Composer (pinned, verified checksum)
|
|
run: |
|
|
WITH_DB=0 EXTRA_PKGS="unzip" tests/ci/setup.sh
|
|
curl -fsSLo /usr/local/bin/composer https://getcomposer.org/download/2.11.3/composer.phar
|
|
echo "04f8b003da4e3a2459056591fbfebd02b4dc3e5adeb158616b90cf55a65113ec /usr/local/bin/composer" | sha256sum -c
|
|
chmod +x /usr/local/bin/composer
|
|
- name: composer.json and composer.lock agree
|
|
run: COMPOSER_ALLOW_SUPERUSER=1 composer validate --no-check-publish --strict
|
|
- name: PHP dependencies (composer audit; ignores are listed with reasons in composer.json)
|
|
run: COMPOSER_ALLOW_SUPERUSER=1 composer audit --locked --no-interaction --abandoned=fail
|
|
- name: npm dependencies of the test tooling (audit, signatures)
|
|
run: |
|
|
for dir in tests/ui tests/lint; do
|
|
echo "== $dir"
|
|
(cd "$dir" && npm ci --ignore-scripts --no-audit --no-fund && npm audit signatures)
|
|
# Retry only when the registry itself fails; a real advisory fails at once.
|
|
for attempt in 1 2 3; do
|
|
if out=$(cd "$dir" && npm audit --audit-level=high 2>&1); then echo "$out"; break; fi
|
|
echo "$out"
|
|
echo "$out" | grep -q "audit endpoint returned an error" || exit 1
|
|
[ "$attempt" = 3 ] && exit 1
|
|
echo "npm registry error (attempt $attempt); retrying in 20s"
|
|
sleep 20
|
|
done
|
|
done
|
|
|
|
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 # 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; reviewed false positives in .gitleaks.toml)
|
|
run: |
|
|
git config --global --add safe.directory "$PWD"
|
|
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: 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.
|
|
# The three excluded PHP rules were reviewed when semgrep was added (security.yml).
|
|
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/php --config p/owasp-top-ten --config p/javascript \
|
|
--config p/secrets --config p/security-audit \
|
|
--exclude-rule=php.lang.security.injection.echoed-request.echoed-request \
|
|
--exclude-rule=php.lang.security.injection.tainted-filename.tainted-filename \
|
|
--exclude-rule=php.lang.security.injection.tainted-callable.tainted-callable \
|
|
--exclude vendor --exclude node_modules
|
|
|
|
api:
|
|
name: API and MCP (PHP 8.4, MariaDB)
|
|
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 # no job pushes; keep the token out of .git/config
|
|
- name: Install PHP 8.4, MariaDB and Composer (pinned, verified checksum)
|
|
run: |
|
|
EXTRA_PKGS="unzip" tests/ci/setup.sh
|
|
curl -fsSLo /usr/local/bin/composer https://getcomposer.org/download/2.11.3/composer.phar
|
|
echo "04f8b003da4e3a2459056591fbfebd02b4dc3e5adeb158616b90cf55a65113ec /usr/local/bin/composer" | sha256sum -c
|
|
chmod +x /usr/local/bin/composer
|
|
- name: Composer dependencies, as the deploy installs them (MCP endpoint)
|
|
run: |
|
|
COMPOSER_ALLOW_SUPERUSER=1 composer install --no-dev --no-interaction --no-progress \
|
|
--no-plugins --no-scripts --classmap-authoritative
|
|
- name: Start Tinker Tickets (port 8400, fresh database, migrations, seed data)
|
|
run: tests/ui/stack.sh . 8400 tinker_ui_api
|
|
- name: Fixtures (system user, API keys, MCP users)
|
|
run: php tests/api/fixtures.php /tmp/api-keys.json
|
|
- name: MCP write tools (comments, links)
|
|
run: php tests/api/mcp_test.php
|
|
- name: Bearer API contract (create, dedup, recurrence, lookup, links) under three workflow setups
|
|
run: python3 tests/api/test_api.py
|
|
- name: No PHP warnings while serving the tests
|
|
run: tests/ci/php-warnings.sh .ui-stack/server.log
|
|
- name: Server log
|
|
if: always()
|
|
run: tail -n 200 .ui-stack/server.log || true
|
|
|
|
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 tests/ui/package.json.
|
|
container: mcr.microsoft.com/playwright:v1.64.1-noble@sha256:2f05f8a734509a7b3f26a912639488ee08f58a7b292d14d62271bcff9038768f
|
|
steps:
|
|
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
|
|
with:
|
|
persist-credentials: false # no job pushes; keep the token out of .git/config
|
|
- name: Install PHP and MariaDB
|
|
run: tests/ci/setup.sh
|
|
- name: Start Tinker Tickets (port 8400, seeded test data)
|
|
run: tests/ui/stack.sh . 8400 tinker_ui
|
|
- name: Install Playwright (lockfile only)
|
|
working-directory: tests/ui
|
|
run: npm ci
|
|
- name: Run Playwright (desktop and mobile)
|
|
working-directory: tests/ui
|
|
run: npx playwright test
|
|
- name: No PHP warnings while serving the tests
|
|
run: tests/ci/php-warnings.sh .ui-stack/server.log
|
|
- name: Server log
|
|
if: always()
|
|
run: tail -n 200 .ui-stack/server.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: |
|
|
tests/ui/playwright-report/
|
|
tests/ui/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:
|
|
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: |
|
|
git config --global --add safe.directory "$PWD"
|
|
if git diff --quiet "$BASE_SHA" HEAD -- assets/ views/; then
|
|
echo "No UI files changed; no screenshots needed."
|
|
else
|
|
echo "changed=true" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
- name: Install PHP and MariaDB
|
|
if: steps.ui.outputs.changed == 'true'
|
|
run: tests/ci/setup.sh
|
|
- name: Start this PR's Tinker Tickets (port 8400)
|
|
if: steps.ui.outputs.changed == 'true'
|
|
run: tests/ui/stack.sh . 8400 tinker_ui
|
|
- name: Start the base branch's Tinker Tickets (port 8401)
|
|
if: steps.ui.outputs.changed == 'true'
|
|
run: |
|
|
git worktree add /tmp/base "$BASE_SHA"
|
|
tests/ui/stack.sh /tmp/base 8401 tinker_ui_base
|
|
- name: Capture before/after screenshots
|
|
if: steps.ui.outputs.changed == 'true'
|
|
run: |
|
|
(cd tests/ui && npm ci)
|
|
node tests/ui/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: 10
|
|
needs: [lint, audit, scan, api, ui]
|
|
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/development')
|
|
# One deploy per site at a time; queue instead of cancelling one mid-way.
|
|
concurrency:
|
|
group: deploy-${{ github.ref_name }}
|
|
cancel-in-progress: false
|
|
permissions:
|
|
contents: write # deploy tag
|
|
steps:
|
|
- name: Trigger webhook
|
|
env:
|
|
WEBHOOK_SECRET: ${{ secrets.WEBHOOK_SECRET }}
|
|
GIT_REF: ${{ github.ref }}
|
|
run: |
|
|
if [ "$GIT_REF" = "refs/heads/main" ]; then
|
|
HOOK_ID="tinker-deploy"
|
|
else
|
|
HOOK_ID="tinker-beta-deploy"
|
|
fi
|
|
PAYLOAD="{\"ref\":\"${GIT_REF}\"}"
|
|
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.45:9000/hooks/${HOOK_ID}"
|
|
|
|
- name: Tag deployed commit
|
|
if: github.ref == 'refs/heads/main'
|
|
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"
|
|
|
|
notify:
|
|
name: Notify
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 5
|
|
needs: [lint, audit, scan, api, ui, deploy]
|
|
# Alert on any failure on a deploy branch or in the weekly run, and on every deploy.
|
|
if: >-
|
|
always() && (
|
|
(failure() && (github.event_name == 'push' || 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 }}
|
|
SHA: ${{ github.sha }}
|
|
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
|
|
RESULTS: "lint=${{ needs.lint.result }} audit=${{ needs.audit.result }} scan=${{ needs.scan.result }} api=${{ needs.api.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} (${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}\"}"
|