Repository navigation
407 lines (362 loc) · 15.2 KB
/
Copy pathagent_fix-obi.yml
File metadata and controls
407 lines (362 loc) · 15.2 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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
name: Fix OBI submodule CI
on:
pull_request:
types: [labeled]
permissions: {}
concurrency:
group: "fix-obi-${{ github.event.pull_request.number || github.ref }}"
cancel-in-progress: true
jobs:
wait-for-ci:
name: Wait for CI completion
if: >
github.event.action == 'labeled' &&
github.event.label.name == 'agent/fix-obi' &&
github.event.pull_request.head.repo.id == github.repository_id
runs-on: ubuntu-latest
permissions:
contents: read
checks: read
id-token: write
timeout-minutes: 150
steps:
- name: Get GitHub App token
id: get-github-app-token
uses: grafana/shared-workflows/actions/create-github-app-token@ae92934a14a48b94494dbc06d74a81d47fe08a40 # create-github-app-token/v0.2.2
with:
github_app: grafana-beyla-bot
- name: Wait for all CI checks to complete
env:
GH_TOKEN: ${{ steps.get-github-app-token.outputs.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
run: |
set -euo pipefail
# Exact names to exclude (our own workflow and the supervisor)
EXCLUDED_NAMES='["Fix OBI submodule CI","CI Supervisor: Rerun flaky failures","Wait for CI completion","Triage CI failures","Plan fixes","Implement and push","Remove agent label","Evaluate failed checks","Add agent/fix-obi label","Add agent/fix-obi-pending label","Handle CI completion","Request Copilot review"]'
# Retry wrapper for transient GitHub API errors (e.g. 401 token refresh race)
gh_retry() {
local attempt
for attempt in 1 2 3; do
if output=$("$@" 2>&1); then
echo "$output"
return 0
fi
echo "::warning::API call failed (attempt ${attempt}/3): $output" >&2
sleep 10
done
echo "::error::API call failed after 3 attempts" >&2
return 1
}
echo "Waiting for all CI checks on PR #${PR_NUMBER} to complete..."
while true; do
HEAD_SHA=$(gh_retry gh pr view "$PR_NUMBER" --repo "$REPO" --json headRefOid --jq '.headRefOid')
# Build set of check-suite IDs from pull_request-triggered workflow runs.
# This excludes schedule/workflow_dispatch/push runs that share the same SHA,
# matching the approach in scripts/release-train.sh:check_ci_green().
PR_SUITE_IDS=$(
gh_retry gh api --paginate -H "Accept: application/vnd.github+json" \
"repos/${REPO}/actions/runs?head_sha=${HEAD_SHA}&event=pull_request&per_page=100" \
| jq -s '[ map(.workflow_runs // []) | add // [] | .[].check_suite_id ]'
)
# Fetch all check-runs, filter to PR suites + non-Actions apps, deduplicate by name.
ALL_CHECKS=$(
gh_retry gh api --paginate -H "Accept: application/vnd.github+json" \
"repos/${REPO}/commits/${HEAD_SHA}/check-runs?per_page=100" \
| jq -s '{check_runs: ((map(.check_runs // []) | add) // [])}'
)
CHECKS_JSON=$(
echo "$ALL_CHECKS" \
| jq --argjson pr_suites "$PR_SUITE_IDS" --argjson excluded "$EXCLUDED_NAMES" \
'{check_runs: [
.check_runs[]
| select(
.app.slug != "github-actions"
or (.check_suite.id as $id | $pr_suites | index($id))
)
| select(
(.name as $n | $excluded | index($n)) | not
)
]}' \
| jq '{check_runs: [.check_runs | group_by(.name) | .[] | sort_by(.id) | last]}'
)
TOTAL=$(echo "$CHECKS_JSON" | jq '.check_runs | length')
PENDING=$(echo "$CHECKS_JSON" | jq '[.check_runs[] | select(.status != "completed")] | length')
if [ "$TOTAL" -eq 0 ]; then
echo "No CI checks found yet. Waiting 60s..."
sleep 60
continue
fi
if [ "$PENDING" -eq 0 ]; then
echo "All ${TOTAL} CI checks have completed."
# Log any non-green checks for visibility
NON_GREEN=$(echo "$CHECKS_JSON" | jq -r '[.check_runs[] | select(.conclusion != "success" and .conclusion != "neutral" and .conclusion != "skipped")] | length')
if [ "$NON_GREEN" -gt 0 ]; then
echo "Warning: ${NON_GREEN} check(s) are not green:"
echo "$CHECKS_JSON" | jq -r '.check_runs[] | select(.conclusion != "success" and .conclusion != "neutral" and .conclusion != "skipped") | " - \(.name): \(.conclusion // "none")"'
fi
break
fi
echo "${PENDING} of ${TOTAL} checks still pending. Waiting 60s..."
sleep 60
done
triage:
name: Triage CI failures
needs: wait-for-ci
if: >
github.event.action == 'labeled' &&
github.event.label.name == 'agent/fix-obi' &&
github.event.pull_request.head.repo.id == github.repository_id
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
id-token: write
timeout-minutes: 45
steps:
- name: Checkout repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: ${{ github.event.pull_request.head.ref }}
submodules: recursive
persist-credentials: false
- name: Set up Go
uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6.5.0
with:
go-version-file: go.mod
cache: false
- name: Generate files
run: make prereqs vendor-obi
- name: Get vault secrets
uses: grafana/shared-workflows/actions/get-vault-secrets@f1614b210386ac420af6807a997ac7f6d96e477a # get-vault-secrets/v1.3.1
with:
repo_secrets: |
ANTHROPIC_API_KEY=anthropic-token:token
- name: Get GitHub App token
id: get-github-app-token
uses: grafana/shared-workflows/actions/create-github-app-token@ae92934a14a48b94494dbc06d74a81d47fe08a40 # create-github-app-token/v0.2.2
with:
github_app: grafana-beyla-bot
- name: Load triage prompt
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
PROMPT=$(cat .github/prompts/fix-obi/triage.md)
PROMPT="${PROMPT//\{\{PR_NUMBER\}\}/${PR_NUMBER}}"
PROMPT="${PROMPT//\{\{PR_TITLE\}\}/${PR_TITLE}}"
{
echo 'AGENT_PROMPT<<PROMPT_EOF'
echo "$PROMPT"
echo 'PROMPT_EOF'
} >> "$GITHUB_ENV"
- name: Run Claude Code – Triage
uses: anthropics/claude-code-action@558b1d6cab4085c7753fe402c10bef0fbb92ac7a # v1.0.165
with:
anthropic_api_key: ${{ env.ANTHROPIC_API_KEY }}
github_token: ${{ steps.get-github-app-token.outputs.token }}
label_trigger: agent/fix-obi
allowed_bots: "grafana-beyla-bot"
use_sticky_comment: "true"
use_commit_signing: "false"
claude_args: >-
--max-turns 75
--allowedTools
"Bash(cat:*),Bash(gh:*),Bash(grep:*),Bash(head:*),Bash(jq:*),
Bash(ls:*),Bash(python3:*),Bash(tail:*),Bash(wc:*),
Glob,Grep,LS,Read,Write,Task,TodoWrite"
prompt: ${{ env.AGENT_PROMPT }}
env:
DISABLE_TELEMETRY: "1"
DISABLE_ERROR_REPORTING: "1"
- name: Upload triage artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: triage
path: triage.md
if-no-files-found: error
plan:
name: Plan fixes
needs: triage
if: >
github.event.action == 'labeled' &&
github.event.label.name == 'agent/fix-obi' &&
github.event.pull_request.head.repo.id == github.repository_id
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
id-token: write
timeout-minutes: 45
steps:
- name: Checkout repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: ${{ github.event.pull_request.head.ref }}
submodules: recursive
persist-credentials: false
- name: Set up Go
uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6.5.0
with:
go-version-file: go.mod
cache: false
- name: Generate files
run: make prereqs vendor-obi
- name: Download triage artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: triage
- name: Get vault secrets
uses: grafana/shared-workflows/actions/get-vault-secrets@f1614b210386ac420af6807a997ac7f6d96e477a # get-vault-secrets/v1.3.1
with:
repo_secrets: |
ANTHROPIC_API_KEY=anthropic-token:token
- name: Get GitHub App token
id: get-github-app-token
uses: grafana/shared-workflows/actions/create-github-app-token@ae92934a14a48b94494dbc06d74a81d47fe08a40 # create-github-app-token/v0.2.2
with:
github_app: grafana-beyla-bot
- name: Load plan prompt
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
PROMPT=$(cat .github/prompts/fix-obi/plan.md)
PROMPT="${PROMPT//\{\{PR_NUMBER\}\}/${PR_NUMBER}}"
PROMPT="${PROMPT//\{\{PR_TITLE\}\}/${PR_TITLE}}"
{
echo 'AGENT_PROMPT<<PROMPT_EOF'
echo "$PROMPT"
echo 'PROMPT_EOF'
} >> "$GITHUB_ENV"
- name: Run Claude Code – Plan
uses: anthropics/claude-code-action@558b1d6cab4085c7753fe402c10bef0fbb92ac7a # v1.0.165
with:
anthropic_api_key: ${{ env.ANTHROPIC_API_KEY }}
github_token: ${{ steps.get-github-app-token.outputs.token }}
label_trigger: agent/fix-obi
allowed_bots: "grafana-beyla-bot"
use_sticky_comment: "true"
use_commit_signing: "false"
claude_args: >-
--max-turns 100
--allowedTools
"Bash(cat:*),Bash(git:*),Bash(grep:*),Bash(head:*),Bash(ls:*),Bash(pwd:*),Bash(tail:*),Bash(wc:*),
Glob,Grep,LS,Read,Write,Task,TodoWrite"
prompt: ${{ env.AGENT_PROMPT }}
env:
DISABLE_TELEMETRY: "1"
DISABLE_ERROR_REPORTING: "1"
- name: Upload plan artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: plan
path: plan.md
if-no-files-found: error
implement:
name: Implement and push
needs: plan
if: >
github.event.action == 'labeled' &&
github.event.label.name == 'agent/fix-obi' &&
github.event.pull_request.head.repo.id == github.repository_id
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
id-token: write
timeout-minutes: 45
steps:
- name: Checkout repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: ${{ github.event.pull_request.head.ref }}
submodules: recursive
persist-credentials: false
- name: Set up Go
uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6.5.0
with:
go-version-file: go.mod
cache: false
- name: Generate files
run: make prereqs vendor-obi
- name: Download triage artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: triage
- name: Download plan artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: plan
- name: Get vault secrets
uses: grafana/shared-workflows/actions/get-vault-secrets@f1614b210386ac420af6807a997ac7f6d96e477a # get-vault-secrets/v1.3.1
with:
repo_secrets: |
ANTHROPIC_API_KEY=anthropic-token:token
- name: Get GitHub App token
id: get-github-app-token
uses: grafana/shared-workflows/actions/create-github-app-token@ae92934a14a48b94494dbc06d74a81d47fe08a40 # create-github-app-token/v0.2.2
with:
github_app: grafana-beyla-bot
- name: Load implement prompt
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
PROMPT=$(cat .github/prompts/fix-obi/implement.md)
PROMPT="${PROMPT//\{\{PR_NUMBER\}\}/${PR_NUMBER}}"
PROMPT="${PROMPT//\{\{PR_TITLE\}\}/${PR_TITLE}}"
{
echo 'AGENT_PROMPT<<PROMPT_EOF'
echo "$PROMPT"
echo 'PROMPT_EOF'
} >> "$GITHUB_ENV"
- name: Run Claude Code – Implement
uses: anthropics/claude-code-action@558b1d6cab4085c7753fe402c10bef0fbb92ac7a # v1.0.165
with:
anthropic_api_key: ${{ env.ANTHROPIC_API_KEY }}
github_token: ${{ steps.get-github-app-token.outputs.token }}
label_trigger: agent/fix-obi
allowed_bots: "grafana-beyla-bot"
use_sticky_comment: "true"
use_commit_signing: "true"
claude_args: >-
--max-turns 100
--allowedTools
"Bash(bash:*),Bash(cat:*),Bash(date:*),Bash(echo:*),Bash(gh:*),
Bash(git:*),Bash(go:*),Bash(grep:*),Bash(head:*),Bash(jq:*),
Bash(ls:*),Bash(make:*),Bash(python3:*),Bash(pwd:*),
Bash(sh:*),Bash(sort:*),Bash(tail:*),Bash(uniq:*),Bash(wc:*),
Edit,MultiEdit,Glob,Grep,LS,Read,Write,Task,TodoWrite,
mcp__github_file_ops__commit_files,
mcp__github_file_ops__delete_files,
mcp__github_file_ops__update_claude_comment,
mcp__github_file_ops__create_or_update_file"
prompt: ${{ env.AGENT_PROMPT }}
env:
DISABLE_TELEMETRY: "1"
DISABLE_ERROR_REPORTING: "1"
cleanup:
name: Remove agent label
needs: implement
if: always() && github.event.label.name == 'agent/fix-obi'
runs-on: ubuntu-latest
permissions:
pull-requests: write
id-token: write
timeout-minutes: 5
steps:
- name: Get GitHub App token
id: get-github-app-token
uses: grafana/shared-workflows/actions/create-github-app-token@ae92934a14a48b94494dbc06d74a81d47fe08a40 # create-github-app-token/v0.2.2
with:
github_app: grafana-beyla-bot
- name: Remove agent/fix-obi label
env:
GH_TOKEN: ${{ steps.get-github-app-token.outputs.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
run: |
echo "Removing agent labels from PR #${PR_NUMBER} to allow re-triggering"
gh pr edit "$PR_NUMBER" --repo "$REPO" --remove-label "agent/fix-obi" || true
gh pr edit "$PR_NUMBER" --repo "$REPO" --remove-label "agent/fix-obi-pending" || true