Skip to content

ci: parsec.tools only changed when someone deployed it by hand - #3

Merged
jamesconwaydev merged 3 commits into
mainfrom
deploy-workflow
Nov 29, 2026
Merged

jamesconwaydev merged 3 commits into
mainfrom
deploy-workflow

Conversation

@jamesconwaydev

Copy link
Copy Markdown
Contributor

Problem

parsec.tools and docs.parsec.tools only change when someone runs wrangler pages deploy by 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.yml runs on every push to main and every pull request:

  • pnpm install --frozen-lockfile, pnpm build and pnpm check for both apps, with Node from .node-version.
  • wrangler pages deploy of apps/site/dist to parsec-site and apps/docs/dist to parsec-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.
  • The branch name is reduced to letters, digits and hyphens before it reaches the command.
  • A pull request from a fork has no CLOUDFLARE_API_TOKEN, so it builds and checks without deploying.
  • Every action is pinned by commit. Permissions are contents: read, and persist-credentials is off.

The token is a Cloudflare API token with only Cloudflare Pages: Edit, stored as the repo secret CLOUDFLARE_API_TOKEN.

Tests

  • actionlint is clean.
  • This PR's own run is the first real test. Once the secret exists, it should build and deploy a preview of this branch.

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 foothillsdigital left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.1 73e46992, setup-node v7.1.0 949feb24 and wrangler-action v4.1.3 953926a2.
  • contents: read, persist-credentials: false, and timeout-minutes.
  • BRANCH is reduced with tr -c 'A-Za-z0-9-' '-' before it's interpolated into command. Only a branch literally named main can come out as main, 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:

  1. A build job with no secrets: install, build, check, then actions/upload-artifact with apps/site/dist and apps/docs/dist.
  2. A deploy job that needs: build and runs only on push to main, or a PR whose head repo is this one. It gets actions/download-artifact and the two wrangler-action steps with wranglerVersion pinned, so the action installs Wrangler itself. No checkout of PR code, and no pnpm install.
  3. Optionally, environment: production on the main deploy, with deployment branches limited to main. 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.

@jamesconwaydev
jamesconwaydev merged commit 38e6869 into main Nov 29, 2026
1 check passed
@jamesconwaydev
jamesconwaydev deleted the deploy-workflow branch November 29, 2026 05:33
@jamesconwaydev

Copy link
Copy Markdown
Contributor Author

The workflow has now run for real: the token check printed token: set, and both sites deployed as previews of this branch, https://deploy-workflow.parsec-site.pages.dev and https://deploy-workflow.parsec-docs.pages.dev. Production only changes when this merges and main deploys.

Two commits were added since you were asked to review. One is empty, to trigger a fresh run. The other replaces the job-level secrets.X != '' expression with a step that checks for the token in the shell and logs "set" or "missing", never the value. The expression came out false even with the secret in place, so the step is the version that's been seen to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants