CI/CD Integration¶
Using Stack with continuous integration and deployment.
How Stack Works with CI¶
Each branch in a stack triggers its own CI run:
main
└── feature/models PR #1 → CI Run #1
└── feature/api PR #2 → CI Run #2
└── feature/ui PR #3 → CI Run #3
CI Status in Stack¶
View CI status with:
Output shows CI status:
Best Practices¶
Test Dependencies Correctly¶
Each PR should pass CI independently:
# .github/workflows/test.yml
on:
pull_request:
branches: [main, 'feature/**']
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm test
Fast CI for Faster Stacks¶
Slow CI blocks the whole stack. Optimize:
- Use caching
- Run tests in parallel
- Skip unnecessary checks on dependent PRs
Branch Protection¶
Configure branch protection to require CI:
GitHub Actions Example¶
name: CI
on:
push:
branches: [main]
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Needed for accurate diffs
- name: Setup
run: npm ci
- name: Lint
run: npm run lint
- name: Test
run: npm test
- name: Build
run: npm run build
GitLab CI Example¶
stages:
- test
- build
test:
stage: test
script:
- npm ci
- npm test
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH == "main"
build:
stage: build
script:
- npm run build
rules:
- if: $CI_COMMIT_BRANCH == "main"
Handling CI Failures¶
When CI fails on a branch in your stack:
# Go to the failing branch
gt checkout feature/failing-branch
# Fix the issue
vim src/broken-test.rs
# Update the commit
git add .
gt modify
# Restack downstream branches
gt restack
# Push all updates
gt submit
Auto-merge on CI Pass¶
Some teams auto-merge when CI passes:
GitHub¶
Enable "Auto-merge" on PRs, then:
GitLab¶
Use "Merge when pipeline succeeds":
Tips¶
- Keep CI fast - Under 10 minutes ideal
- Cache dependencies - Don't download on every run
- Test the right things - Focus on what changed
- Parallelize - Run independent tests concurrently