Skip to content

ci: share codegen output across jobs via artifact#171

Merged
pgherveou merged 4 commits into
mainfrom
ci/share-codegen-artifact
Jun 4, 2026
Merged

ci: share codegen output across jobs via artifact#171
pgherveou merged 4 commits into
mainfrom
ci/share-codegen-artifact

Conversation

@eugypalu

@eugypalu eugypalu commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Closes #134.

The codegen job is the single place that runs scripts/codegen.sh (and therefore the only job that builds the Rust crate to produce the rustdoc JSON). It uploads the generated TypeScript surface as a codegen-output artifact:

  • js/packages/truapi/src/generated
  • js/packages/truapi/src/playground/codegen
  • js/packages/truapi/src/explorer/codegen + src/explorer/versions.ts
  • js/packages/truapi-host/src/generated
  • playground/test/generated

The downstream jobs (ts-client, playground, explorer) download that artifact before npm ci. With the generated files already present, scripts/ensure-generated.sh short-circuits, so npm ci/npm run build compile the client with tsc alone and never invoke codegen.sh.

Because those jobs no longer touch Rust, the dtolnay/rust-toolchain and Swatinem/rust-cache steps are dropped from them, and the explicit ./scripts/codegen.sh invocations in playground and explorer are removed. ts-client now declares needs: codegen so the artifact is available when it runs.

@eugypalu eugypalu requested a review from a team June 3, 2026 12:15
@pgherveou

Copy link
Copy Markdown
Collaborator

Review: share codegen output across jobs via artifact

Summary. The codegen job becomes the single place that runs scripts/codegen.sh (and thus the only job that builds the Rust crate for rustdoc JSON). It uploads the generated TypeScript surface as the codegen-output artifact; ts-client, playground, explorer, and e2e download it before npm ci, so ensure-generated.sh short-circuits and those jobs compile with tsc alone. The Rust toolchain + cache steps and the explicit ./scripts/codegen.sh calls are dropped from the downstream jobs, and a new TRUAPI_REQUIRE_GENERATED=1 guard makes ensure-generated.sh fail loudly (instead of silently re-running codegen) when the artifact didn't restore the expected files.

Why all three mechanisms are needed (not just needs:): GitHub Actions jobs run on separate ephemeral runners with no shared filesystem, and the generated files are gitignored, so needs: alone transfers nothing — a downstream job would check out a tree with no generated files. The artifact is the actual data transfer; needs: only orders the jobs; TRUAPI_REQUIRE_GENERATED=1 is a fail-fast guard that turns "files missing → silently run codegen → cryptic cargo error (toolchain now removed)" into a clear "add the path to the upload-artifact step" message.

Findings

# Severity File Description
1 Info .github/workflows/ci.yml TRUAPI_REQUIRE_GENERATED: 1 is repeated across 4 jobs. Could be hoisted to a workflow-level env:. Harmless to set globally: the rust job never runs ensure-generated.sh, and codegen always produces the files so the guard never trips. DRY nit only.
2 Info .github/workflows/ci.yml The graph now serializes codegen → ts-client → {playground, explorer} → e2e. This trades parallelism for not rebuilding Rust 4×; net win, but codegen is now a hard gate on everything downstream.

Verified

  • Artifact paths cover every required file. Both ensure-generated.sh checklists (truapi: src/generated/{client,types,wire-table}.ts, playground/codegen/services.ts, explorer/codegen/types.ts, explorer/versions.ts, playground/test/generated/examples/*.ts; host: server.ts, types-by-version.ts) are fully covered by the six upload paths.
  • Path consistency. codegen.sh writes examples to playground/test/generated/examples, matching both the ensure-generated check and the upload path.
  • upload-artifact@v4 least-common-ancestor behavior preserves repo-root-relative structure (paths span js/... and playground/...), so download restores files to the correct locations.
  • Dependency chain reaches codegen transitively from every artifact consumer.
  • if-no-files-found: error and retention-days: 1 are appropriate.

Verdict: Mergeable. Clean PR, satisfies #134 (single Rust build, generated surface shared via artifact). The two items above are Info-only. A fresh CI run is currently in progress on a diff identical to the previously-green run.


Reviewed with assistance from Claude Code.

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

LGTM — clean artifact-sharing refactor for #134. Only Info-level nits (see review comment). Verified artifact paths cover all required generated files and the dependency chain reaches codegen.

@pgherveou pgherveou enabled auto-merge June 4, 2026 11:06
@pgherveou pgherveou merged commit e2c4903 into main Jun 4, 2026
11 checks passed
@pgherveou pgherveou deleted the ci/share-codegen-artifact branch June 4, 2026 11:09
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.

CI: share codegen output across jobs instead of re-running codegen.sh per job

2 participants