Skip to content

CI and caching

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:

nx.json
{
"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.

check needs @astrojs/check in the workspace root.

Terminal window
nx affected -t check test build --base=origin/main

A project is affected when the change touches it or a project it depends on. Imports in .astro files count, see Share code between apps.

Pull requests run the affected projects, pushes to main run all of them:

.github/workflows/ci.yml
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 build

pnpm/action-setup reads the pnpm version from packageManager in the root package.json. check runs sync first, so sync needs no step.

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.

nx-astro 3.2.0 · MIT Developed by