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/patterns.md
1# CI Optimization Patterns23Strategies for efficient CI/CD with Turborepo.45## PR vs Main Branch Builds67### PR Builds: Only Affected89Test only what changed in the PR:1011```yaml12- name: Test (PR)13if: github.event_name == 'pull_request'14run: turbo run build test --affected15```1617### Main Branch: Full Build1819Ensure complete validation on merge:2021```yaml22- name: Test (Main)23if: github.ref == 'refs/heads/main'24run: turbo run build test25```2627## Custom Git Ranges with --filter2829For advanced scenarios, use `--filter` with git refs:3031```bash32# Changes since specific commit33turbo run test --filter="...[abc123]"3435# Changes between refs36turbo run test --filter="...[main...HEAD]"3738# Changes in last 3 commits39turbo run test --filter="...[HEAD~3]"40```4142## Caching Strategies4344### Remote Cache (Recommended)4546Best performance - shared across all CI runs and developers:4748```yaml49env:50TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}51TURBO_TEAM: ${{ vars.TURBO_TEAM }}52```5354### actions/cache Fallback5556When remote cache isn't available:5758```yaml59- uses: actions/cache@v460with:61path: .turbo62key: turbo-${{ runner.os }}-${{ github.sha }}63restore-keys: |64turbo-${{ runner.os }}-${{ github.ref }}-65turbo-${{ runner.os }}-66```6768Limitations:6970- Cache is branch-scoped71- PRs restore from base branch cache72- Less efficient than remote cache7374## Matrix Builds7576Test across Node versions:7778```yaml79strategy:80matrix:81node: [18, 20, 22]8283steps:84- uses: actions/setup-node@v485with:86node-version: ${{ matrix.node }}8788- run: turbo run test89```9091## Parallelizing Across Jobs9293Split tasks into separate jobs:9495```yaml96jobs:97lint:98runs-on: ubuntu-latest99steps:100- run: turbo run lint --affected101102test:103runs-on: ubuntu-latest104steps:105- run: turbo run test --affected106107build:108runs-on: ubuntu-latest109needs: [lint, test]110steps:111- run: turbo run build112```113114### Cache Considerations115116When parallelizing:117118- Each job has separate cache writes119- Remote cache handles this automatically120- With actions/cache, use unique keys per job to avoid conflicts121122```yaml123- uses: actions/cache@v4124with:125path: .turbo126key: turbo-${{ runner.os }}-${{ github.job }}-${{ github.sha }}127```128129## Conditional Tasks130131Skip expensive tasks on draft PRs:132133```yaml134- name: E2E Tests135if: github.event.pull_request.draft == false136run: turbo run test:e2e --affected137```138139Or require label for full test:140141```yaml142- name: Full Test Suite143if: contains(github.event.pull_request.labels.*.name, 'full-test')144run: turbo run test145```146