返回 CodeWhale
web.yml
根目录 / .github / workflows / web.yml
1 name: Web Frontend
2
3 on:
4 workflow_dispatch:
5 inputs:
6 expected_sha:
7 description: Optional exact 40-character commit SHA selected by --ref
8 required: false
9 default: ''
10 type: string
11
12 permissions:
13 contents: read
14
15 concurrency:
16 group: ${{ github.event_name == 'pull_request' && format('web-pr-{0}', github.event.pull_request.number) || format('web-{0}', github.run_id) }}
17 cancel-in-progress: ${{ github.event_name == 'pull_request' }}
18
19 jobs:
20 lint:
21 name: Lint & Type Check
22 runs-on: ubuntu-24.04
23 timeout-minutes: 30
24 defaults:
25 run:
26 working-directory: web
27 steps:
28 - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
29 with:
30 # `check:facts` derives each model's `addedAt` from the commit date on
31 # which its id first appeared in the model declaration paths
32 # (web/scripts/facts-lib.mjs). A shallow checkout cannot see that
33 # history, so every date collapses to the tip commit and the committed
34 # facts always read as stale. ci.yml pins depth 0 for the same reason.
35 fetch-depth: 0
36 - name: Verify expected commit
37 shell: bash
38 env:
39 EXPECTED_SHA: ${{ inputs.expected_sha }}
40 run: |
41 set -euo pipefail
42 if [[ -n "${EXPECTED_SHA}" ]]; then
43 if [[ "${#EXPECTED_SHA}" -ne 40 || "${EXPECTED_SHA}" =~ [^0-9a-fA-F] ]]; then
44 echo "::error::expected_sha must be a full 40-character commit SHA." >&2
45 exit 1
46 fi
47 actual="$(git rev-parse HEAD)"
48 expected_normalized="$(printf '%s' "${EXPECTED_SHA}" | tr '[:upper:]' '[:lower:]')"
49 if [[ "${actual}" != "${expected_normalized}" ]]; then
50 echo "::error::Dispatch resolved to ${actual}, not requested ${EXPECTED_SHA}." >&2
51 exit 1
52 fi
53 fi
54 - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
55 with:
56 node-version: 22
57 cache: 'npm'
58 cache-dependency-path: web/package-lock.json
59 - name: Install dependencies
60 run: npm ci
61 - name: Run tests
62 run: npm test
63 - name: Check web surface
64 # The shared gate checks committed facts before generating build inputs.
65 env:
66 GITHUB_TOKEN: ${{ github.token }}
67 run: npm run check
68
69 deploy-reminder:
70 name: Deployment approval needed
71 runs-on: ubuntu-24.04
72 timeout-minutes: 5
73 needs: lint
74 if: github.event_name == 'push' && github.ref == 'refs/heads/main'
75 steps:
76 - name: Surface the manual deployment gate
77 env:
78 REVISION: ${{ github.sha }}
79 run: |
80 echo "::notice title=Web deployment approval needed::Revision ${REVISION} passed the web gates but is not deployed. Dispatch web.yml on main to publish it."
81 {
82 echo "## Web deployment approval needed"
83 echo
84 echo "Revision \`${REVISION}\` passed the web gates but has **not** been deployed."
85 echo
86 echo "A maintainer can publish it with \`gh workflow run web.yml --repo codewhale-hq/CodeWhale --ref main\`."
87 } >> "$GITHUB_STEP_SUMMARY"
88
89 deploy:
90 name: Deploy to Cloudflare
91 runs-on: ubuntu-24.04
92 timeout-minutes: 30
93 needs: lint
94 # Deploy is MANUAL ONLY: an authorized dispatch on main runs `lint`
95 # before deploying. Pushes and pull requests do not start this workflow.
96 # This mirrors scripts/check-cloudflare-deploy-env.mjs, which fails closed
97 # unless GITHUB_EVENT_NAME is workflow_dispatch, GITHUB_REF is
98 # refs/heads/main, and GITHUB_SHA is an exact 40-hex revision — a push
99 # trigger here would only produce a red job after `lint` had already run.
100 # lib/deploy-preflight.test.ts asserts both halves of that contract.
101 # `needs: lint` is the gate: facts drift, docs parity, tests, ESLint, tsc,
102 # and a production build all pass before anything reaches Cloudflare.
103 if: >-
104 github.event_name == 'workflow_dispatch'
105 && github.ref == 'refs/heads/main'
106 # Serialize deploys so two dispatches landing close together cannot race and
107 # leave Cloudflare serving the older bundle. Never cancel in progress: a
108 # half-finished OpenNext upload is worse than a queued one.
109 concurrency:
110 group: deploy-codewhale-web
111 cancel-in-progress: false
112 defaults:
113 run:
114 working-directory: web
115 env:
116 CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
117 CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
118 steps:
119 - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
120 # Pin the checkout to the exact revision this dispatch resolved, so the
121 # SHA reported to compare:deployed-facts and asserted on the public
122 # receipt below is the SHA that was actually built, even if main moves
123 # while the run is queued behind the concurrency group.
124 with:
125 ref: ${{ github.sha }}
126 fetch-depth: 0
127 - name: Verify expected commit
128 shell: bash
129 env:
130 EXPECTED_SHA: ${{ inputs.expected_sha }}
131 run: |
132 set -euo pipefail
133 if [[ -n "${EXPECTED_SHA}" ]]; then
134 if [[ "${#EXPECTED_SHA}" -ne 40 || "${EXPECTED_SHA}" =~ [^0-9a-fA-F] ]]; then
135 echo "::error::expected_sha must be a full 40-character commit SHA." >&2
136 exit 1
137 fi
138 actual="$(git rev-parse HEAD)"
139 expected_normalized="$(printf '%s' "${EXPECTED_SHA}" | tr '[:upper:]' '[:lower:]')"
140 if [[ "${actual}" != "${expected_normalized}" ]]; then
141 echo "::error::Dispatch resolved to ${actual}, not requested ${EXPECTED_SHA}." >&2
142 exit 1
143 fi
144 fi
145 - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
146 with:
147 node-version: 22
148 cache: 'npm'
149 cache-dependency-path: web/package-lock.json
150 - name: Install dependencies
151 run: npm ci
152 - name: Refresh published release facts
153 # Clear CLOUDFLARE_API_TOKEN so only the deploy step sees the Cloudflare credential.
154 env:
155 CLOUDFLARE_API_TOKEN: ''
156 GITHUB_TOKEN: ${{ github.token }}
157 run: |
158 set -euo pipefail
159 node scripts/sync-latest-release.mjs
160 node scripts/derive-facts.mjs
161 node scripts/derive-release-docs.mjs
162 node scripts/check-cloud-facts.mjs
163 node scripts/check-facts.mjs
164 node scripts/check-release-docs.mjs
165 - name: Record deployed/source drift
166 # Read-only and credential-free. A mismatch is the normal state here —
167 # it is the gap this run is about to close — so this step reports
168 # without gating. The real assertion is the post-deploy verification
169 # below, which must observe this exact revision on the public receipt.
170 run: npm run compare:deployed-facts -- --expected-revision "$GITHUB_SHA"
171 - name: Check Cloudflare deploy environment
172 run: npm run check:deploy-env
173 # npm's deploy script performs one OpenNext build, then deploys that exact
174 # bundle. OpenNext populates the remote cache before cf deploy --prebuilt;
175 # the bundler has no custom build that could invalidate that cache.
176 - name: Build and deploy exact OpenNext bundle
177 run: npm run deploy
178 - name: Verify exact deployed revision
179 # The public /api/facts receipt must identify this workflow's exact
180 # checkout before the manual deployment run can finish green.
181 run: npm run check:deployed-facts -- --expected-revision "$GITHUB_SHA" --attempts 10 --retry-delay-ms 3000
182
182 lines YAML