-
Notifications
You must be signed in to change notification settings - Fork 12
300 lines (257 loc) · 13.7 KB
/
auto-generate-codebundle.yml
File metadata and controls
300 lines (257 loc) · 13.7 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
name: Auto-Generate Codebundle from Issue
on:
issues:
types: [opened, labeled]
workflow_dispatch:
inputs:
issue_number:
description: 'Issue number to process'
required: true
type: number
use_ai:
description: 'Use AI for generation (requires OpenAI API key in secrets)'
required: false
type: boolean
default: true
jobs:
generate-codebundle:
# Run if manually triggered OR if issue has labels containing 'new' and 'auto-intake'
if: |
github.event_name == 'workflow_dispatch' ||
(contains(join(github.event.issue.labels.*.name, ' '), 'new') &&
contains(join(github.event.issue.labels.*.name, ' '), 'auto-intake'))
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
issues: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Update labels - Start Processing
uses: actions/github-script@v7
with:
script: |
const issueNumber = ${{ github.event.inputs.issue_number || github.event.issue.number }};
// Add processing label
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
labels: ['codebundle-processing']
});
// Remove trigger labels (anything with 'new' or 'auto-intake')
const { data: issue } = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber
});
for (const label of issue.labels) {
const labelName = typeof label === 'string' ? label : label.name;
if (labelName.includes('new') || labelName.includes('auto-intake')) {
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
name: labelName
});
console.log(`Removed trigger label: ${labelName}`);
} catch (error) {
console.log(`Could not remove label ${labelName}: ${error.message}`);
}
}
}
- name: Generate Codebundle
id: generate
uses: runwhen-contrib/github-actions/codebundle-generator@feat/auto-cb
with:
issue-number: ${{ github.event.inputs.issue_number || github.event.issue.number }}
github-token: ${{ secrets.GITHUB_TOKEN }}
openai-api-key: ${{ secrets.OPENAI_API_KEY }}
- name: Debug Action Outputs
continue-on-error: true
run: |
echo "=== ACTION OUTPUTS DEBUG ==="
echo "codebundle-name: '${{ steps.generate.outputs.codebundle-name }}'"
echo "generated-files: '${{ steps.generate.outputs.generated-files }}'"
echo "generated-tasks: '${{ steps.generate.outputs.generated-tasks }}'"
echo "success: '${{ steps.generate.outputs.success }}'"
echo "total-tokens: '${{ steps.generate.outputs.total-tokens }}'"
echo "prompt-tokens: '${{ steps.generate.outputs.prompt-tokens }}'"
echo "completion-tokens: '${{ steps.generate.outputs.completion-tokens }}'"
echo "api-calls: '${{ steps.generate.outputs.api-calls }}'"
echo "=== END OUTPUTS DEBUG ==="
- name: Check if codebundle was generated
id: check-generation
run: |
# Check the success output from the generator
if [ "${{ steps.generate.outputs.success }}" = "true" ]; then
echo "generated=true" >> $GITHUB_OUTPUT
echo "✅ Codebundle generation successful: ${{ steps.generate.outputs.codebundle-name }}"
elif [ "${{ steps.generate.outputs.success }}" = "false" ]; then
echo "generated=false" >> $GITHUB_OUTPUT
echo "❌ Codebundle generation failed: ${{ steps.generate.outputs.codebundle-name }}"
elif [ -n "${{ steps.generate.outputs.codebundle-name }}" ] && [ "${{ steps.generate.outputs.codebundle-name }}" != "unknown" ]; then
echo "generated=true" >> $GITHUB_OUTPUT
echo "✅ Codebundle generation detected via outputs: ${{ steps.generate.outputs.codebundle-name }}"
elif find codebundles/ -maxdepth 1 -type d -newer codebundles/ 2>/dev/null | grep -q .; then
echo "generated=true" >> $GITHUB_OUTPUT
echo "✅ Codebundle generation detected via file system changes"
else
echo "generated=false" >> $GITHUB_OUTPUT
echo "❌ No codebundle generation detected"
fi
- name: Create Pull Request
if: steps.check-generation.outputs.generated == 'true'
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "feat: auto-generated codebundle from issue #${{ github.event.inputs.issue_number || github.event.issue.number }}"
title: "✨ Auto-generated codebundle: ${{ steps.generate.outputs.codebundle-name || format('from issue #{0}', github.event.inputs.issue_number || github.event.issue.number) }}"
body: |
## ✨ Auto-Generated Codebundle
This codebundle was automatically generated using AI based on the requirements in issue #${{ github.event.inputs.issue_number || github.event.issue.number }}.
### 📦 Generated Components
**Codebundle Location:** `codebundles/${{ steps.generate.outputs.codebundle-name || 'unknown' }}/`
**Generated Files:**
- **Bash Scripts:** ${{ steps.generate.outputs.generated-files || 'None listed' }}
- **Robot Framework Tasks:** ${{ steps.generate.outputs.generated-tasks || 'Unknown count' }} tasks
- **Documentation:** README.md with usage instructions
- **Cursor Rules:** .cursorrules for development assistance
- **RunWhen Templates:** .runwhen/ directory with SLI, Taskset, and Workflow templates
- **Test Directory:** .test/ for validation scripts
### 🤖 AI Generation Details
| Metric | Value |
|--------|-------|
| **Total Tokens Used** | ${{ steps.generate.outputs.total-tokens || 'Not available' }} |
| **Prompt Tokens** | ${{ steps.generate.outputs.prompt-tokens || 'Not available' }} |
| **Completion Tokens** | ${{ steps.generate.outputs.completion-tokens || 'Not available' }} |
| **API Calls Made** | ${{ steps.generate.outputs.api-calls || 'Not available' }} |
| **Model Used** | GPT-4 |
| **Generation Method** | AI-powered with reference codebundle context |
### Review Checklist
- [ ] Review generated bash scripts for correctness
- [ ] Test Robot Framework tasks locally
- [ ] Check README documentation
- [ ] Validate against existing patterns
### Next Steps
1. Review the generated code
2. Test locally using the provided instructions
3. Make any necessary adjustments
4. Merge when ready
**Auto-closes**: #${{ github.event.inputs.issue_number || github.event.issue.number }}
branch: auto-codebundle-${{ github.event.inputs.issue_number || github.event.issue.number }}
delete-branch: true
- name: Update issue labels on success
if: steps.check-generation.outputs.generated == 'true'
uses: actions/github-script@v7
with:
script: |
// Remove processing label and add success label
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ github.event.inputs.issue_number || github.event.issue.number }},
name: 'codebundle-processing'
});
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ github.event.inputs.issue_number || github.event.issue.number }},
labels: ['codebundle-generated', 'pr-created']
});
// Add comment with PR link
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ github.event.inputs.issue_number || github.event.issue.number }},
body: `✨ **Codebundle Generated Successfully!**
I've created a pull request with your auto-generated codebundle: **${{ steps.generate.outputs.codebundle-name }}**
The PR includes:
- Complete codebundle structure
- Generated bash scripts for your tasks
- Robot Framework task definitions
- Documentation and metadata
📊 **AI Generation Stats:**
- Total tokens used: ${{ steps.generate.outputs.total-tokens }}
- API calls made: ${{ steps.generate.outputs.api-calls }}
Please review the generated code and merge when ready!`
});
- name: Handle generation failure
if: steps.check-generation.outputs.generated == 'false'
uses: actions/github-script@v7
with:
script: |
// Remove processing label and add failure label
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ github.event.inputs.issue_number || github.event.issue.number }},
name: 'codebundle-processing'
});
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ github.event.inputs.issue_number || github.event.issue.number }},
labels: ['codebundle-failed']
});
// Add detailed failure comment
const failureReason = '${{ steps.generate.outputs.codebundle-name }}';
let failureMessage = '';
if (failureReason === 'generation-failed') {
failureMessage = 'The AI generation process encountered an error. This could be due to:\n- OpenAI API issues or rate limits\n- Invalid or unclear requirements in the issue\n- Missing OpenAI API key in repository secrets';
} else if (failureReason === 'fatal-error') {
failureMessage = 'A fatal error occurred during initialization. This could be due to:\n- Missing required environment variables\n- GitHub API authentication issues\n- Invalid issue format or content';
} else {
failureMessage = 'The codebundle generation process completed but no output was produced.';
}
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ github.event.inputs.issue_number || github.event.issue.number }},
body: `❌ **Codebundle Generation Failed**
${failureMessage}
**Debug Information:**
- Failure Type: \`${failureReason}\`
- Workflow Run: [View Logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
**Next Steps:**
1. Check the workflow logs for detailed error messages
2. Verify your issue follows the required format
3. Ensure OpenAI API key is configured in repository secrets
4. Try again or contact support if the issue persists`
});
- name: Update issue labels on workflow failure
if: failure()
uses: actions/github-script@v7
with:
script: |
// Remove processing label and add failure label
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ github.event.inputs.issue_number || github.event.issue.number }},
name: 'codebundle-processing'
});
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ github.event.inputs.issue_number || github.event.issue.number }},
labels: ['codebundle-failed']
});
// Add comment about failure
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ github.event.inputs.issue_number || github.event.issue.number }},
body: `❌ **Codebundle Generation Failed**
I encountered an error while trying to generate your codebundle. Please check the [workflow logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.
Common issues:
- Missing or unclear requirements in the issue description
- Unsupported platform or service type
- API rate limits
Please update your issue with more details and I'll try again!`
});