advanced60 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?

BenefitDescription
Automated ReviewAI catches issues before human review
Consistent QualitySame standards every commit
Faster FeedbackDevelopers get instant feedback
Cost ReductionFewer 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_requests

Quality Gates

Pre-commit Hook

Create .husky/pre-commit:

bash
#!/bin/bash opencode run "Check if staged files follow coding standards" || exit 1

PR 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.md

Automated Testing

Test Generation

yaml
- name: Generate Tests run: | opencode run "Generate unit tests for all functions in src/utils.ts" \ --output tests/utils.test.ts

Test Coverage

yaml
- name: Check Coverage run: | npm test -- --coverage opencode run "Analyze test coverage and suggest improvements" \ --output coverage-analysis.md

Deployment Automation

Changelog Generation

yaml
- name: Generate Changelog run: | opencode run "Generate changelog from git commits since last release" \ --output CHANGELOG.md

Release 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.md

Security 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.md

License Compliance

yaml
- name: License Check run: | opencode run "Check all dependencies have compatible licenses" \ --output license-report.md

Best Practices

PracticeReason
Cache dependenciesFaster pipeline execution
Set timeoutsPrevent hanging jobs
Use secretsNever commit API keys
Parallel jobsFaster feedback
Artifact storageKeep 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%