-
Notifications
You must be signed in to change notification settings - Fork 0
163 lines (139 loc) · 5.08 KB
/
ci-auto-loop.yml
File metadata and controls
163 lines (139 loc) · 5.08 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
name: CI/CD with Auto Bug-Fix Loop
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
env:
PYTHON_VERSION: "3.11"
jobs:
ci-loop:
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history for better analysis
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Cache pip
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install strategy-pm[github] pytest pytest-cov
pip install llx # Install llx for AI analysis
- name: Install Ollama (for local LLM)
if: env.AUTO_FIX == 'true'
run: |
curl -fsSL https://ollama.ai/install.sh | sh
ollama serve &
sleep 5
ollama pull qwen2.5:3b
- name: Run CI Auto-Loop
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPO: ${{ github.repository }}
AUTO_FIX: ${{ vars.AUTO_FIX || 'false' }}
run: |
strategy-pm auto loop \
--strategy ./strategy.yaml \
--project . \
--backend github \
--max-iterations 5 \
--auto-fix ${{ env.AUTO_FIX }} \
--output ci-results.json
- name: Comment PR with results
if: github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
if (fs.existsSync('ci-results.json')) {
const results = JSON.parse(fs.readFileSync('ci-results.json', 'utf8'));
const comment = `
## 🤖 CI/CD Auto-Loop Results
**Status**: ${results.success ? '✅ Success' : '❌ Failed'}
**Iterations**: ${results.total_iterations}
**Tickets Created**: ${results.tickets_created.length}
${results.tickets_created.length > 0 ? `
### 📫 Created Tickets
${results.tickets_created.map(url => `- [Ticket](${url})`).join('\n')}
` : ''}
${!results.success ? `
### ❌ Issues
Final status: ${results.final_status}
` : ''}
---
*Generated by SprintStrat CI/CD*
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
}
- name: Update strategy if needed
if: failure() && env.UPDATE_STRATEGY == 'true'
run: |
# Generate updated strategy based on failures
llx chat --model balanced \
--prompt "Update strategy.yaml based on recent test failures and CI results" \
--output strategy-updated.yaml
# Create PR for strategy update
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git checkout -b strategy-update-${{ github.run_number }}
git add strategy-updated.yaml
git commit -m "ci: Update strategy based on CI results"
git push origin strategy-update-${{ github.run_number }}
gh pr create --title "Auto-update strategy" --body "Strategy updated based on CI results"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload artifacts
uses: actions/upload-artifact@v3
if: always()
with:
name: ci-results
path: |
ci-results.json
test-results.xml
coverage.json
htmlcov/
- name: Coverage badge
uses: tj-actions/coverage-badge-py@v2
if: github.ref == 'refs/heads/main'
with:
output: coverage.svg
- name: Deploy coverage reports
if: github.ref == 'refs/heads/main'
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./htmlcov
destination_dir: coverage
notify:
runs-on: ubuntu-latest
needs: ci-loop
if: always()
steps:
- name: Notify Slack
if: env.SLACK_WEBHOOK_URL != ''
run: |
curl -X POST -H 'Content-type: application/json' \
--data '{"text":"CI/CD ${{ needs.ci-loop.result }}: ${{ github.repository }} - ${{ github.sha }}"}' \
${{ env.SLACK_WEBHOOK_URL }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}