Skip to content

ci: split website workflow into validate + deploy-preview - #785

Merged
SnowboardTechie merged 9 commits into
mainfrom
fix/form-loader-test-and-ci-gap
May 6, 2026
Merged

SnowboardTechie merged 9 commits into
mainfrom
fix/form-loader-test-and-ci-gap

Conversation

@SnowboardTechie

@SnowboardTechie SnowboardTechie commented Apr 28, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Runs vitest on website PRs and decouples the Cloudflare preview deploy from check/test/audit outcome.

  • Time to review: 10 minutes

Changes proposed

  • .github/workflows/ci-website-preview.yml:
    • Rename display name to CI - Website: Validate and Deploy Preview.
    • Split the single build-and-deploy-preview job into validate (install / build / upload-artifact / checks / tests / audit) and deploy-preview (download-artifact / wrangler deploy / post preview comment).
    • Run vitest in validate via a new Run tests step — previously vitest only ran via ci-catalog-validation.yml, which triggers on pnpm-workspace.yaml / pnpm-lock.yaml / .github/dependabot.yml, so website-only diffs bypassed tests entirely.
    • Gate Run all checks, Run tests, and Audit dependencies on !cancelled() && steps.build.outcome == 'success' so all three run regardless of which one fails first.
    • deploy-preview uses pnpm dlx wrangler@4 deploy against the uploaded artifact, so the deploy job no longer runs pnpm install. The @4 pin matches the ^4.85.0 devDep in website/package.json.
    • Expose validate.outputs.artifact_ready from the Upload build output step; deploy-preview gates on that plus pull_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-preview via artifact, so the deploy job skips rebuild and workspace install. And with the per-step !cancelled() gating on validate, 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' for needs.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 becomes validate and deploy-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) and actionlint on the workflow file. This PR's own CI run is the first exercise of the new structure.

Additional information

N/A — no UI changes.

@SnowboardTechie SnowboardTechie added ci Issue or PR related to CI/CD workflows website Issues related to the website labels Apr 28, 2026
@github-actions github-actions Bot added the typescript Issue or PR related to TypeScript tooling label Apr 28, 2026
@github-actions

github-actions Bot commented Apr 28, 2026 •

Copy link
Copy Markdown
Contributor

🚀 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.

@SnowboardTechie SnowboardTechie changed the title ci: run vitest on website PRs and fix stale key-contact assertion ci: split website workflow into validate + deploy-preview Apr 28, 2026
@SnowboardTechie
SnowboardTechie marked this pull request as ready for review April 28, 2026 19:58
@jcrichlake

Copy link
Copy Markdown
Collaborator

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.

@SnowboardTechie

SnowboardTechie commented Apr 28, 2026 •

Copy link
Copy Markdown
Collaborator Author

@jcrichlake no, deploy isn't blocked on test failures. The gate is artifact_ready (build succeeded and the artifact uploaded), so a build failure stops the preview but a test, check, or audit failure doesn't.

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 needs.validate.outputs.artifact_ready == 'true' for needs.validate.result == 'success'.

Leaning toward keeping it decoupled given prior experience with this pattern, but open to the stricter gate if you'd prefer it.

Comment on lines +129 to +131
- name: Install dependencies
working-directory: .
run: pnpm install --frozen-lockfile

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.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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/.

@widal001 widal001 Apr 29, 2026 •

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.

@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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

Comment on lines +81 to +85
- 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.

@widal001 widal001 Apr 29, 2026 •

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.

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:

Image

@widal001 widal001 Apr 29, 2026 •

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.

By contrast this CI file does produce multiple concurrent runs because it splits these steps to separate jobs:

Image

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)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.
@SnowboardTechie
SnowboardTechie force-pushed the fix/form-loader-test-and-ci-gap branch from 1c97c23 to d5a98e2 Compare April 29, 2026 16:47
@SnowboardTechie
SnowboardTechie merged commit b038b10 into main May 6, 2026
5 checks passed
@SnowboardTechie
SnowboardTechie deleted the fix/form-loader-test-and-ci-gap branch May 6, 2026 14:41
@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

🗑️ Preview Cleaned Up

The preview for this PR has been automatically deleted.

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

Labels

ci Issue or PR related to CI/CD workflows typescript Issue or PR related to TypeScript tooling website Issues related to the website

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants