.agents/skills/turborepo/references/ci/patterns.md
Strategies for efficient CI/CD with Turborepo.
Test only what changed in the PR:
- name: Test (PR)
if: github.event_name == 'pull_request'
run: turbo run build test --affected
Ensure complete validation on merge:
- name: Test (Main)
if: github.ref == 'refs/heads/main'
run: turbo run build test
For advanced scenarios, use --filter with git refs:
# Changes since specific commit
turbo run test --filter="...[abc123]"
# Changes between refs
turbo run test --filter="...[main...HEAD]"
# Changes in last 3 commits
turbo run test --filter="...[HEAD~3]"
Best performance - shared across all CI runs and developers:
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
When remote cache isn't available:
- uses: actions/cache@v4
with:
path: .turbo
key: turbo-${{ runner.os }}-${{ github.sha }}
restore-keys: |
turbo-${{ runner.os }}-${{ github.ref }}-
turbo-${{ runner.os }}-
Limitations:
Test across Node versions:
strategy:
matrix:
node: [18, 20, 22]
steps:
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- run: turbo run test
Split tasks into separate jobs:
jobs:
lint:
runs-on: ubuntu-latest
steps:
- run: turbo run lint --affected
test:
runs-on: ubuntu-latest
steps:
- run: turbo run test --affected
build:
runs-on: ubuntu-latest
needs: [lint, test]
steps:
- run: turbo run build
When parallelizing:
- uses: actions/cache@v4
with:
path: .turbo
key: turbo-${{ runner.os }}-${{ github.job }}-${{ github.sha }}
Skip expensive tasks on draft PRs:
- name: E2E Tests
if: github.event.pull_request.draft == false
run: turbo run test:e2e --affected
Or require label for full test:
- name: Full Test Suite
if: contains(github.event.pull_request.labels.*.name, 'full-test')
run: turbo run test