GitHub Actions
Prerequisites: AddFACTORY_API_KEY
to repository secrets (Settings → Secrets → Actions)
Example 1: Automated PR Review and Fix
Automatically reviews PRs, fixes issues, and posts detailed feedback.Copy
Ask AI
name: PR Assistant
on:
pull_request:
types: [opened, synchronize]
jobs:
review-and-fix:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup droid CLI
run: |
curl -fsSL https://app.factory.ai/cli | sh
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Analyze and fix code
env:
FACTORY_API_KEY: ${{ secrets.FACTORY_API_KEY }}
run: |
# Get the diff
git diff origin/${{ github.base_ref }}...HEAD > pr_changes.diff
# Review and fix issues (pipe diff to stdin)
cat pr_changes.diff | droid exec --auto low "
Review this PR diff and:
1. Fix any obvious bugs, typos, or linting errors
2. Add missing error handling
3. Improve code comments where unclear
4. DO NOT commit or push changes
"
# Generate review report (needs --auto to write files)
droid exec --auto low "Analyze the changes again and write a detailed review to review.md with:
- Summary of automated fixes made
- Remaining issues that need human attention
- Security or performance concerns
- Test coverage recommendations"
- name: Commit fixes if any
run: |
if [ -n "$(git status --porcelain)" ]; then
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "fix: automated improvements for PR #${{ github.event.pull_request.number }}
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>"
git push
fi
- name: Post review comment
if: always()
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
let review = '## 🤖 Automated Review\n\n';
if (fs.existsSync('review.md')) {
review += fs.readFileSync('review.md', 'utf8');
} else {
review += 'Review completed successfully.';
}
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: review
});
Example 2: Daily Documentation and Test Updates
Keeps documentation and tests in sync with code changes automatically.Copy
Ask AI
name: Daily Maintenance
on:
schedule:
- cron: '0 3 * * *' # 3 AM UTC daily
workflow_dispatch: # Allow manual trigger
jobs:
update-docs-and-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup droid CLI
run: |
curl -fsSL https://app.factory.ai/cli | sh
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Update documentation
env:
FACTORY_API_KEY: ${{ secrets.FACTORY_API_KEY }}
run: |
droid exec --auto low "
Review all code files modified in the last 7 days and:
1. Update any outdated JSDoc/docstring comments
2. Update README.md if new features were added
3. Add missing documentation for public APIs
4. Update examples to match current implementation
Write a summary of changes to docs-updates.md
"
- name: Generate missing tests
env:
FACTORY_API_KEY: ${{ secrets.FACTORY_API_KEY }}
run: |
droid exec --auto low "
Find functions and components without test coverage and:
1. Generate unit tests for utility functions
2. Create basic test cases for React components
3. Add edge case tests for error handling
4. Follow existing test patterns in the codebase
Write a summary to test-updates.md
"
- name: Create PR if changes exist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Note: gh CLI is pre-installed on GitHub-hosted runners
if [ -n "$(git status --porcelain)" ]; then
BRANCH="auto-updates-$(date +%Y%m%d)"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout -b $BRANCH
git add -A
git commit -m "chore: automated documentation and test updates
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>"
git push origin $BRANCH
# Combine summaries for PR body
PR_BODY="## Automated Updates\n\n"
[ -f docs-updates.md ] && PR_BODY="${PR_BODY}### Documentation\n$(cat docs-updates.md)\n\n"
[ -f test-updates.md ] && PR_BODY="${PR_BODY}### Tests\n$(cat test-updates.md)\n\n"
gh pr create \
--title "🤖 Daily automated updates" \
--body "$PR_BODY" \
--label "automated,documentation,tests"
fi
Example 3: Security and Dependency Scanner
Scans for vulnerabilities and outdated dependencies on a schedule.Copy
Ask AI
name: Security Scanner
on:
schedule:
- cron: '0 9 * * 1' # Mondays at 9 AM UTC
workflow_dispatch:
jobs:
security-scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup droid CLI
run: |
curl -fsSL https://app.factory.ai/cli | sh
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Security audit
env:
FACTORY_API_KEY: ${{ secrets.FACTORY_API_KEY }}
run: |
droid exec --auto medium "
Perform a comprehensive security audit:
1. Check package.json for known vulnerabilities
2. Update vulnerable dependencies to safe versions
3. Scan code for hardcoded secrets or API keys
4. Review authentication and authorization patterns
5. Check for SQL injection or XSS vulnerabilities
6. Generate security-report.md with all findings and fixes
"
- name: Create issue if vulnerabilities found
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Note: gh CLI is pre-installed on GitHub-hosted runners
if [ -f security-report.md ] && grep -q "vulnerability\|security\|risk" security-report.md; then
gh issue create \
--title "🔒 Security audit findings - $(date +%Y-%m-%d)" \
--body-file security-report.md \
--label "security,high-priority" \
--assignee "${{ github.repository_owner }}"
fi
- name: Create PR for fixes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Note: gh CLI is pre-installed on GitHub-hosted runners
if [ -n "$(git status --porcelain)" ]; then
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout -b security-fixes-$(date +%Y%m%d)
git add -A
git commit -m "fix: security updates and dependency patches
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>"
git push origin HEAD
gh pr create \
--title "🔒 Security fixes" \
--body-file security-report.md \
--label "security,dependencies" \
--assignee "${{ github.repository_owner }}"
fi