name: AI Loop
on:
workflow_dispatch:
inputs:
branch:
description: "Base branch to run against"
required: true
default: "main"
prompt:
description: "Prompt (optional)"
required: false
type: string
attempts:
description: "Max attempts"
default: "40"
type: number
pr-on-fail:
description: "Create a PR on failure"
default: true
type: boolean
provider:
description: "AI provider"
default: "openai"
required: true
type: choice
options:
- openai
- deepseek
- gemini
model:
description: "AI model"
default: "o3-mini"
required: true
type: choice
options:
- o3-mini - o1 - deepseek-reasoner - deepseek-coder - gemini-2.0-flash-thinking-exp
permissions:
contents: write
pull-requests: write
issues: write
jobs:
loop:
name: AI Loop
runs-on: ubuntu-latest
timeout-minutes: 360
env:
MAX_ATTEMPTS: ${{ github.event.inputs.attempts }}
BASE_BRANCH: ${{ github.event.inputs.branch }}
NEW_BRANCH: ${{ github.event.inputs.branch }}-ai-loop-${{ github.run_id }}
CARGO_TERM_COLOR: always
RUSTFLAGS: "-Cinstrument-coverage"
LLVM_PROFILE_FILE: "coverage/bodo-%p-%m.profraw"
AI_PROVIDER: ${{ github.event.inputs.provider }}
AI_MODEL: ${{ github.event.inputs.model }}
AI_PROMPT: ${{ github.event.inputs.prompt }}
steps:
- name: Print inputs
run: |
echo "MAX_ATTEMPTS=${{ env.MAX_ATTEMPTS }}"
echo "BASE_BRANCH=${{ env.BASE_BRANCH }}"
echo "NEW_BRANCH=${{ env.NEW_BRANCH }}"
echo "AI_PROVIDER=${{ env.AI_PROVIDER }}"
echo "AI_MODEL=${{ env.AI_MODEL }}"
echo "AI_PROMPT=${{ env.AI_PROMPT }}"
- name: Checkout base branch
uses: actions/checkout@v4
with:
ref: ${{ env.BASE_BRANCH }}
fetch-depth: 0
- name: Cache Rust dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Setup Deno
uses: denoland/setup-deno@v2
with:
deno-version: v2.x
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Install llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: Install cargo-nextest
uses: taiki-e/install-action@nextest
- name: Install Yek
run: |
curl -fsSL https://bodo.run/yek.sh | bash
- name: Configure git with Github Bot
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Create and setup new branch
run: |
# Create new branch from base branch
git checkout -b ${{ env.NEW_BRANCH }} ${{ env.BASE_BRANCH }}
# Push the new branch to establish tracking
git push -u origin ${{ env.NEW_BRANCH }}
- name: Run AI Loop
id: ai_loop
timeout-minutes: 360
continue-on-error: true
env:
DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
MAX_ATTEMPTS: ${{ env.MAX_ATTEMPTS }}
AI_PROVIDER: ${{ env.AI_PROVIDER }}
AI_MODEL: ${{ env.AI_MODEL }}
AI_PROMPT: ${{ env.AI_PROMPT }}
BASE_BRANCH: ${{ env.BASE_BRANCH }}
NEW_BRANCH: ${{ env.NEW_BRANCH }}
run: |
for i in $(seq 1 $MAX_ATTEMPTS); do
echo "===== Attempt $i ====="
deno run --allow-all scripts/ailoop.ts 2>&1 || true
if [ -n "$(git status --porcelain)" ]; then
git add -A
git commit -m "AI Loop attempt $i"
git push -u origin $NEW_BRANCH
fi
echo "last_attempt=${i}" >> "$GITHUB_OUTPUT"
done
echo "success=${SUCCESS}" >> "$GITHUB_OUTPUT"
- name: Create PR
if: always() && ${{ github.event.inputs.pr-on-fail }}
env:
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
MAX_ATTEMPTS: ${{ env.MAX_ATTEMPTS }}
AI_PROVIDER: ${{ env.AI_PROVIDER }}
AI_MODEL: ${{ env.AI_MODEL }}
run: |
gh pr create \
--title "AI tests for \`${{ env.BASE_BRANCH }}\` branch" \
--body "- Successful: ${{ steps.ai_loop.outputs.success != 0 }}
- Attempts: \`${{ steps.ai_loop.outputs.last_attempt }} / ${{ env.MAX_ATTEMPTS }}\`
- AI Provider: \`${{ env.AI_PROVIDER }}\`
- AI Model: \`${{ env.AI_MODEL }}\`
- [View run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})" \
--base "${{ env.BASE_BRANCH }}" \
--head "${{ env.NEW_BRANCH }}"