Automate GitHub workflows with AI assistance. Includes PR reviews, issue triage, CI/CD integration, and Git operations. Use when automating GitHub workflows, setting up PR review automation, creating GitHub Actions, or triaging issues.
Automate GitHub workflows with AI assistance. Includes PR reviews, issue triage, CI/CD integration, and Git operations. Use when automating GitHub workflows, setting up PR review automation, creating GitHub Actions, or triaging issues.
🔧 GitHub Workflow Automation
Patterns for automating GitHub workflows with AI assistance, inspired by Gemini CLI and modern DevOps practices.
# AI Review Structure## 📋 Summary
Brief description of what this PR does.
## ✅ What looks good- Well-structured code
- Good test coverage
- Clear naming conventions
## ⚠️ Potential Issues1.**Line 42**: Possible null pointer exception
```javascript
// Current
user.profile.name;
// Suggested
user?.profile?.name ?? "Unknown";
```
Line 78: Consider error handling
// Add try-catch or .catch()
💡 Suggestions
Consider extracting the validation logic into a separate function
Add JSDoc comments for public methods
🔒 Security Notes
No sensitive data exposure detected
API key handling looks correct
### 1.3 Focused Reviews
```yaml
# Review only specific file types
- name: Filter code files
run: |
files=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | \
grep -E '\.(ts|tsx|js|jsx|py|go)$' || true)
echo "code_files=$files" >> $GITHUB_OUTPUT
# Review with context
- name: AI Review with context
run: |
# Include relevant context files
context=""
for file in ${{ steps.changed.outputs.files }}; do
if [[ -f "$file" ]]; then
context+="=== $file ===\n$(cat $file)\n\n"
fi
done
# Send to AI with full file context
# .github/workflows/stale.ymlname:ManageStaleIssueson:schedule:-cron:"0 0 * * *"# Dailyjobs:stale:runs-on:ubuntu-lateststeps:-uses:actions/stale@v9with:stale-issue-message:|
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed in 14 days if no further activity occurs.
If this issue is still relevant:-Addacommentwithanupdate-Removethe`stale`labelThankyouforyourcontributions!🙏stale-pr-message:|
This PR has been automatically marked as stale. Please update it or it
will be closed in 14 days.
days-before-stale:60days-before-close:14stale-issue-label:"stale"stale-pr-label:"stale"exempt-issue-labels:"pinned,security,in-progress"exempt-pr-labels:"pinned,security"
3. CI/CD Integration
3.1 Smart Test Selection
# .github/workflows/smart-tests.ymlname:SmartTestSelectionon:pull_request:jobs:analyze:runs-on:ubuntu-latestoutputs:test_suites:${{steps.analyze.outputs.suites}}steps:-uses:actions/checkout@v4with:fetch-depth:0-name:Analyzechangesid:analyzerun:|
# Get changed files
changed=$(git diff --name-only origin/${{ github.base_ref }}...HEAD)
# Determine which test suites to runsuites="[]"ifecho"$changed"|grep-q"^src/api/";thensuites=$(echo$suites|jq'. + ["api"]')fiifecho"$changed"|grep-q"^src/frontend/";thensuites=$(echo$suites|jq'. + ["frontend"]')fiifecho"$changed"|grep-q"^src/database/";thensuites=$(echo$suites|jq'. + ["database", "api"]')fi# If nothing specific, run allif [ "$suites"="[]" ];thensuites='["all"]'fiecho"suites=$suites">>$GITHUB_OUTPUTtest:needs:analyzeruns-on:ubuntu-lateststrategy:matrix:suite:${{fromJson(needs.analyze.outputs.test_suites)}}steps:-uses:actions/checkout@v4-name:Runtestsrun:|
if [ "${{ matrix.suite }}" = "all" ]; then
npm test
else
npm test -- --suite ${{ matrix.suite }}
fi
3.2 Deployment with AI Validation
# .github/workflows/deploy.ymlname:DeploywithAIValidationon:push:branches: [main]
jobs:validate:runs-on:ubuntu-lateststeps:-uses:actions/checkout@v4-name:Getdeploymentchangesid:changesrun:|
# Get commits since last deployment
last_deploy=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -n "$last_deploy" ]; then
changes=$(git log --oneline $last_deploy..HEAD)
else
changes=$(git log --oneline -10)
fi
echo "changes<<EOF" >> $GITHUB_OUTPUT
echo "$changes" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
-name:AIRiskAssessmentid:assessuses:actions/github-script@v7with:script:|
// Analyze changes for deployment risk
const prompt = `
Analyze these changes for deployment risk:
${process.env.CHANGES}Return JSON:
{
"riskLevel":"low"|"medium"|"high",
"concerns": ["concern1", "concern2"],
"recommendations": ["rec1", "rec2"],
"requiresManualApproval":boolean
}
`;//CallAIandparseresponseconstanalysis=awaitcallAI(prompt);if(analysis.riskLevel==='high') {
core.setFailed('High-riskdeploymentdetected.Manualreviewrequired.');
}
returnanalysis;env:CHANGES:${{steps.changes.outputs.changes}}deploy:needs:validateruns-on:ubuntu-latestenvironment:productionsteps:-name:Deployrun:|
echo "Deploying to production..."
# Deployment commands here
3.3 Rollback Automation
# .github/workflows/rollback.ymlname:AutomatedRollbackon:workflow_dispatch:inputs:reason:description:"Reason for rollback"required:truejobs:rollback:runs-on:ubuntu-lateststeps:-uses:actions/checkout@v4with:fetch-depth:0-name:Findlaststableversionid:stablerun:|
# Find last successful deployment
stable=$(git tag -l 'v*' --sort=-version:refname | head -1)
echo "version=$stable" >> $GITHUB_OUTPUT
-name:Rollbackrun:|
git checkout ${{ steps.stable.outputs.version }}
# Deploy stable version
npm run deploy
-name:Notifyteamuses:slackapi/slack-github-action@v1with:payload:|
{
"text": "🔄 Production rolled back to ${{ steps.stable.outputs.version }}",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Rollback executed*\n• Version: `${{ steps.stable.outputs.version }}`\n• Reason: ${{ inputs.reason }}\n• Triggered by: ${{ github.actor }}"
}
}
]
}