Files
sencho/.github/workflows/ci.yml
T
Anso fdb476a84a ci: hard-fail PR and release scans on unacknowledged HIGH/CRITICAL CVEs (#484)
* ci: hard-fail PR and release scans on unacknowledged HIGH/CRITICAL CVEs

Make Trivy a real gate instead of an advisory signal:

- PR CI (docker-validate) no longer uses `continue-on-error: true` on the
  Trivy step, so any HIGH/CRITICAL finding not in `.trivyignore` fails the PR.
- The release pipeline (docker-publish.yml) now builds an amd64-only scan
  image into the local daemon before the multi-arch push-build, re-runs
  Trivy against that exact artifact, and only proceeds to the push if the
  scan passes. This closes the gap where a CVE landed between PR merge and
  release-time rebuild.
- New `.trivyignore` at repo root is the single source of truth for
  acknowledged CVEs across both workflows; it starts empty so the first CI
  run surfaces the full list, which we then populate with justifications.

* ci: populate .trivyignore with initial HIGH/CRITICAL acknowledgements

First CI run on the hard-fail Trivy policy surfaced 7 unacknowledged
findings. Each has been reviewed and justified inline:

- 6 CVEs in the statically-linked Go modules inside docker-compose v5.1.1
  (github.com/docker/docker, buildkit, otel/sdk x2, grpc). These are
  transitively bundled and cannot be bumped without an upstream Compose
  rebuild. The grpc CVE is already explicitly acknowledged in the
  Dockerfile rationale block at Dockerfile:108-111.
- 1 CVE in picomatch 4.0.3 bundled inside the npm CLI that ships with
  node:22-alpine. npm is only invoked at build time against our own
  package.json, so the ReDoS vector is not reachable.

Every entry has a revisit trigger (next Compose release or next Alpine
node bump).
2026-04-10 14:01:02 -04:00

258 lines
8.1 KiB
YAML

name: Sencho CI
on:
pull_request:
branches: [main]
push:
branches: [main]
# Screenshot auto-merge commits only touch docs/images/.
# Ignoring this path breaks the cascade:
# merge PR → screenshots PR auto-merges → would re-trigger CI → now skipped.
# The next real merge will sync everything (rsync --delete does a full mirror).
paths-ignore:
- 'docs/images/**'
# Cancel previous runs on the same branch/PR
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
# Least-privilege default for every job. Individual jobs may override (e.g.
# update-screenshots needs contents: write + pull-requests: write to open a PR).
permissions:
contents: read
# ---------------------------------------------------------------------------
# Build & Validation (PRs only, skipped for release-please PRs)
# ---------------------------------------------------------------------------
jobs:
backend:
name: Backend (Build, Test, Lint)
runs-on: ubuntu-latest
timeout-minutes: 10
if: >-
github.event_name == 'pull_request'
&& github.head_ref != 'release-please--branches--main--components--sencho'
steps:
- name: Checkout Code
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: backend/package-lock.json
- name: Install Dependencies
working-directory: ./backend
run: npm ci
- name: Build (TypeScript)
working-directory: ./backend
run: npm run build
- name: Unit Tests (Vitest)
working-directory: ./backend
run: npm test
- name: Lint (ESLint)
working-directory: ./backend
run: npm run lint
- name: Audit Dependencies
working-directory: ./backend
run: npm audit --audit-level=high
frontend:
name: Frontend (Build, Lint)
runs-on: ubuntu-latest
timeout-minutes: 10
if: >-
github.event_name == 'pull_request'
&& github.head_ref != 'release-please--branches--main--components--sencho'
steps:
- name: Checkout Code
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: frontend/package-lock.json
- name: Install Dependencies
working-directory: ./frontend
run: npm ci
- name: Build (Vite/React)
working-directory: ./frontend
run: npm run build
- name: Lint (ESLint)
working-directory: ./frontend
run: npm run lint
- name: Audit Dependencies
working-directory: ./frontend
run: npm audit --audit-level=high
docker-validate:
name: Docker Build & Scan
runs-on: ubuntu-latest
timeout-minutes: 15
if: >-
github.event_name == 'pull_request'
&& github.head_ref != 'release-please--branches--main--components--sencho'
steps:
- name: Checkout Code
uses: actions/checkout@v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Build Docker image (validation only)
uses: docker/build-push-action@v7
with:
context: .
push: false
load: true
tags: sencho:pr-test
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Scan image for vulnerabilities (Trivy)
# Hard-fails the PR on any HIGH or CRITICAL finding that is not listed
# in .trivyignore at the repo root. To accept a CVE, add it to that
# file with a human-readable justification comment, not here.
uses: aquasecurity/trivy-action@57a97c7e7821a5776cebc9bb87c984fa69cba8f1 # v0.35.0
with:
image-ref: sencho:pr-test
exit-code: '1'
severity: 'CRITICAL,HIGH'
format: 'table'
# ---------------------------------------------------------------------------
# E2E Tests (PRs only, skipped for release-please PRs)
# ---------------------------------------------------------------------------
e2e:
name: E2E Tests (Playwright)
runs-on: ubuntu-latest
timeout-minutes: 15
needs: [backend, frontend]
if: >-
github.event_name == 'pull_request'
&& github.head_ref != 'release-please--branches--main--components--sencho'
steps:
- name: Checkout Code
uses: actions/checkout@v6
- name: Start app & install Playwright
uses: ./.github/actions/start-app
- name: Run E2E tests
run: npx playwright test
- name: Upload E2E report and service logs
if: failure()
uses: actions/upload-artifact@v7
with:
name: playwright-report
path: |
e2e/report/
test-results/
ci-logs/
retention-days: 7
# ---------------------------------------------------------------------------
# Post-release only: Screenshot refresh
# Only runs when release-please merges a "chore(main): release" commit,
# so screenshots are refreshed once per release - not on every merge.
# ---------------------------------------------------------------------------
update-screenshots:
name: Refresh Doc Screenshots
runs-on: ubuntu-latest
timeout-minutes: 15
if: >-
github.event_name == 'push'
&& github.ref == 'refs/heads/main'
&& startsWith(github.event.head_commit.message, 'chore(main): release')
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout Code
uses: actions/checkout@v6
with:
token: ${{ secrets.DOCS_REPO_TOKEN }}
- name: Start app & install Playwright
uses: ./.github/actions/start-app
- name: Capture screenshots
run: npx playwright test e2e/screenshots.spec.ts --project=chromium
- name: Open / update screenshots PR
id: create-pr
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
with:
token: ${{ secrets.DOCS_REPO_TOKEN }}
branch: chore/refresh-screenshots
commit-message: "docs: refresh screenshots"
title: "docs: refresh screenshots"
body: "Automated screenshot refresh - generated by the `update-screenshots` CI job on push to `main`."
add-paths: docs/images/
delete-branch: true
- name: Auto-merge screenshots PR
if: steps.create-pr.outputs.pull-request-number != ''
env:
GH_TOKEN: ${{ secrets.DOCS_REPO_TOKEN }}
run: |
gh pr merge ${{ steps.create-pr.outputs.pull-request-number }} \
--squash \
--repo ${{ github.repository }}
sync-docs:
name: Sync Docs to sencho-docs
runs-on: ubuntu-latest
timeout-minutes: 5
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- name: Checkout Sencho repo
uses: actions/checkout@v6
with:
path: sencho
- name: Clone or init sencho-docs
env:
DOCS_TOKEN: ${{ secrets.DOCS_REPO_TOKEN }}
run: |
rm -rf sencho-docs
REMOTE="https://x-access-token:${DOCS_TOKEN}@github.com/AnsoCode/sencho-docs.git"
if git clone "${REMOTE}" sencho-docs 2>/dev/null; then
echo "Cloned existing sencho-docs."
else
echo "Clone failed (repo is empty or has no default branch) - initializing."
mkdir -p sencho-docs
cd sencho-docs
git init
git checkout -b main
git remote add origin "${REMOTE}"
fi
- name: Copy /docs into sencho-docs root
run: rsync -av --delete --exclude='.git' sencho/docs/ sencho-docs/
- name: Commit and push to sencho-docs
working-directory: sencho-docs
run: |
git config user.email "docs-bot@sencho.io"
git config user.name "Sencho Docs Bot"
git add -A
git commit -m "docs: sync from main@${{ github.sha }}" || echo "No changes to commit"
git push origin HEAD:main