CI and caching
What is cached
Section titled “What is cached”| Target | Cached | Inputs | Output |
|---|---|---|---|
build |
yes | Production files of the project and its dependencies, its package.json, the installed astro version |
dist/<project root> |
check |
yes | All files of the project, production files of its dependencies, the installed astro and typescript versions |
none |
test |
yes | All files of the project, production files of its dependencies | none |
dev, preview, sync |
no |
In a Bun workspace, generated projects use the lock file instead of the installed versions.
Production files are the named input production of your nx.json. Leave tests out of it, so that changing a test does not build the site again:
{ "namedInputs": { "default": ["{projectRoot}/**/*", "sharedGlobals"], "production": ["default", "!{projectRoot}/**/*.test.ts"], "sharedGlobals": [] }}Environment variables are not inputs. When a build reads one, add it to the inputs of its target.
Build what changed
Section titled “Build what changed”check needs @astrojs/check in the workspace root.
nx affected -t check test build --base=origin/mainA project is affected when the change touches it or a project it depends on. Imports in .astro files count, see Share code between apps.
GitHub Actions
Section titled “GitHub Actions”Pull requests run the affected projects, pushes to main run all of them:
name: CI
on: push: branches: [main] pull_request:
permissions: contents: read
jobs: ci: runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 with: fetch-depth: 0 # affected compares with the base branch - uses: pnpm/action-setup@v6 - uses: actions/setup-node@v7 with: node-version: 22 cache: pnpm - run: pnpm install --frozen-lockfile - if: github.event_name == 'pull_request' run: pnpm exec nx affected -t check test build env: NX_BASE: origin/${{ github.base_ref }} - if: github.event_name == 'push' run: pnpm exec nx run-many -t check test buildpnpm/action-setup reads the pnpm version from packageManager in the root package.json. check runs sync first, so sync needs no step.
Commit the synced package.json
Section titled “Commit the synced package.json”The build copies Astro versions from the root package.json into the one of each app. Commit that change. If your apps are pnpm, npm or yarn workspace packages, also run the install command once, so that the lock file matches and --frozen-lockfile passes in CI.