返回 CodeWhale
web-maintainer.yml
根目录 / .github / workflows / web-maintainer.yml
1 name: Web maintainer
2
3 on:
4 schedule:
5 - cron: '43 6 * * *'
6 workflow_dispatch:
7 inputs:
8 lane:
9 description: Which lane to run
10 required: true
11 default: all
12 type: choice
13 options:
14 - all
15 - derived
16 - copy-freshness
17 - link-health
18 - docs-drift
19
20 permissions: {}
21
22 concurrency:
23 group: web-maintainer
24 cancel-in-progress: false
25
26 env:
27 WEB_MAINTAINER_CLI_VERSION: v0.10.2
28
29 jobs:
30 plan:
31 name: Plan
32 if: github.repository == 'codewhale-hq/Codewhale' && github.ref == 'refs/heads/main' && vars.WEB_MAINTAINER_ENABLED == 'true'
33 runs-on: ubuntu-24.04
34 timeout-minutes: 5
35 permissions: {}
36 outputs:
37 lanes: ${{ steps.plan.outputs.lanes }}
38 derived: ${{ steps.plan.outputs.derived }}
39 steps:
40 - id: plan
41 env:
42 INPUT_LANE: ${{ inputs.lane || 'all' }}
43 run: |
44 derived=false
45 lanes='[]'
46 case "$INPUT_LANE" in
47 all) derived=true; lanes='["copy-freshness","link-health","docs-drift"]' ;;
48 derived) derived=true ;;
49 copy-freshness|link-health|docs-drift) lanes="[\"${INPUT_LANE}\"]" ;;
50 *) echo "::error::unknown lane"; exit 1 ;;
51 esac
52 echo "derived=${derived}" >> "$GITHUB_OUTPUT"
53 echo "lanes=${lanes}" >> "$GITHUB_OUTPUT"
54 echo "Web maintainer plan: derived=${derived} lanes=${lanes}" >> "$GITHUB_STEP_SUMMARY"
55
56 derived:
57 name: Derived files
58 needs: plan
59 if: needs.plan.result == 'success' && needs.plan.outputs.derived == 'true' && vars.WEB_MAINTAINER_ENABLED == 'true'
60 runs-on: ubuntu-24.04
61 timeout-minutes: 30
62 permissions:
63 contents: read
64 steps:
65 - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
66 with:
67 ref: main
68 fetch-depth: 0
69 persist-credentials: false
70 - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
71 with:
72 node-version: 22
73 - name: Install web dependencies
74 working-directory: web
75 run: npm ci --no-audit --no-fund
76 - name: Regenerate derived files
77 working-directory: web
78 env:
79 GH_TOKEN: ${{ github.token }}
80 run: |
81 node scripts/sync-latest-release.mjs
82 node scripts/derive-facts.mjs
83 node scripts/derive-changelog.mjs
84 node scripts/derive-install.mjs
85 node scripts/render-released-capture.mjs
86 - name: Check what changed
87 id: drift
88 run: |
89 mkdir -p "$RUNNER_TEMP/out"
90 if [ -n "$(git ls-files --others --exclude-standard)" ]; then
91 echo "::error::regeneration produced untracked files"
92 git ls-files --others --exclude-standard
93 exit 1
94 fi
95 git diff --name-status | node web/maintainer/check-allowlist.mjs web/maintainer/derived.txt derived
96 if [ -n "$(git diff --summary)" ]; then
97 echo "::error::regeneration created, deleted or changed modes"
98 exit 1
99 fi
100 git diff --binary > "$RUNNER_TEMP/out/change.patch"
101 if [ -s "$RUNNER_TEMP/out/change.patch" ]; then
102 echo "drift=true" >> "$GITHUB_OUTPUT"
103 git diff --stat >> "$GITHUB_STEP_SUMMARY"
104 else
105 echo "drift=false" >> "$GITHUB_OUTPUT"
106 echo "Derived files are current." >> "$GITHUB_STEP_SUMMARY"
107 fi
108 - name: Run the web checks on the regenerated tree
109 if: steps.drift.outputs.drift == 'true'
110 working-directory: web
111 run: |
112 npm run check
113 npx vitest run
114 - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
115 if: steps.drift.outputs.drift == 'true'
116 with:
117 name: web-maintainer-derived
118 path: ${{ runner.temp }}/out/change.patch
119 retention-days: 3
120 if-no-files-found: error
121
122 lane:
123 name: Lane ${{ matrix.lane }}
124 needs: plan
125 if: needs.plan.result == 'success' && needs.plan.outputs.lanes != '[]' && vars.WEB_MAINTAINER_ENABLED == 'true'
126 runs-on: ubuntu-24.04
127 timeout-minutes: 45
128 permissions:
129 contents: read
130 strategy:
131 fail-fast: false
132 max-parallel: 3
133 matrix:
134 lane: ${{ fromJSON(needs.plan.outputs.lanes) }}
135 env:
136 LANE: ${{ matrix.lane }}
137 steps:
138 - name: Require the DeepSeek key
139 env:
140 KEY: ${{ secrets.WEB_MAINTAINER_DEEPSEEK_API_KEY }}
141 run: |
142 if [ -z "$KEY" ]; then
143 echo "::error::WEB_MAINTAINER_DEEPSEEK_API_KEY is not set. Create a dedicated DeepSeek key with a provider-side monthly cap and add it as that repository secret, or unset WEB_MAINTAINER_ENABLED. See web/maintainer/README.md."
144 exit 1
145 fi
146 - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
147 with:
148 ref: main
149 persist-credentials: false
150 - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
151 with:
152 node-version: 22
153 - name: Prove the command sandbox works or stop
154 run: |
155 sudo apt-get install -y --no-install-recommends bubblewrap util-linux >/dev/null
156 sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0 >/dev/null || true
157 probe="$GITHUB_WORKSPACE/.sandbox-probe"
158 rm -f "$probe" /usr/local/sandbox-probe
159 if ! timeout 10 bash -c 'exec 3<>/dev/tcp/api.deepseek.com/443'; then
160 echo "::error::the runner cannot reach api.deepseek.com, so the network denial cannot be proven."
161 exit 1
162 fi
163 if ! /usr/bin/bwrap --unshare-all --ro-bind / / --dev /dev --proc /proc --tmpfs /tmp \
164 --bind "$GITHUB_WORKSPACE" "$GITHUB_WORKSPACE" --chdir "$GITHUB_WORKSPACE" -- \
165 bash -c 'touch .sandbox-probe && ! touch /usr/local/sandbox-probe 2>/dev/null && ! timeout 10 bash -c "exec 3<>/dev/tcp/api.deepseek.com/443" 2>/dev/null'; then
166 echo "::error::bubblewrap did not confine a child on this runner (writes outside the workspace or outbound network were not denied). Refusing to give a model a shell."
167 exit 1
168 fi
169 if [ ! -e "$probe" ] || [ -e /usr/local/sandbox-probe ]; then
170 echo "::error::sandbox probe left unexpected state. Refusing to give a model a shell."
171 exit 1
172 fi
173 rm -f "$probe"
174 echo "Sandbox probe passed: workspace-only writes, no outbound network." >> "$GITHUB_STEP_SUMMARY"
175 - name: Stage trusted tooling and the pinned CLI
176 run: |
177 mkdir -p "$RUNNER_TEMP/trusted" "$RUNNER_TEMP/home"
178 cp web/maintainer/allowlist.txt web/maintainer/check-allowlist.mjs "$RUNNER_TEMP/trusted/"
179 cp "web/maintainer/lanes/${LANE}.md" "$RUNNER_TEMP/trusted/prompt.md"
180 CODEWHALE_VERSION="$WEB_MAINTAINER_CLI_VERSION" CODEWHALE_INSTALL_DIR="$RUNNER_TEMP/bin" sh web/public/install.sh
181 "$RUNNER_TEMP/bin/codewhale" --version
182 - name: Probe outbound links
183 if: matrix.lane == 'link-health'
184 run: node web/maintainer/link-report.mjs "$GITHUB_WORKSPACE/.git/maintainer-input/link-report.json"
185 - name: Record the git state the model must not change
186 run: |
187 git config --local --list | sort > "$RUNNER_TEMP/git-config.before"
188 find .git/hooks -type f ! -name '*.sample' > "$RUNNER_TEMP/hooks.before"
189 test ! -s "$RUNNER_TEMP/hooks.before"
190 - name: Run the lane on DeepSeek
191 timeout-minutes: 25
192 env:
193 WEB_MAINTAINER_DEEPSEEK_API_KEY: ${{ secrets.WEB_MAINTAINER_DEEPSEEK_API_KEY }}
194 run: |
195 env -i \
196 PATH="$PATH" \
197 HOME="$RUNNER_TEMP/home" \
198 CODEWHALE_HOME="$RUNNER_TEMP/home/.codewhale" \
199 CODEWHALE_SECRET_BACKEND=file \
200 CODEWHALE_MEMORY=false \
201 CODEWHALE_TELEMETRY=false \
202 DEEPSEEK_API_KEY="$WEB_MAINTAINER_DEEPSEEK_API_KEY" \
203 "$RUNNER_TEMP/bin/codewhale" \
204 --no-project-config \
205 --skip-onboarding \
206 --workspace "$GITHUB_WORKSPACE" \
207 exec \
208 --provider deepseek \
209 --model deepseek-flash \
210 --reasoning-effort low \
211 --auto \
212 --sandbox workspace-write \
213 --max-turns 40 \
214 --output-format stream-json \
215 -- "$(cat "$RUNNER_TEMP/trusted/prompt.md")" \
216 > "$RUNNER_TEMP/exec.jsonl"
217 echo "Model run finished: $(wc -l < "$RUNNER_TEMP/exec.jsonl") stream events." >> "$GITHUB_STEP_SUMMARY"
218 - name: Enforce the path allowlist
219 id: scope
220 run: |
221 if git status --porcelain --untracked-files=all --ignored | grep -qv '^ M '; then
222 echo "::error::the lane left untracked, ignored, staged or non-edit entries"
223 git status --porcelain --untracked-files=all --ignored | grep -v '^ M '
224 exit 1
225 fi
226 git config --local --list | sort | diff - "$RUNNER_TEMP/git-config.before" || { echo "::error::the lane changed .git/config"; exit 1; }
227 find .git/hooks -type f ! -name '*.sample' | diff - "$RUNNER_TEMP/hooks.before" || { echo "::error::the lane added git hooks"; exit 1; }
228 git diff --name-status | node "$RUNNER_TEMP/trusted/check-allowlist.mjs" "$RUNNER_TEMP/trusted/allowlist.txt" "$LANE"
229 if [ -n "$(git diff --summary)" ]; then
230 echo "::error::the lane created, deleted or changed modes"
231 exit 1
232 fi
233 mkdir -p "$RUNNER_TEMP/out"
234 git diff --binary > "$RUNNER_TEMP/out/change.patch"
235 if [ ! -s "$RUNNER_TEMP/out/change.patch" ]; then
236 echo "changed=false" >> "$GITHUB_OUTPUT"
237 echo "Lane ${LANE}: no change proposed." >> "$GITHUB_STEP_SUMMARY"
238 exit 0
239 fi
240 if [ "$(wc -c < "$RUNNER_TEMP/out/change.patch")" -gt 262144 ]; then
241 echo "::error::patch exceeds 256 KiB"
242 exit 1
243 fi
244 echo "changed=true" >> "$GITHUB_OUTPUT"
245 { echo "Lane ${LANE} proposes:"; echo '```text'; git diff --stat; echo '```'; } >> "$GITHUB_STEP_SUMMARY"
246 - name: Fresh checkout for verification
247 if: steps.scope.outputs.changed == 'true'
248 uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
249 with:
250 ref: main
251 fetch-depth: 0
252 path: verify
253 persist-credentials: false
254 - name: Run the web checks on the proposal in a clean tree without secrets
255 if: steps.scope.outputs.changed == 'true'
256 env:
257 PATCH: ${{ runner.temp }}/out/change.patch
258 run: |
259 cd verify
260 git apply --index --whitespace=nowarn "$PATCH"
261 cd web
262 npm ci --no-audit --no-fund
263 npm run check
264 npx vitest run
265 - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
266 if: steps.scope.outputs.changed == 'true'
267 with:
268 name: web-maintainer-${{ matrix.lane }}
269 path: ${{ runner.temp }}/out/change.patch
270 retention-days: 3
271 if-no-files-found: error
272
273 publish:
274 name: Open pull requests
275 needs: [plan, derived, lane]
276 if: always() && needs.plan.result == 'success' && vars.WEB_MAINTAINER_ENABLED == 'true'
277 runs-on: ubuntu-24.04
278 timeout-minutes: 15
279 permissions:
280 contents: read
281 steps:
282 - name: Report lanes that did not finish
283 id: lanes
284 env:
285 DERIVED_RESULT: ${{ needs.derived.result }}
286 LANE_RESULT: ${{ needs.lane.result }}
287 run: |
288 failed=""
289 for pair in "derived=$DERIVED_RESULT" "lane=$LANE_RESULT"; do
290 case "${pair#*=}" in success|skipped) ;; *) failed="$failed ${pair}" ;; esac
291 done
292 if [ -n "$failed" ]; then
293 echo "failed=true" >> "$GITHUB_OUTPUT"
294 echo "::error::web-maintainer jobs did not finish:$failed; their patches are missing from this run."
295 echo "Jobs did not finish:$failed. Their patches are missing; this run is not a clean no-op." >> "$GITHUB_STEP_SUMMARY"
296 else
297 echo "failed=false" >> "$GITHUB_OUTPUT"
298 fi
299 - id: download
300 uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8
301 continue-on-error: true
302 with:
303 pattern: web-maintainer-*
304 path: ${{ runner.temp }}/patches
305 - name: Look for proposed patches
306 id: patches
307 env:
308 LANES_FAILED: ${{ steps.lanes.outputs.failed }}
309 DOWNLOAD_OUTCOME: ${{ steps.download.outcome }}
310 run: |
311 if [ "$DOWNLOAD_OUTCOME" = "failure" ]; then
312 echo "::error::web-maintainer patch artifacts could not be downloaded; their patches may exist but were not published."
313 echo "Patch artifact download failed; this run is not a clean no-op. No pull request was opened." >> "$GITHUB_STEP_SUMMARY"
314 exit 1
315 fi
316 if [ -n "$(find "$RUNNER_TEMP/patches" -name change.patch -size +0c 2>/dev/null)" ]; then
317 echo "found=true" >> "$GITHUB_OUTPUT"
318 else
319 echo "found=false" >> "$GITHUB_OUTPUT"
320 if [ "$LANES_FAILED" != "true" ]; then
321 echo "No lane proposed a change; no pull request opened." >> "$GITHUB_STEP_SUMMARY"
322 fi
323 fi
324 - if: steps.patches.outputs.found == 'true'
325 uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3
326 id: app-token
327 with:
328 app-id: ${{ vars.CODEWHALE_APP_ID }}
329 private-key: ${{ secrets.CODEWHALE_APP_PRIVATE_KEY }}
330 permission-contents: write
331 permission-pull-requests: write
332 - if: steps.patches.outputs.found == 'true'
333 uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
334 with:
335 ref: main
336 fetch-depth: 0
337 token: ${{ steps.app-token.outputs.token }}
338 persist-credentials: false
339 - name: Open or update one pull request per lane
340 if: steps.patches.outputs.found == 'true'
341 env:
342 GH_TOKEN: ${{ steps.app-token.outputs.token }}
343 APP_ID: ${{ vars.CODEWHALE_APP_ID }}
344 ARTIFACTS_DIR: ${{ runner.temp }}/patches
345 RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
346 run: |
347 mkdir -p "$RUNNER_TEMP/trusted"
348 cp web/maintainer/allowlist.txt web/maintainer/derived.txt web/maintainer/check-allowlist.mjs web/maintainer/publish-prs.sh "$RUNNER_TEMP/trusted/"
349 TRUSTED_DIR="$RUNNER_TEMP/trusted" bash "$RUNNER_TEMP/trusted/publish-prs.sh"
350 - name: Fail when a lane did not finish
351 if: steps.lanes.outputs.failed == 'true'
352 run: exit 1
353
353 lines YAML