Repository navigation
ci: split website workflow into validate + deploy-preview - #785
Conversation
|
🚀 Website Preview Deployed! Preview your changes at: https://cg-pr-785.billy-daly.workers.dev This preview will be automatically deleted when the PR is closed. |
|
I just want to confirm, does this block deploys if tests are failing? I kind of think we shouldn't generate a preview environment either in that case. |
|
@jcrichlake no, deploy isn't blocked on test failures. The gate is This was intentional though, I've found preview environments useful on prior repos for visually confirming what a failing test is catching, and for reviewing UI changes on a PR that happens to have an unrelated test regression. The argument for blocking is real: a passing preview on top of failing tests can mask a regression the reviewer might otherwise notice. If you'd rather make test-pass a hard gate, the change is one line, swap Leaning toward keeping it decoupled given prior experience with this pattern, but open to the stricter gate if you'd prefer it. |
| - name: Install dependencies | ||
| working-directory: . | ||
| run: pnpm install --frozen-lockfile |
There was a problem hiding this comment.
You might need to check me on this, but if we already have the build artifact I think we can just change the deploy preview command to pnpm dlx wrangler deploy ... and we can skip installing dependencies, which should save us some time.
There was a problem hiding this comment.
Good call. Switched to pnpm dlx wrangler@4 deploy … and dropped the workspace install from deploy-preview. One gotcha: pnpm 10's default rejects postinstall scripts unless allow-listed (ERR_PNPM_IGNORED_BUILDS), and pnpm dlx doesn't inherit the workspace's approved list, so the command ended up as pnpm --allow-build=workerd --allow-build=esbuild --allow-build=sharp dlx wrangler@4 deploy …. Pinned to major @4 to match the "wrangler": "^4.85.0" devDep in website/package.json. Net result: deploy-preview dropped from 55s to 39s on the latest run.
| # (artifact root = website/). The deploy-preview download then uses | ||
| # `path: website` to restore them at website/dist, website/cache, etc. | ||
| # Adding a path outside `website/` here will shrink the common prefix | ||
| # and silently shift download locations — keep new paths under website/. |
There was a problem hiding this comment.
@SnowboardTechie Can we try to state this a bit more succinctly and in plain language? Same is true for the other code comments here and the PR description:
I think the CI/CD changes in this PR are trying to do a few main things:
- We're splitting out these CI steps so they can (largely) run in parallel after a build succeeds:
- checks
- tests
- deploy preview
- We're uploading the build artifact so that even as we split out the deploy to a separate step we don't have to rebuild.
- All of these changes are designed to ultimately help us:
- Surface multiple issues (linting issues, failed tests, etc.) on a single CI/CD run rather than having to wait for a fix to an earlier issue to surface an issue in a subsequent step.
- Speed up development and (ideally) reduce our GH action runtimes
But the fact that I'm not totally sure and am having trouble reasoning about it suggests that we might need to simplify the PR description and the code comments here.
I'm all for using AI to streamline the creation of PRs, but I've noticed that AI-generated PRs tend to lose the forest for the trees a little bit, over explaining specific implementation details and consequently "burying the lead" (to mix metaphors) of what the PR is actually trying to accomplish.
There was a problem hiding this comment.
Fair. Rewrote the PR description to match the repo's template sections (it was ignoring three of them) and trimmed the workflow comments from ~35 lines to ~10, keeping only the three that document non-obvious behavior: the path-structure invariant on upload-artifact (real footgun, adding a path outside website/ silently shifts download locations), the pnpm audit 410 workaround (pre-existing), and the wrangler@4 + --allow-build context.
| - name: Run tests | ||
| # Run independently of checks so a real test failure still surfaces | ||
| # when an unrelated lint/format/spell/astro-check step has failed. | ||
| # Gated on build success because vitest needs the build outputs and | ||
| # the install tree. |
There was a problem hiding this comment.
FWIW I don't think this is true currently since it's a later step in the same job. To actually have them run independently the tests would need to run in a separate job.
If they were run independently and in parallel you would see them listed as multiple jobs in the action summary, but we just see two:
There was a problem hiding this comment.
By contrast this CI file does produce multiple concurrent runs because it splits these steps to separate jobs:
A notable tradeoff though is that the more jobs you split out CI checks to the faster you run up your GitHub action usage both because you have to install deps multiple times and because each separate job might be rounded up to the minute (but I could be wrong on that)
There was a problem hiding this comment.
You're right, "independently" was the wrong word. !cancelled() && steps.build.outcome == '"'"'success'"'"' doesn't create parallelism; it just prevents the default short-circuit-on-failure between sequential steps. Replaced the per-step comments with one comment above validate: saying exactly that: steps are sequential, but each runs regardless of the previous step's pass/fail so all failures surface in one run.
There was a problem hiding this comment.
Yeah, the per-job split is a real option and the tradeoff you name (N× install + minute rounding) is exactly the thing I'd want to measure before committing to it repo-wide. This PR is scoped to "run vitest on website PRs + decouple deploy from test/check/audit outcome," and the same question applies to ci-lib-core, ci-lib-cli, ci-lib-sdk, ci-lib-python-sdk, cleaner to evaluate holistically than spot-fix here. Keeping the current single-job-with-gating structure in this PR.
The website-preview workflow only ran build + checks on website/** PRs, leaving vitest exclusively to catalog-validate (which fires only on lockfile/dependabot file changes). #775 updated the key-contact form description in typespec-index.json without updating loader.spec.ts:44, and the path-filter gap let it land green. - Add a Run tests step to ci-website-preview.yml so vitest runs on website-only PRs (mirrors the build/checks/test ordering already encoded in the website ci script). - Lowercase the substring in the loader.spec.ts assertion to match the authoritative description in typespec-index.json (other 4 form entries use the same lowercase descriptive style).
- Capture validate's job output from the upload step (id: upload-build) rather than the build step, so deploy-preview only fires when the artifact is actually present (not just when the build script exited 0). Output renamed build_succeeded -> artifact_ready to match. - Switch deploy-preview's gate from `always()` to `!cancelled()` so a user-cancelled run doesn't still kick off the wrangler deploy. - Add an inline comment on the upload-artifact paths block calling out the common-prefix invariant: every entry must stay under `website/` or download paths silently shift.
The display name (CI - Website: Validate and Deploy Preview) is what shows up in the PR UI, so the file path mismatch is cosmetic. Dropping the rename trims the diff and avoids forcing external references (branch protection rules keyed on file path, bookmarks, etc.) to follow. The validate + deploy-preview job split stays as-is.
The audit step previously ran sequentially after checks and tests, so a failure in either step would skip the audit and leave a vulnerable dependency unsurfaced for the run. Gate on build success (the script needs node_modules) and `!cancelled()` so a user-cancel still skips it.
The Run tests step previously short-circuited when Run all checks failed, masking real test failures behind unrelated lint/format/ spell/astro-check noise and forcing another CI cycle to learn whether the code logic was fine. Apply the same gate the audit step uses (`!cancelled() && build success`) so checks, tests, and audit each surface their own failures in one run.
- deploy-preview: drop workspace install, use `pnpm dlx wrangler@4 deploy` against the uploaded artifact. The @4 pin matches the ^4.85.0 devDep in website/package.json. - Trim verbose workflow comments to the three that document non-obvious behavior (upload-artifact path-prefix invariant, pnpm audit 410 workaround, and the wrangler version pin). - Gate `Run all checks` on `!cancelled() && steps.build.outcome == 'success'` to match the gate already on `Run tests` and `Audit dependencies`. A lint/check failure no longer short-circuits the remaining post-build steps, so all failures surface in a single CI run.
…gler pnpm 10's default rejects install scripts unless explicitly allow-listed (ERR_PNPM_IGNORED_BUILDS). The workspace allows these via its approved list, but `pnpm dlx` creates a fresh install scope that doesn't inherit it — so the flags have to be passed on the command itself.
1c97c23 to
d5a98e2
Compare
|
🗑️ Preview Cleaned Up The preview for this PR has been automatically deleted. |
Summary
Runs vitest on website PRs and decouples the Cloudflare preview deploy from check/test/audit outcome.
Changes proposed
.github/workflows/ci-website-preview.yml:CI - Website: Validate and Deploy Preview.build-and-deploy-previewjob intovalidate(install / build / upload-artifact / checks / tests / audit) anddeploy-preview(download-artifact / wrangler deploy / post preview comment).validatevia a newRun testsstep — previously vitest only ran viaci-catalog-validation.yml, which triggers onpnpm-workspace.yaml/pnpm-lock.yaml/.github/dependabot.yml, so website-only diffs bypassed tests entirely.Run all checks,Run tests, andAudit dependencieson!cancelled() && steps.build.outcome == 'success'so all three run regardless of which one fails first.deploy-previewusespnpm dlx wrangler@4 deployagainst the uploaded artifact, so the deploy job no longer runspnpm install. The@4pin matches the^4.85.0devDep inwebsite/package.json.validate.outputs.artifact_readyfrom theUpload build outputstep;deploy-previewgates on that pluspull_request && !dependabot. A build failure blocks the preview; a test/check/audit failure does not.Context for reviewers
The job split serves two goals beyond fixing the test gap. Build runs once and the output is shared with
deploy-previewvia artifact, so the deploy job skips rebuild and workspace install. And with the per-step!cancelled()gating onvalidate, a lint failure no longer short-circuits tests or audit — all three surface in a single CI run.Deploy decoupling from test outcome is intentional. Previews stay available for reviewing UI changes on a PR that happens to have an unrelated test or lint regression. If the team prefers strict gating, swapping
needs.validate.outputs.artifact_ready == 'true'forneeds.validate.result == 'success'is a one-line change (see the thread with @jcrichlake).Branch-protection heads-up: the required check name was
build-and-deploy-preview. After this lands it becomesvalidateanddeploy-preview. Anyone with branch-protection rules keyed on the old name will need to update the repo settings.Verified locally with
pnpm --filter website run build && pnpm --filter website run test(60/60 vitest pass) andactionlinton the workflow file. This PR's own CI run is the first exercise of the new structure.Additional information
N/A — no UI changes.