Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Configure and optimize Turborepo monorepo build pipelines with correct task structure, caching, and CI setup.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/ci/RULE.md
1# CI/CD with Turborepo23General principles for running Turborepo in continuous integration environments.45## Core Principles67### Always Use `turbo run` in CI89**Never use the `turbo <tasks>` shorthand in CI or scripts.** Always use `turbo run`:1011```bash12# CORRECT - Always use in CI, package.json, scripts13turbo run build test lint1415# WRONG - Shorthand is only for one-off terminal commands16turbo build test lint17```1819The shorthand `turbo <tasks>` is only for one-off invocations typed directly in terminal by humans or agents. Anywhere the command is written into code (CI, package.json, scripts), use `turbo run`.2021### Enable Remote Caching2223Remote caching dramatically speeds up CI by sharing cached artifacts across runs.2425Required environment variables:2627```bash28TURBO_TOKEN=your_vercel_token29TURBO_TEAM=your_team_slug30```3132### Use --affected for PR Builds3334The `--affected` flag only runs tasks for packages changed since the base branch:3536```bash37turbo run build test --affected38```3940This requires Git history to compute what changed.4142## Git History Requirements4344### Fetch Depth4546`--affected` needs access to the merge base. Shallow clones break this.4748```yaml49# GitHub Actions50- uses: actions/checkout@v451with:52fetch-depth: 2 # Minimum for --affected53# Use 0 for full history if merge base is far54```5556### Why Shallow Clones Break --affected5758Turborepo compares the current HEAD to the merge base with `main`. If that commit isn't fetched, `--affected` falls back to running everything.5960For PRs with many commits, consider:6162```yaml63fetch-depth: 0 # Full history64```6566## Environment Variables Reference6768| Variable | Purpose |69| ------------------- | ------------------------------------ |70| `TURBO_TOKEN` | Vercel access token for remote cache |71| `TURBO_TEAM` | Your Vercel team slug |72| `TURBO_REMOTE_ONLY` | Skip local cache, use remote only |73| `TURBO_LOG_ORDER` | Set to `grouped` for cleaner CI logs |7475## See Also7677- [github-actions.md](./github-actions.md) - GitHub Actions setup78- [vercel.md](./vercel.md) - Vercel deployment79- [patterns.md](./patterns.md) - CI optimization patterns80