Skip to content

Commit 83ea968

Browse files
authored
ci: introduce daily AI factory (validation pending) (#4)
* ci: add weekly maintenance audit * ci: run maintenance audit daily * ci: introduce gated AI issue agent and daily PR triage * ci: remove redundant audit covered by Renovate * fix: account for untracked files and resolve PR base branch
1 parent 2a4b7d2 commit 83ea968

1 file changed

Lines changed: 88 additions & 0 deletions

File tree

‎.github/workflows/ai-factory.yml‎

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: AI software factory
2+
on:
3+
schedule:
4+
- cron: '23 9 * * *'
5+
workflow_dispatch:
6+
inputs:
7+
issue_number:
8+
description: 'Issue number to implement (optional)'
9+
required: false
10+
type: string
11+
issues:
12+
types: [labeled]
13+
permissions:
14+
contents: write
15+
issues: write
16+
pull-requests: write
17+
concurrency:
18+
group: ai-factory-${{ github.event.issue.number || github.event.inputs.issue_number || 'daily' }}
19+
cancel-in-progress: false
20+
jobs:
21+
daily-triage:
22+
if: github.event_name == 'schedule'
23+
runs-on: ubuntu-latest
24+
timeout-minutes: 10
25+
env:
26+
GH_TOKEN: ${{ github.token }}
27+
steps:
28+
- name: Identify failing PRs
29+
shell: bash
30+
run: |
31+
gh pr list --repo "$GITHUB_REPOSITORY" --state open --json number,title,statusCheckRollup,headRefName --limit 100 > prs.json
32+
jq -c '.[] | select(any(.statusCheckRollup[]?; .conclusion == "FAILURE" or .conclusion == "TIMED_OUT"))' prs.json | while IFS= read -r pr; do
33+
number=$(jq -r '.number' <<< "$pr")
34+
title=$(jq -r '.title' <<< "$pr")
35+
existing=$(gh issue list --repo "$GITHUB_REPOSITORY" --state open --search "AI repair PR #$number in:title" --json number | jq length)
36+
if [ "$existing" -eq 0 ]; then
37+
gh issue create --repo "$GITHUB_REPOSITORY" --title "AI repair PR #$number" --body "PR #$number ($title) has failing checks. Investigate logs, repair on the PR branch, and rerun tests. Human review required before merging."
38+
fi
39+
done
40+
implement:
41+
if: (github.event_name == 'issues' && github.event.label.name == 'ai:implement') || (github.event_name == 'workflow_dispatch' && inputs.issue_number != '')
42+
runs-on: ubuntu-latest
43+
timeout-minutes: 30
44+
env:
45+
GH_TOKEN: ${{ github.token }}
46+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
47+
steps:
48+
- name: Require model credentials
49+
run: |
50+
if [ -z "$OPENAI_API_KEY" ]; then
51+
echo 'Configure repository or organization secret OPENAI_API_KEY.' >> "$GITHUB_STEP_SUMMARY"
52+
exit 1
53+
fi
54+
- uses: actions/checkout@v4
55+
with:
56+
persist-credentials: true
57+
- uses: actions/setup-python@v5
58+
with:
59+
python-version: '3.12'
60+
- name: Install coding agent
61+
run: pip install 'aider-chat==0.86.1'
62+
- name: Implement issue on isolated branch
63+
shell: bash
64+
env:
65+
ISSUE_NUMBER: ${{ github.event.issue.number || inputs.issue_number }}
66+
run: |
67+
set -euo pipefail
68+
issue=$(gh issue view "$ISSUE_NUMBER" --repo "$GITHUB_REPOSITORY" --json title,body,state)
69+
[ "$(jq -r '.state' <<< "$issue")" = OPEN ] || exit 1
70+
branch="ai/issue-${ISSUE_NUMBER}-${GITHUB_RUN_ID}"
71+
git config user.name 'github-actions[bot]'
72+
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
73+
git checkout -b "$branch"
74+
jq -r '"Issue: " + .title + "\n\n" + (.body // "")' <<< "$issue" > /tmp/ai-task.txt
75+
echo 'Implement the issue described below. Keep changes minimal, preserve existing APIs, add or update tests, and do not modify workflows, secrets, or access policies.' >> /tmp/ai-task.txt
76+
aider --yes --no-auto-commits --model gpt-4.1 --message-file /tmp/ai-task.txt
77+
if [ -z "$(git status --porcelain)" ]; then echo 'No changes generated'; exit 0; fi
78+
git add -A
79+
if git diff --cached --name-only | grep -E '(^|/)(\.github/workflows/|\.env|AGENTS\.md|renovate\.json)' ; then
80+
echo 'Sensitive configuration changes require a separate manual process'; exit 1
81+
fi
82+
if [ -f package.json ]; then
83+
if [ -f package-lock.json ]; then npm ci --ignore-scripts; else npm install --ignore-scripts; fi
84+
npm test --if-present || { echo 'Tests failed; no PR pushed'; exit 1; }
85+
fi
86+
git commit -m "ai: implement issue #$ISSUE_NUMBER"
87+
git push origin "$branch"
88+
gh pr create --repo "$GITHUB_REPOSITORY" --base "$(gh repo view "$GITHUB_REPOSITORY" --json defaultBranchRef --jq .defaultBranchRef.name)" --head "$branch" --draft --title "AI: $(jq -r '.title' <<< "$issue")" --body "Implements #$ISSUE_NUMBER. Generated by AI; requires CI and human review before merge."

0 commit comments

Comments
 (0)