php-devops/.github/workflows/free-tier-ai.yml
Snider 9c10ff9b1c feat: add comprehensive free tier integrations
AI Services (contributor's fork pays):
- Groq: 14,400 req/day (Llama 3.3 70B)
- Mistral: 1M tokens/month
- Cohere: 1000 req/month (classification)
- Cloudflare AI: 10K neurons/day
- Gemini: 1500 req/day (existing)

Security Scanners (100% free, no keys):
- Semgrep: SAST
- Trivy: Container/IaC vulns
- Gitleaks: Secret detection
- OSV-Scanner: Google vuln DB
- Checkov: IaC security

All results:
- Upload to GitHub Security tab (SARIF)
- Create artifacts for core CLI to consume
- Feed into Agentic task queue

Doc: free-tier-services.md lists 50+ free services

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 22:36:27 +00:00

145 lines
5 KiB
YAML

name: Free Tier AI Analysis
on:
pull_request:
types: [opened, synchronize]
issues:
types: [opened, labeled]
workflow_dispatch:
permissions:
contents: read
pull-requests: write
issues: write
jobs:
# Groq - 14,400 requests/day FREE (Llama 3, Mixtral)
groq-analysis:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get diff
id: diff
run: |
git diff origin/${{ github.base_ref }}...HEAD > /tmp/diff.txt
head -c 30000 /tmp/diff.txt > /tmp/diff_truncated.txt
- name: Groq Analysis
if: env.GROQ_API_KEY != ''
env:
GROQ_API_KEY: ${{ secrets.GROQ_API_KEY }}
run: |
# Groq is FAST and FREE (14,400 req/day)
DIFF=$(cat /tmp/diff_truncated.txt | jq -Rs .)
curl -s https://api.groq.com/openai/v1/chat/completions \
-H "Authorization: Bearer $GROQ_API_KEY" \
-H "Content-Type: application/json" \
-d "{
\"model\": \"llama-3.3-70b-versatile\",
\"messages\": [{
\"role\": \"user\",
\"content\": \"Review this diff for security issues, bugs, and code smells. Be very concise. Output as: SECURITY: x issues, BUGS: x issues, SMELLS: x issues. Then list critical items only.\n\nDiff:\n${DIFF}\"
}],
\"temperature\": 0.1,
\"max_tokens\": 500
}" | jq -r '.choices[0].message.content' > /tmp/groq_review.txt
cat /tmp/groq_review.txt
# Mistral - Free tier available
mistral-analysis:
if: github.event_name == 'pull_request' && vars.MISTRAL_API_KEY != ''
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v4
- name: Mistral Code Review
env:
MISTRAL_API_KEY: ${{ secrets.MISTRAL_API_KEY }}
run: |
echo "Mistral analysis would run here"
# Similar pattern to Groq
# Cohere - 1000 req/month free (good for classification)
cohere-classify:
if: github.event_name == 'issues'
runs-on: ubuntu-latest
continue-on-error: true
steps:
- name: Classify Issue
if: env.COHERE_API_KEY != ''
env:
COHERE_API_KEY: ${{ secrets.COHERE_API_KEY }}
run: |
# Use Cohere to classify issue type/priority
TITLE="${{ github.event.issue.title }}"
BODY="${{ github.event.issue.body }}"
curl -s https://api.cohere.ai/v1/classify \
-H "Authorization: Bearer $COHERE_API_KEY" \
-H "Content-Type: application/json" \
-d "{
\"inputs\": [\"$TITLE\"],
\"examples\": [
{\"text\": \"App crashes on login\", \"label\": \"bug\"},
{\"text\": \"Add dark mode\", \"label\": \"feature\"},
{\"text\": \"SQL injection in auth\", \"label\": \"security\"},
{\"text\": \"Slow page load\", \"label\": \"performance\"}
]
}" | jq '.classifications[0].prediction'
# Cloudflare Workers AI - 10,000 neurons/day FREE
cloudflare-ai:
if: github.event_name == 'pull_request' && vars.CF_ACCOUNT_ID != ''
runs-on: ubuntu-latest
continue-on-error: true
steps:
- name: Cloudflare AI Analysis
env:
CF_API_TOKEN: ${{ secrets.CF_API_TOKEN }}
CF_ACCOUNT_ID: ${{ vars.CF_ACCOUNT_ID }}
run: |
# Cloudflare Workers AI - runs at the edge
echo "Cloudflare AI analysis would run here"
# @cf/meta/llama-3-8b-instruct is free
# Aggregate results and create summary
aggregate:
needs: [groq-analysis]
if: always() && github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Create Summary
uses: actions/github-script@v7
with:
script: |
const summary = `## 🤖 Free Tier AI Analysis
Multiple AI services analyzed this PR:
| Service | Status | Free Tier |
|---------|--------|-----------|
| Groq (Llama 3) | ${{ needs.groq-analysis.result }} | 14,400 req/day |
| Mistral | skipped | 1M tokens/month |
| Cohere | skipped | 1000 req/month |
| Cloudflare AI | skipped | 10K neurons/day |
---
_Add API keys to your fork secrets to enable more services._
_All analysis runs on contributor's free tier allowance._
`;
// Only comment if at least one analysis ran
if ('${{ needs.groq-analysis.result }}' !== 'skipped') {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: summary
});
}