advanced⏱60 minLesson 2 of 5
CI/CD Integration Patterns
Integrate OpenCode into your CI/CD pipelines. Learn automated code review, testing workflows, deployment automation, and quality gates for continuous integration.
CI/CD Integration Patterns
Why Integrate OpenCode with CI/CD?
| Benefit | Description |
|---|---|
| Automated Review | AI catches issues before human review |
| Consistent Quality | Same standards every commit |
| Faster Feedback | Developers get instant feedback |
| Cost Reduction | Fewer human review cycles |
GitHub Actions Integration
Basic Workflow
Create .github/workflows/opencode-review.yml:
yaml
name: OpenCode Review
on:
pull_request:
types: [opened, synchronize]
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Install OpenCode
run: npm install -g opencode
- name: Run Code Review
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
opencode run "Review this pull request for security vulnerabilities and code quality issues" \
--output review.md
- name: Comment on PR
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const review = fs.readFileSync('review.md', 'utf8');
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: review
});GitLab CI Integration
Create .gitlab-ci.yml:
yaml
stages:
- review
- test
- deploy
opencode-review:
stage: review
image: node:18
script:
- npm install -g opencode
- opencode run "Review changed files for issues" > review.txt
artifacts:
paths:
- review.txt
only:
- merge_requestsQuality Gates
Pre-commit Hook
Create .husky/pre-commit:
bash
#!/bin/bash
opencode run "Check if staged files follow coding standards" || exit 1PR Validation
yaml
- name: Validate PR
run: |
opencode run "Validate:
1. All tests pass
2. No security vulnerabilities
3. Code follows style guide
4. Documentation is updated" \
--output validation-report.mdAutomated Testing
Test Generation
yaml
- name: Generate Tests
run: |
opencode run "Generate unit tests for all functions in src/utils.ts" \
--output tests/utils.test.tsTest Coverage
yaml
- name: Check Coverage
run: |
npm test -- --coverage
opencode run "Analyze test coverage and suggest improvements" \
--output coverage-analysis.mdDeployment Automation
Changelog Generation
yaml
- name: Generate Changelog
run: |
opencode run "Generate changelog from git commits since last release" \
--output CHANGELOG.mdRelease Notes
yaml
- name: Create Release Notes
if: starts_with(github.ref, 'refs/tags/')
run: |
opencode run "Create release notes for version ${{ github.ref_name }}" \
--output release-notes.mdSecurity Integration
Vulnerability Scanning
yaml
- name: Security Scan
run: |
opencode run "Scan codebase for:
1. SQL injection vulnerabilities
2. XSS vulnerabilities
3. Hardcoded secrets
4. Insecure dependencies" \
--output security-report.mdLicense Compliance
yaml
- name: License Check
run: |
opencode run "Check all dependencies have compatible licenses" \
--output license-report.mdBest Practices
| Practice | Reason |
|---|---|
| Cache dependencies | Faster pipeline execution |
| Set timeouts | Prevent hanging jobs |
| Use secrets | Never commit API keys |
| Parallel jobs | Faster feedback |
| Artifact storage | Keep reports accessible |
Practice Questions
Practice Question
What is the primary benefit of integrating OpenCode with CI/CD?
Practice Question
Where should API keys be stored in GitHub Actions?
Practice Question
What does the opencode run command do in CI/CD?
Practice Question
How do you capture OpenCode output in CI/CD?
Practice Question
What should you do to prevent CI/CD jobs from hanging?
Success
Key Takeaways
- Integrate OpenCode with GitHub Actions or GitLab CI for automated review
- Use the --output flag to capture results in files
- Store API keys in GitHub Secrets or GitLab CI Variables
- Quality gates catch issues before human review
- Security scanning can detect vulnerabilities automatically
- Cache dependencies and set timeouts for faster, reliable pipelines
- Parallel jobs provide faster feedback to developers
Progress40%