CI/CD Pipelines
Integrate Claude Code into your CI/CD pipeline for continuous quality assurance.
GitHub Actions Basics
Create .github/workflows/ci.yml:
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm ci
- run: npm test
- run: npm run buildClaude Code in CI
Automated Code Review
claude-review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Claude Code Review
run: |
npx @anthropic-ai/claude-code --auto \
"Review this PR for:
- Security issues
- Performance problems
- Code style violations
Output as GitHub PR comment"
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}Automated Fixes
claude-fix:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Fix Issues
run: |
npx @anthropic-ai/claude-code --auto \
"Fix all TypeScript errors and linting issues"
- name: Commit Fixes
run: |
git config user.name "Claude Code"
git config user.email "claude@ci"
git add -A
git diff --staged --quiet || git commit -m "fix: auto-fix issues"
git pushPipeline Stages
Complete Pipeline
name: Full Pipeline
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm run lint
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm test -- --coverage
build:
runs-on: ubuntu-latest
needs: [lint, test]
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm run build
deploy:
runs-on: ubuntu-latest
needs: build
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm run deployQuality Gates
Required Checks
Configure branch protection:
- Go to Settings > Branches
- Add rule for
main - Require status checks:
linttestbuild
Coverage Thresholds
- name: Check Coverage
run: |
npm test -- --coverage --coverageThreshold='{
"global": {
"branches": 80,
"functions": 80,
"lines": 80
}
}'Deployment Strategies
Preview Deployments
deploy-preview:
if: github.event_name == 'pull_request'
steps:
- run: vercel --token=${{ secrets.VERCEL_TOKEN }}Production Deployment
deploy-production:
if: github.ref == 'refs/heads/main'
steps:
- run: vercel --prod --token=${{ secrets.VERCEL_TOKEN }}Best Practices
Cache Dependencies
- uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}Parallel Jobs
jobs:
lint:
...
test:
...
# lint and test run in parallel
build:
needs: [lint, test] # waits for bothSecrets Management
Never commit secrets:
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
DATABASE_URL: ${{ secrets.DATABASE_URL }}Next Steps
In the final module, you'll get your 7-day action plan to master Claude Code.