Your CI/CD pipeline runs linters, tests, and deploys. But it doesnβt understand your code. Adding AI to the pipeline gives you automated code review, intelligent test generation, and deployment risk assessment β without a human in the loop.
AI code review in GitHub Actions
# .github/workflows/ai-review.yml
name: AI Code Review
on: [pull_request]
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get PR diff
run: git diff origin/main...HEAD > diff.txt
- name: AI Review
run: |
REVIEW=$(curl -s https://openrouter.ai/api/v1/chat/completions \
-H "Authorization: Bearer ${{ secrets.OPENROUTER_KEY }}" \
-H "Content-Type: application/json" \
-d "{
\"model\": \"openai/gpt-5.4-mini\",
\"messages\": [{
\"role\": \"user\",
\"content\": \"Review this code diff for security issues, bugs, and performance problems. Be specific and actionable. Format as a GitHub comment with markdown.\n\nDiff:\n$(cat diff.txt | head -500)\"
}]
}" | jq -r '.choices[0].message.content')
# Post as PR comment
gh pr comment ${{ github.event.pull_request.number }} --body "$REVIEW"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Cost: ~$0.01-0.05 per PR review with GPT-5.4 Mini. For free, use Qwen 3.6 Plus via OpenRouter.
AI-generated PR descriptions
- name: Generate PR Description
run: |
DIFF=$(git diff origin/main...HEAD | head -1000)
DESC=$(curl -s https://openrouter.ai/api/v1/chat/completions \
-H "Authorization: Bearer ${{ secrets.OPENROUTER_KEY }}" \
-H "Content-Type: application/json" \
-d "{
\"model\": \"openai/gpt-5.4-mini\",
\"messages\": [{
\"role\": \"user\",
\"content\": \"Write a concise PR description for this diff. Include: what changed, why, and any breaking changes.\n\n$DIFF\"
}]
}" | jq -r '.choices[0].message.content')
gh pr edit ${{ github.event.pull_request.number }} --body "$DESC"
AI deployment risk assessment
Before deploying, let AI assess the risk:
- name: Deployment Risk Check
run: |
CHANGES=$(git log --oneline origin/main...HEAD)
FILES=$(git diff --name-only origin/main...HEAD)
RISK=$(curl -s https://openrouter.ai/api/v1/chat/completions \
-H "Authorization: Bearer ${{ secrets.OPENROUTER_KEY }}" \
-H "Content-Type: application/json" \
-d "{
\"model\": \"openai/gpt-5.4-mini\",
\"messages\": [{
\"role\": \"user\",
\"content\": \"Assess deployment risk (LOW/MEDIUM/HIGH) for these changes:\n\nCommits: $CHANGES\n\nFiles changed: $FILES\n\nRisk factors: database migrations, auth changes, API breaking changes, config changes. Respond with RISK_LEVEL: LOW/MEDIUM/HIGH and a one-line explanation.\"
}]
}" | jq -r '.choices[0].message.content')
echo "$RISK"
if echo "$RISK" | grep -q "HIGH"; then
echo "::warning::High-risk deployment detected. Manual approval recommended."
fi
AI changelog generation
- name: Generate Changelog
if: github.ref == 'refs/heads/main'
run: |
COMMITS=$(git log --oneline $(git describe --tags --abbrev=0)..HEAD)
CHANGELOG=$(curl -s https://openrouter.ai/api/v1/chat/completions \
-H "Authorization: Bearer ${{ secrets.OPENROUTER_KEY }}" \
-H "Content-Type: application/json" \
-d "{
\"model\": \"openai/gpt-5.4-mini\",
\"messages\": [{
\"role\": \"user\",
\"content\": \"Generate a user-facing changelog from these commits. Group by: Features, Fixes, Improvements. Skip internal/CI changes.\n\n$COMMITS\"
}]
}" | jq -r '.choices[0].message.content')
echo "$CHANGELOG" >> CHANGELOG.md
Using local models in CI (self-hosted runners)
If you use self-hosted GitHub Actions runners, you can use Ollama for free AI in CI:
jobs:
review:
runs-on: self-hosted # Your runner with Ollama installed
steps:
- name: AI Review (local, free)
run: |
git diff origin/main...HEAD | ollama run qwen3:8b "Review this diff for bugs:"
Zero API cost, zero data leaving your network. See our self-hosted n8n guide for the infrastructure setup.
Cost per pipeline run
| Task | Model | Cost per run |
|---|---|---|
| Code review | GPT-5.4 Mini | ~$0.02 |
| PR description | GPT-5.4 Mini | ~$0.01 |
| Risk assessment | GPT-5.4 Mini | ~$0.005 |
| Changelog | GPT-5.4 Mini | ~$0.01 |
| All four | ~$0.05 | |
| All four (local Ollama) | qwen3:8b | $0 |
At $0.05 per PR, a team doing 20 PRs/day spends $1/day on AI-powered CI. Thatβs cheaper than one missed bug in production.
Related: AI App Deployment Checklist Β· Deploy AI Agents to Production Β· Claude Code Routines Β· Self-Host n8n with Local AI Β· LLM Regression Testing Β· OpenRouter Complete Guide