Repository navigation
修复第 2 轮(CI/部署安全):按审查报告加固 GitHub Actions 工作流 - #118
Merged
todosdev[bot] merged 2 commits intoOct 17, 2026
Merged
Conversation
added 2 commits
October 17, 2026 19:59
- CI-C3/C4: least-privilege permissions; tag.yml drops PAT and calls release.yml - CI-C2/C8: pin deploy to CI head_sha, production env, concurrency, smoke test - CI-C5/C6/C7: D1 migrations before deploy, frozen lockfile + audit, validate IDs Co-Authored-By: Claude Code <noreply@anthropic.com> Checkpoint: gKV4K2rDLsiq3Qz1ay8M5
When tables exist without any migration history, check that every 0001_init.sql table and links.user_seq exist before marking it applied; otherwise fail instead of baselining a partial or drifted schema. Checkpoint: 8BGviyy8TdefHfg4_zijF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PAT_TOKEN, deploying exactly the commit CI verified, and putting production deploys behind an environment, a concurrency group and a post-deploy smoke test./setuproute, a prep script first records the already-applied migrations as a baseline so wrangler doesn't re-run them.apps/*/srcis touched, to avoid conflicts with the parallel round-1 security PR.Changes
ci.ymlpermissions: contents: read; checkout usespersist-credentials: false.pnpm install --frozen-lockfile.auditjob runningpnpm audit --prod --audit-level=high. It is non-blocking (continue-on-error) because of existingreact-router@7.17.0advisories (2 high, 3 moderate; fixed in ≥ 7.18.2).tag.yml/release.ymltag.ymldropsPAT_TOKENand pushes the tag withGITHUB_TOKEN(contents: writeon that job only). The user-supplied tag reaches the scripts throughenv, not inline expressions.GITHUB_TOKENdoes not trigger other workflows, sotag.ymlcallsrelease.ymlthrough the newworkflow_callentry point.release.ymlkeeps itspush: tags v*trigger, so a manually pushed tag still releases. Top-levelpermissions: {}with job-scopedcontents: write; the unneeded checkout is removed.deploy.ymlpushto main of this repo. The oldbranches: [main]filter alone also matched fork PRs from a branch namedmain. Manual dispatch is allowed only frommain.workflow_run.head_shawithpersist-credentials: false.environment: production(urlvars.APP_URL) and aconcurrency: deploy-productiongroup that never cancels a deploy already running.envand format-checked before thesedinjection. The step fails if any_PLACEHOLDERis left inwrangler.toml./api/healthmust returnstatus == "ok"and/must return successfully./api/configis also checked when the pipeline manages migrations.wrangler rollbackhint; nothing is rolled back automatically..github/scripts/d1-prepare-migrations.sh(new)d1_migrationsfrom the setup route's_schema_migrations, using the conventionschema_vN⇔migrations/000N_*.sql.0001_init.sqlonly after confirming every 0001 table andlinks.user_seqexist; otherwise it fails.TABLE_PREFIXis set or prefixed tables are detected.apps/worker/package.jsondb:migratenow passes--remote. Under wrangler v4 it previously applied migrations to the local database.DBinstead of the nameshortlink, which did not match the placeholder inwrangler.toml.turbo.json: thedeploytask gets"cache": false, so a cache hit can no longer skipwrangler deploy.Required GitHub configuration
productionenvironment with required reviewers, and restrict its deployment branches tomain.APP_URL. The smoke test fails without it.CLOUDFLARE_API_TOKENneeds D1 edit permission for the migration step.TABLE_PREFIXis set in Cloudflare, mirror it as a GitHub variable.v*tags.PAT_TOKENsecret is no longer used; deleting it is optional.Testing
actionlint1.7.12 (with shellcheck) passes on all workflows;shellcheckpasses on the script;pnpm checkpasses.d1-prepare-migrations.shwas run against local D1 (with--remoteswapped for--local) in these states:applyschema_v1recorded → baselines0001_init.sql, and wrangler then reports "No migrations to apply"applyskipTABLE_PREFIXset →skip0001_init.sqllinks.user_seq→ failsDBford1 migrations, and thatpnpm auditworks from the lockfile alone, withoutnode_modules.workflow_callpermission flow, remote migrations against production D1, and the smoke test against the live URL.