-
Notifications
You must be signed in to change notification settings - Fork 1
248 lines (206 loc) · 8.25 KB
/
Copy pathci-autofix.yml
File metadata and controls
248 lines (206 loc) · 8.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
name: "CI Autofix - Self-Improvement Loop"
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
workflow_dispatch:
env:
PYTHON_VERSION: "3.12"
AUTOFIX_MAX_TRIES: "2"
jobs:
autofix-pipeline:
name: "Autofix Pipeline"
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-test.txt
pip install pyright coverage pytest-html
- name: Run initial linting
run: |
echo "🔍 Running initial linting checks..."
ruff check . --force-exclude --output-format=json > ruff-report.json || true
pyright --stats --outputjson > pyright-report.json || true
- name: Run initial tests
run: |
echo "🧪 Running initial test suite..."
python -m pytest -q --maxfail=1 --tb=short --html=pytest-report.html --self-contained-html || true
- name: Run coverage analysis
run: |
echo "📊 Running coverage analysis..."
python -m coverage run -m pytest -q
python -m coverage report -m --skip-covered > coverage-report.txt
python -m coverage xml -o coverage.xml
- name: Check if autofix needed
id: check_autofix
run: |
echo "🔍 Checking if autofix is needed..."
if [ -f pytest-report.html ] && grep -q "failed" pytest-report.html; then
echo "needs_autofix=true" >> $GITHUB_OUTPUT
echo "❌ Tests failed - autofix needed"
else
echo "needs_autofix=false" >> $GITHUB_OUTPUT
echo "✅ All tests passed - no autofix needed"
fi
- name: Run Self-Improvement Loop
if: steps.check_autofix.outputs.needs_autofix == 'true'
run: |
echo "🤖 Running Self-Improvement Loop..."
python -m agent_dev.auto_fix --max-tries ${{ env.AUTOFIX_MAX_TRIES }} --db-path autofix.db
- name: Run tests after autofix
if: steps.check_autofix.outputs.needs_autofix == 'true'
run: |
echo "🧪 Running tests after autofix..."
python -m pytest -q --maxfail=1 --tb=short --html=pytest-report-after.html --self-contained-html || true
- name: Run coverage after autofix
if: steps.check_autofix.outputs.needs_autofix == 'true'
run: |
echo "📊 Running coverage after autofix..."
python -m coverage run -m pytest -q
python -m coverage report -m --skip-covered > coverage-report-after.txt
python -m coverage xml -o coverage-after.xml
- name: Check autofix success
id: autofix_success
if: steps.check_autofix.outputs.needs_autofix == 'true'
run: |
echo "🔍 Checking autofix success..."
if [ -f pytest-report-after.html ] && ! grep -q "failed" pytest-report-after.html; then
echo "autofix_success=true" >> $GITHUB_OUTPUT
echo "✅ Autofix successful - all tests now pass"
else
echo "autofix_success=false" >> $GITHUB_OUTPUT
echo "❌ Autofix failed - tests still failing"
fi
- name: Create autofix branch and commit
if: steps.autofix_success.outputs.autofix_success == 'true'
run: |
echo "🌿 Creating autofix branch and committing changes..."
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
# Create autofix branch
BRANCH_NAME="autofix/$(date +%Y%m%d-%H%M%S)-${{ github.run_id }}"
git checkout -b "$BRANCH_NAME"
# Add all changes
git add .
# Commit changes
git commit -m "fix: Apply self-improvement loop fixes
- Applied automated fixes using AgentDev Self-Improvement Loop
- Fixed ${{ github.run_id }} issues
- All tests now passing
- Coverage maintained
Generated by CI Autofix Pipeline" || echo "No changes to commit"
# Push branch
git push origin "$BRANCH_NAME"
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
- name: Create Pull Request
if: steps.autofix_success.outputs.autofix_success == 'true'
uses: actions/github-script@v6
with:
script: |
const branchName = process.env.BRANCH_NAME;
const { data: pr } = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `🤖 Autofix: Self-Improvement Loop Applied`,
head: branchName,
base: context.payload.pull_request?.base?.ref || 'main',
body: `## 🤖 Automated Fixes Applied
This PR contains automated fixes applied by the AgentDev Self-Improvement Loop.
### 📊 Results:
- **Pipeline Run**: ${{ github.run_id }}
- **Max Tries**: ${{ env.AUTOFIX_MAX_TRIES }}
- **Status**: ✅ All tests now passing
- **Coverage**: Maintained or improved
### 🔧 Changes:
- Applied automated error detection and fixing
- Used rule-based pattern matching
- Maintained code quality standards
- No \`# type: ignore\` or comment-out used
### 📋 Artifacts:
- Coverage reports: \`coverage.xml\`, \`coverage-report.txt\`
- Test reports: \`pytest-report.html\`
- Linting reports: \`ruff-report.json\`, \`pyright-report.json\`
### ✅ Quality Assurance:
- All tests passing
- Coverage targets met
- No linting errors
- Type safety maintained
**Ready for review and merge.**`,
draft: false
});
console.log(`Created PR #${pr.number}: ${pr.html_url}`);
- name: Upload artifacts
uses: actions/upload-artifact@v3
if: always()
with:
name: autofix-artifacts-${{ github.run_id }}
path: |
coverage.xml
coverage-report.txt
coverage-after.xml
coverage-report-after.txt
pytest-report.html
pytest-report-after.html
ruff-report.json
pyright-report.json
autofix.db
retention-days: 30
- name: Comment on original PR
if: github.event_name == 'pull_request' && steps.autofix_success.outputs.autofix_success == 'true'
uses: actions/github-script@v6
with:
script: |
const { data: pr } = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `🤖 Autofix: Self-Improvement Loop Applied`,
head: process.env.BRANCH_NAME,
base: context.payload.pull_request.base.ref,
body: `## 🤖 Automated Fixes Applied
This PR contains automated fixes applied by the AgentDev Self-Improvement Loop.
### 📊 Results:
- **Pipeline Run**: ${{ github.run_id }}
- **Max Tries**: ${{ env.AUTOFIX_MAX_TRIES }}
- **Status**: ✅ All tests now passing
- **Coverage**: Maintained or improved
### 🔧 Changes:
- Applied automated error detection and fixing
- Used rule-based pattern matching
- Maintained code quality standards
- No \`# type: ignore\` or comment-out used
**Ready for review and merge.**`
});
// Comment on original PR
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `🤖 **Autofix Applied Successfully!**
I've automatically applied fixes using the AgentDev Self-Improvement Loop:
- **Pipeline Run**: ${{ github.run_id }}
- **Status**: ✅ All tests now passing
- **Coverage**: Maintained or improved
- **Quality**: No \`# type: ignore\` or comment-out used
**Created PR**: #${pr.number} - ${pr.html_url}
The fixes are ready for review and merge.`
});
- name: Report autofix failure
if: steps.check_autofix.outputs.needs_autofix == 'true' && steps.autofix_success.outputs.autofix_success == 'false'
run: |
echo "❌ Autofix failed - manual intervention required"
echo "Please review the test failures and apply manual fixes"
echo "Artifacts have been uploaded for analysis"