CI/CD Integration: Automate AI-Assisted Workflows
Integrate CCJK into your CI/CD pipeline for automated code reviews, test generation, and documentation updates.
CI/CD Integration: Automate AI-Assisted Workflows
Integrating AI assistance into your CI/CD pipeline unlocks powerful automation capabilities. From automated code reviews to intelligent test generation, CCJK can enhance every stage of your development workflow.
Overview
What Can Be Automated?
| Stage | AI Capability |
|---|---|
| Pre-commit | Code formatting, linting suggestions |
| Pull Request | Automated code review, security scan |
| Build | Documentation generation |
| Test | Test coverage analysis, test generation |
| Deploy | Release notes, changelog generation |
GitHub Actions Integration
Basic Setup
Create a workflow file:
hljs yaml# .github/workflows/ai-review.yml
name: AI Code Review
on:
pull_request:
types: [opened, synchronize]
jobs:
ai-review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install CCJK
run: npm install -g ccjk
- name: Run AI Review
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
ccjk review --ci --output github-pr
Advanced Review Workflow
hljs yaml# .github/workflows/comprehensive-review.yml
name: Comprehensive AI Review
on:
pull_request:
types: [opened, synchronize, ready_for_review]
jobs:
code-review:
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- run: npm ci
- run: npm install -g ccjk
- name: Code Quality Review
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
ccjk review \
--focus quality \
--severity-threshold minor \
--output review-quality.md
- name: Security Review
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
ccjk review \
--focus security \
--severity-threshold critical \
--output review-security.md
- name: Performance Review
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
ccjk review \
--focus performance \
--output review-performance.md
- name: Post Review Comments
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const reviews = [
'review-quality.md',
'review-security.md',
'review-performance.md'
];
let body = '## AI Code Review Summary\n\n';
for (const file of reviews) {
if (fs.existsSync(file)) {
body += fs.readFileSync(file, 'utf8') + '\n\n';
}
}
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});
Automated Test Generation
On New Code
hljs yaml# .github/workflows/test-generation.yml
name: AI Test Generation
on:
pull_request:
paths:
- 'src/**/*.ts'
- 'src/**/*.tsx'
jobs:
generate-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup
uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm ci
- run: npm install -g ccjk
- name: Identify Changed Files
id: changed
run: |
FILES=$(git diff --name-only origin/main...HEAD | grep -E '\.(ts|tsx)$' | grep -v '\.test\.' | tr '\n' ' ')
echo "files=$FILES" >> $GITHUB_OUTPUT
- name: Generate Tests
if: steps.changed.outputs.files != ''
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
for file in ${{ steps.changed.outputs.files }}; do
ccjk test generate "$file" --output "${file%.ts}.test.ts"
done
- name: Run Generated Tests
run: npm test -- --passWithNoTests
- name: Create PR with Tests
uses: peter-evans/create-pull-request@v5
with:
title: "test: Add AI-generated tests"
body: "Automated test generation for new code"
branch: ai-tests-${{ github.event.pull_request.number }}
Documentation Automation
Auto-Generate API Docs
hljs yaml# .github/workflows/docs-generation.yml
name: Documentation Generation
on:
push:
branches: [main]
paths:
- 'src/api/**'
jobs:
generate-docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup
uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm ci
- run: npm install -g ccjk
- name: Generate API Documentation
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
ccjk docs generate \
--input src/api/ \
--output docs/api/ \
--format markdown
- name: Generate OpenAPI Spec
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
ccjk docs openapi \
--input src/api/ \
--output docs/openapi.yaml
- name: Commit Documentation
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "docs: Update API documentation"
file_pattern: "docs/**"
Changelog Generation
hljs yaml# .github/workflows/changelog.yml
name: Changelog Generation
on:
release:
types: [created]
jobs:
changelog:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup
uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm install -g ccjk
- name: Generate Changelog
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^)
ccjk changelog generate \
--from $PREV_TAG \
--to ${{ github.ref_name }} \
--output CHANGELOG_ENTRY.md
- name: Update Release Notes
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const changelog = fs.readFileSync('CHANGELOG_ENTRY.md', 'utf8');
await github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: ${{ github.event.release.id }},
body: changelog
});
GitLab CI Integration
hljs yaml# .gitlab-ci.yml
stages:
- review
- test
- docs
variables:
ANTHROPIC_API_KEY: $ANTHROPIC_API_KEY
ai-review:
stage: review
image: node:20
script:
- npm install -g ccjk
- ccjk review --ci --output gitlab-mr
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
ai-test-coverage:
stage: test
image: node:20
script:
- npm ci
- npm install -g ccjk
- npm test -- --coverage
- ccjk analyze coverage --input coverage/lcov.info --suggest-tests
artifacts:
reports:
coverage_report:
coverage_format: cobertura
path: coverage/cobertura-coverage.xml
ai-docs:
stage: docs
image: node:20
script:
- npm install -g ccjk
- ccjk docs generate --input src/ --output public/docs/
artifacts:
paths:
- public/docs/
rules:
- if: $CI_COMMIT_BRANCH == "main"
Pre-commit Hooks
Setup with Husky
hljs bash# Install husky
npm install -D husky
npx husky init
hljs bash# .husky/pre-commit
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
# Run AI-assisted pre-commit checks
npx ccjk precommit --staged-only
Pre-commit Configuration
hljs yaml# .claude/precommit.yaml
checks:
- name: "Code Quality"
command: ccjk lint --fix
on: ["*.ts", "*.tsx", "*.js", "*.jsx"]
- name: "Security Scan"
command: ccjk security --quick
on: ["*.ts", "*.tsx"]
block: true # Block commit if issues found
- name: "Commit Message"
command: ccjk commit --validate
on: commit-msg
Best Practices
1. Rate Limiting
Avoid excessive API calls:
hljs yaml# Only run on significant changes
on:
pull_request:
paths:
- 'src/**'
- '!src/**/*.test.*'
- '!src/**/*.spec.*'
- '!**/*.md'
2. Caching
Cache AI responses where appropriate:
hljs yaml- name: Cache AI Responses
uses: actions/cache@v3
with:
path: .ccjk-cache
key: ccjk-${{ hashFiles('src/**') }}
3. Cost Management
Set spending limits:
hljs yaml- name: AI Review
env:
CCJK_MAX_TOKENS: 10000
CCJK_MAX_COST: 0.50
run: ccjk review --ci
4. Fallback Handling
Handle API failures gracefully:
hljs yaml- name: AI Review
continue-on-error: true
id: ai-review
run: ccjk review --ci
- name: Fallback Notice
if: steps.ai-review.outcome == 'failure'
run: echo "AI review unavailable, manual review required"
Security Considerations
Secrets Management
hljs yaml# Use GitHub secrets
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
# Never log secrets
- name: Review
run: |
ccjk review --ci 2>&1 | grep -v "API"
Code Privacy
Configure what gets sent to AI:
hljs yaml# .claude/ci-config.yaml
privacy:
exclude:
- "**/*.env*"
- "**/secrets/**"
- "**/credentials/**"
redact:
- pattern: "api[_-]?key"
replacement: "[REDACTED]"
- pattern: "password"
replacement: "[REDACTED]"
Monitoring and Metrics
Track AI CI Performance
hljs yaml- name: Record Metrics
run: |
echo "review_duration=${{ steps.review.outputs.duration }}" >> metrics.txt
echo "issues_found=${{ steps.review.outputs.issues }}" >> metrics.txt
echo "tokens_used=${{ steps.review.outputs.tokens }}" >> metrics.txt
- name: Send to Monitoring
run: |
curl -X POST ${{ secrets.METRICS_ENDPOINT }} \
-d @metrics.txt
Conclusion
CI/CD integration transforms AI assistance from a developer tool into a team-wide quality gate. Start with simple review automation, then gradually add more sophisticated workflows.
Key benefits:
- Consistent code quality across all PRs
- Reduced manual review burden
- Faster feedback loops
- Automated documentation
Next: Learn about VS Code Integration for a seamless development experience.
Related Articles
Understanding AI Agents in CCJK
Discover how AI agents work in CCJK and learn to leverage them for automated development workflows.
Understanding AI Agents: Autonomous Coding Assistants
Explore how AI agents in CCJK can autonomously handle complex, multi-step development tasks while you focus on high-level decisions.
Advanced Prompt Engineering for AI-Assisted Development
Master the art of crafting effective prompts to maximize your productivity with AI coding assistants. Learn proven techniques used by expert developers.
