Repository navigation
ci: parsec.tools only changed when someone deployed it by hand - #3
Conversation
Cloudflare Pages can't read this repo through its GitHub app (it fails to list the branches), so the sites were uploaded with wrangler after each merge. A workflow now builds and checks both apps on every push and pull request, deploys main to production and each pull request to a preview named after its branch. Pull requests from forks have no token, so they build without deploying.
foothillsdigital
left a comment
There was a problem hiding this comment.
Approving edb4b45, with one structural change I'd make before the secret goes in. It's not a blocker.
What's right:
- All four pins match their tags: checkout v7.0.1
3d3c42e5, pnpm/action-setup v6.1.173e46992, setup-node v7.1.0949feb24and wrangler-action v4.1.3953926a2. contents: read,persist-credentials: false, andtimeout-minutes.BRANCHis reduced withtr -c 'A-Za-z0-9-' '-'before it's interpolated intocommand. Only a branch literally namedmaincan come out asmain, so a same-repo PR can't name its way into production.- The token check prints only "set" or "missing". A fork PR, or Dependabot's, builds and checks without deploying.
- The first run on this PR shows install, build and check all succeeding, and both deploys skipped, as expected before the secret exists.
The change I'd make: deploy in a second job that never installs dependencies. Right now pnpm install, pnpm build (Astro, Starlight and their plugins) and the two wrangler-action steps share one runner. The token is only in the deploy steps' inputs, but anything that ran earlier in the job can tamper with what those steps run. And wrangler-action's README says: "If you omit wranglerVersion and Wrangler is already installed in your environment, the action uses the existing installation." Here that's node_modules/.bin/wrangler, from the root devDependencies, installed and runnable by everything before it. A compromised dependency or build plugin could swap it out and read a token that can deploy to every Pages project on the account, at any time later. A defaced build would only last until the next deploy.
The usual shape, which costs a few lines:
- A
buildjob with no secrets: install, build, check, thenactions/upload-artifactwithapps/site/distandapps/docs/dist. - A
deployjob thatneeds: buildand runs only onpushto main, or a PR whose head repo is this one. It getsactions/download-artifactand the twowrangler-actionsteps withwranglerVersionpinned, so the action installs Wrangler itself. No checkout of PR code, and nopnpm install. - Optionally,
environment: productionon the main deploy, with deployment branches limited tomain. One "Pages: Edit" token can still deploy to production from a preview job, so separate tokens would take two accounts or two projects. That's likely not worth it here.
The build-time risk of a malicious dependency writing bad content into dist stays either way. The split only keeps the token out of reach, which is the part that outlives a single deploy.
|
The workflow has now run for real: the token check printed Two commits were added since you were asked to review. One is empty, to trigger a fresh run. The other replaces the job-level |
Problem
parsec.tools and docs.parsec.tools only change when someone runs
wrangler pages deployby hand after a merge, and pull requests get no preview. Cloudflare's GitHub app is installed on parsec-html for this repo, but Cloudflare can't list the repo's branches through it ("There was a problem retrieving this data" in the dashboard, "internal issue with your Cloudflare Pages Git installation" from the API), so a Git-connected Pages project can't be made.Change
.github/workflows/deploy.ymlruns on every push to main and every pull request:pnpm install --frozen-lockfile,pnpm buildandpnpm checkfor both apps, with Node from.node-version.wrangler pages deployofapps/site/disttoparsec-siteandapps/docs/disttoparsec-docs. main goes to production, which is parsec.tools and docs.parsec.tools. A pull request goes to a preview named after its branch, with the URLs in the job summary.CLOUDFLARE_API_TOKEN, so it builds and checks without deploying.contents: read, andpersist-credentialsis off.The token is a Cloudflare API token with only Cloudflare Pages: Edit, stored as the repo secret
CLOUDFLARE_API_TOKEN.Tests
actionlintis clean.