Repository navigation
333 lines (295 loc) · 12.3 KB
/
Copy pathauto-claude-build.yml
File metadata and controls
333 lines (295 loc) · 12.3 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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# Auto-Claude CI/CD Integration
#
# Example workflow demonstrating how to run Auto-Claude builds in CI/CD pipelines.
# This workflow runs autonomous AI-powered builds with JSON output, proper exit
# code handling, and artifact generation.
#
# Usage:
# 1. Copy this workflow to your repository
# 2. Configure environment variables (see env section below)
# 3. Adjust the spec number or task description for your use case
# 4. Customize triggered branches and paths as needed
name: Auto-Claude Build
on:
# This workflow is a template/example — trigger it manually in your own repo.
# The pull_request/push triggers are intentionally removed so this demo
# workflow does not run in CI without the required ANTHROPIC_API_KEY secret.
workflow_dispatch:
inputs:
spec_number:
description: 'Spec number to build (e.g., 001)'
required: false
default: '001'
task_description:
description: 'Task description (if no spec)'
required: false
default: ''
concurrency:
group: auto-claude-${{ github.ref }}
cancel-in-progress: true
env:
# Auto-Claude Configuration
AUTO_CLAUDE_CI: 'true' # Enable CI mode (non-interactive)
AUTO_CLAUDE_JSON_OUTPUT: 'true' # Enable JSON output
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
# Autonomy level (ADR-006). 'safe' enables evidence-gated direct-API provider
# promotion: a provider runs fully autonomous only after it passes the
# recorded AutonomyPolicy gate; unproven providers stay limited. Claude
# remains the trusted baseline. Override per run via repo variables if needed.
AUTO_CODE_AUTONOMY: ${{ vars.AUTO_CODE_AUTONOMY || 'safe' }}
# Optional: Configure Claude model
# CLAUDE_MODEL: 'claude-sonnet-4-5-20250929'
# Optional: Graphiti memory configuration
# GRAPHITI_ENABLED: 'true'
# GRAPHITI_LLM_PROVIDER: 'openai'
# OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
jobs:
# --------------------------------------------------------------------------
# Auto-Claude Build Job
# --------------------------------------------------------------------------
auto-claude-build:
name: Auto-Claude Build (${{ matrix.os }})
runs-on: ${{ matrix.os }}
permissions:
contents: read
actions: read
pull-requests: write
issues: write
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Checkout repository
uses: actions/checkout@v7
with:
fetch-depth: 0 # Full history for better analysis
- name: Setup Python backend
uses: ./.github/actions/setup-python-backend
with:
python-version: '3.12'
install-test-deps: 'true'
- name: Determine spec to build
id: spec-config
shell: bash
run: |
if [ -n "${{ github.event.inputs.task_description }}" ]; then
echo "Using task description instead of spec"
echo "mode=task" >> $GITHUB_OUTPUT
echo "target=${{ github.event.inputs.task_description }}" >> $GITHUB_OUTPUT
else
# Use input spec or default to 001
SPEC="${{ github.event.inputs.spec_number }}"
if [ -z "$SPEC" ]; then
SPEC="001"
fi
echo "mode=spec" >> $GITHUB_OUTPUT
echo "target=$SPEC" >> $GITHUB_OUTPUT
fi
- name: Run Auto-Claude build (Spec mode)
if: steps.spec-config.outputs.mode == 'spec'
working-directory: apps/backend
shell: bash
env:
PYTHONPATH: ${{ github.workspace }}/apps/backend
run: |
# Activate virtual environment
if [ "$RUNNER_OS" == "Windows" ]; then
source .venv/Scripts/activate
else
source .venv/bin/activate
fi
# Run Auto-Claude in CI mode
echo "Running Auto-Claude build for spec ${{ steps.spec-config.outputs.target }}"
python run.py \
--spec ${{ steps.spec-config.outputs.target }} \
--ci \
--json
- name: Run Auto-Claude build (Task mode)
if: steps.spec-config.outputs.mode == 'task'
working-directory: apps/backend
shell: bash
env:
PYTHONPATH: ${{ github.workspace }}/apps/backend
run: |
# Activate virtual environment
if [ "$RUNNER_OS" == "Windows" ]; then
source .venv/Scripts/activate
else
source .venv/bin/activate
fi
# Run Auto-Claude with task description
echo "Running Auto-Claude for task: ${{ steps.spec-config.outputs.target }}"
python run.py \
--task "${{ steps.spec-config.outputs.target }}" \
--ci \
--json
# Exit codes are handled automatically by GitHub Actions:
# 0 = success (build passed, QA approved)
# 1 = build failed (implementation errors)
# 2 = QA failed (validation rejected)
# 3 = system error (configuration, auth, etc.)
- name: Upload build artifacts
if: always()
uses: actions/upload-artifact@v7
with:
name: auto-claude-artifacts-${{ matrix.os }}
path: |
.auto-claude/specs/**/artifacts/
.auto-claude/specs/**/build-log.json
.auto-claude/specs/**/test-report.json
.auto-claude/specs/**/qa-report.md
retention-days: 30
if-no-files-found: ignore
- name: Upload spec documentation
if: always()
uses: actions/upload-artifact@v7
with:
name: auto-claude-specs-${{ matrix.os }}
path: |
.auto-claude/specs/**/spec.md
.auto-claude/specs/**/implementation_plan.json
.auto-claude/specs/**/qa_report.md
retention-days: 30
if-no-files-found: ignore
- name: Comment PR with results
if: always() && github.event_name == 'pull_request'
uses: actions/github-script@v9
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const specDir = '.auto-claude/specs';
// Find the most recent spec directory
let latestSpec = null;
let latestTime = 0;
if (fs.existsSync(specDir)) {
const specs = fs.readdirSync(specDir, { withFileTypes: true })
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name);
for (const spec of specs) {
const specPath = `${specDir}/${spec}`;
const stat = fs.statSync(specPath);
if (stat.mtimeMs > latestTime) {
latestTime = stat.mtimeMs;
latestSpec = spec;
}
}
}
if (!latestSpec) {
console.log('No spec directory found');
return;
}
// Read build log from artifacts subdirectory (where ArtifactManager writes it)
const buildLogPath = `${specDir}/${latestSpec}/artifacts/build-log.json`;
let buildLog = null;
if (fs.existsSync(buildLogPath)) {
try {
buildLog = JSON.parse(fs.readFileSync(buildLogPath, 'utf8'));
} catch (e) {
console.log('Failed to read build log:', e);
}
}
// Read QA report if it exists — support both naming conventions
const qaReportPath = `${specDir}/${latestSpec}/qa-report.md`;
const qaReportPathAlt = `${specDir}/${latestSpec}/qa_report.md`;
let qaReport = null;
if (fs.existsSync(qaReportPath)) {
qaReport = fs.readFileSync(qaReportPath, 'utf8');
} else if (fs.existsSync(qaReportPathAlt)) {
qaReport = fs.readFileSync(qaReportPathAlt, 'utf8');
}
// Build comment
let comment = '## 🤖 Auto-Claude Build Results\n\n';
if (buildLog) {
const status = buildLog.status || 'unknown';
const emoji = status === 'success' ? '✅' :
status === 'failed' ? '❌' :
status === 'qa_failed' ? '⚠️' : '❓';
comment += `**Status:** ${emoji} ${status.toUpperCase()}\n\n`;
comment += `**Exit Code:** ${buildLog.exit_code || 'N/A'}\n\n`;
comment += `**Duration:** ${buildLog.duration || 'N/A'}\n\n`;
if (buildLog.error_message) {
comment += `**Error:** \`${buildLog.error_message}\`\n\n`;
}
if (buildLog.changed_files && buildLog.changed_files.length > 0) {
comment += `**Files Changed:** ${buildLog.changed_files.length}\n`;
comment += '```diff\n' + buildLog.changed_files.slice(0, 10).join('\n') + '\n```\n\n';
}
} else {
comment += '**Status:** ❓ Build log not found\n\n';
}
// Add QA report section if available
if (qaReport) {
comment += '---\n\n### QA Report\n\n';
// Truncate if too long
const maxLength = 5000;
if (qaReport.length > maxLength) {
comment += qaReport.substring(0, maxLength) + '\n\n...(truncated)';
} else {
comment += qaReport;
}
}
comment += '\n\n---\n\n';
comment += '*View full artifacts in the workflow run*';
// Post comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('Auto-Claude Build Results')
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: comment
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: comment
});
}
# --------------------------------------------------------------------------
# Summary Job
# --------------------------------------------------------------------------
build-summary:
name: Build Summary
runs-on: ubuntu-latest
needs: [auto-claude-build]
if: always()
steps:
- name: Check build results
run: |
echo "## Auto-Claude Build Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Matrix Job Result: ${{ needs.auto-claude-build.result }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [[ "${{ needs.auto-claude-build.result }}" == "success" ]]; then
echo "✅ Build completed successfully" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- Exit code: 0 (success)" >> $GITHUB_STEP_SUMMARY
echo "- QA: Approved" >> $GITHUB_STEP_SUMMARY
elif [[ "${{ needs.auto-claude-build.result }}" == "failure" ]]; then
echo "❌ Build failed" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Possible causes:" >> $GITHUB_STEP_SUMMARY
echo "- Exit code: 1 (implementation failed)" >> $GITHUB_STEP_SUMMARY
echo "- Exit code: 2 (QA rejected)" >> $GITHUB_STEP_SUMMARY
echo "- Exit code: 3 (system error)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Check the artifacts for detailed logs and reports." >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Artifacts" >> $GITHUB_STEP_SUMMARY
echo "- Build logs (build-log.json)" >> $GITHUB_STEP_SUMMARY
echo "- Test reports (test-report.json)" >> $GITHUB_STEP_SUMMARY
echo "- QA reports (qa-report.md)" >> $GITHUB_STEP_SUMMARY
echo "- Spec documentation" >> $GITHUB_STEP_SUMMARY