|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + |
| 9 | +# Cancel superseded runs on the same PR/branch. |
| 10 | +concurrency: |
| 11 | + group: ci-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
| 12 | + cancel-in-progress: ${{ github.event_name == 'pull_request' }} |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: read |
| 16 | + |
| 17 | +jobs: |
| 18 | + typecheck: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - name: Harden the runner (Audit all outbound calls) |
| 22 | + uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0 |
| 23 | + with: |
| 24 | + egress-policy: audit |
| 25 | + |
| 26 | + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 |
| 27 | + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 |
| 28 | + with: |
| 29 | + node-version: 24 |
| 30 | + cache: npm |
| 31 | + - run: npm ci |
| 32 | + - run: npm run typecheck |
| 33 | + |
| 34 | + lint: |
| 35 | + runs-on: ubuntu-latest |
| 36 | + steps: |
| 37 | + - name: Harden the runner (Audit all outbound calls) |
| 38 | + uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0 |
| 39 | + with: |
| 40 | + egress-policy: audit |
| 41 | + |
| 42 | + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 |
| 43 | + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 |
| 44 | + with: |
| 45 | + node-version: 24 |
| 46 | + cache: npm |
| 47 | + - run: npm ci |
| 48 | + - run: npm run lint |
| 49 | + |
| 50 | + test: |
| 51 | + runs-on: ubuntu-latest |
| 52 | + steps: |
| 53 | + - name: Harden the runner (Audit all outbound calls) |
| 54 | + uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0 |
| 55 | + with: |
| 56 | + egress-policy: audit |
| 57 | + |
| 58 | + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 |
| 59 | + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 |
| 60 | + with: |
| 61 | + node-version: 24 |
| 62 | + cache: npm |
| 63 | + - run: npm ci |
| 64 | + - run: npm test |
| 65 | + |
| 66 | + # public/llms.txt, llms-full.txt, and AGENTS.md are generated from the route |
| 67 | + # tree and committed. They go stale whenever a route is added, renamed, or |
| 68 | + # removed, so this fails if they differ from a fresh generation (it also |
| 69 | + # reports sitemap drift). Fix with: npm run llms && npm run agents |
| 70 | + docs: |
| 71 | + name: docs (generated agent index) |
| 72 | + runs-on: ubuntu-latest |
| 73 | + steps: |
| 74 | + - name: Harden the runner (Audit all outbound calls) |
| 75 | + uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0 |
| 76 | + with: |
| 77 | + egress-policy: audit |
| 78 | + |
| 79 | + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 |
| 80 | + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 |
| 81 | + with: |
| 82 | + node-version: 24 |
| 83 | + cache: npm |
| 84 | + - run: npm ci |
| 85 | + - run: npm run docs:check |
| 86 | + |
| 87 | + public-build-excludes-internal: |
| 88 | + name: public build excludes internal-only surfaces |
| 89 | + runs-on: ubuntu-latest |
| 90 | + steps: |
| 91 | + - name: Harden the runner (Audit all outbound calls) |
| 92 | + uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0 |
| 93 | + with: |
| 94 | + egress-policy: audit |
| 95 | + |
| 96 | + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 |
| 97 | + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 |
| 98 | + with: |
| 99 | + node-version: 24 |
| 100 | + cache: npm |
| 101 | + - run: npm ci |
| 102 | + |
| 103 | + # The default (external) build is what ships to Vercel. Deliberately no |
| 104 | + # NEXT_PUBLIC_DEPLOY_TARGET here, so this reproduces the public build. |
| 105 | + - run: npm run build |
| 106 | + |
| 107 | + # Guards the deployment matrix in deploy.config.mjs: a surface that is not |
| 108 | + # shipped to the external target must be unreachable on the public site. |
| 109 | + # Without this, dropping the middleware rule — or adding an internal-only |
| 110 | + # page and forgetting its SURFACES entry — would silently publish it. |
| 111 | + - name: Assert internal-only surfaces are absent |
| 112 | + run: | |
| 113 | + set -euo pipefail |
| 114 | +
|
| 115 | + npx next start -p 3000 & |
| 116 | + SERVER_PID=$! |
| 117 | + trap 'kill $SERVER_PID 2>/dev/null || true' EXIT |
| 118 | +
|
| 119 | + for i in $(seq 1 60); do |
| 120 | + if curl -fsS -o /dev/null http://localhost:3000/; then break; fi |
| 121 | + if [ "$i" -eq 60 ]; then echo "server never became ready"; exit 1; fi |
| 122 | + sleep 1 |
| 123 | + done |
| 124 | +
|
| 125 | + fail=0 |
| 126 | +
|
| 127 | + # Internal-only routes must 404 on the public build. |
| 128 | + for route in /tips /tips/block/0x1 /tips/bundles/0x1 /api/tips/blocks; do |
| 129 | + code=$(curl -s -o /dev/null -w '%{http_code}' "http://localhost:3000${route}") |
| 130 | + if [ "${code}" != "404" ]; then |
| 131 | + echo "FAIL: ${route} returned ${code}, expected 404" |
| 132 | + fail=1 |
| 133 | + fi |
| 134 | + done |
| 135 | +
|
| 136 | + # Pages that must stay public. |
| 137 | + for route in / /snapshots; do |
| 138 | + code=$(curl -s -o /dev/null -w '%{http_code}' "http://localhost:3000${route}") |
| 139 | + if [ "${code}" != "200" ]; then |
| 140 | + echo "FAIL: ${route} returned ${code}, expected 200" |
| 141 | + fail=1 |
| 142 | + fi |
| 143 | + done |
| 144 | +
|
| 145 | + # No nav link to, or sitemap entry for, an internal-only section. |
| 146 | + if curl -s http://localhost:3000/ | grep -q 'href="/tips"'; then |
| 147 | + echo "FAIL: public homepage links to /tips" |
| 148 | + fail=1 |
| 149 | + fi |
| 150 | + if curl -s http://localhost:3000/sitemap.xml | grep -q '/tips'; then |
| 151 | + echo "FAIL: public sitemap lists /tips" |
| 152 | + fail=1 |
| 153 | + fi |
| 154 | +
|
| 155 | + if [ "${fail}" -ne 0 ]; then exit 1; fi |
| 156 | + echo "OK: internal-only surfaces are absent from the public build" |
0 commit comments