Skip to content

Commit 63a0a7b

Browse files
author
Kim Harjamaki
committed
Add Autopilot demo workflows
1 parent 0c81a8a commit 63a0a7b

3 files changed

Lines changed: 129 additions & 2 deletions

File tree

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
name: Autopilot Issue Intake
2+
3+
on:
4+
workflow_run:
5+
# Update this list in each repo to match the workflows you want monitored.
6+
workflows: ["Demo CI"]
7+
types: [completed]
8+
9+
permissions:
10+
actions: read
11+
issues: write
12+
contents: read
13+
14+
jobs:
15+
create-issue:
16+
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Create or update issue
20+
uses: actions/github-script@v7
21+
with:
22+
script: |
23+
const run = context.payload.workflow_run;
24+
const owner = context.repo.owner;
25+
const repo = context.repo.repo;
26+
const runId = run.id;
27+
const signature = `${run.name}|${run.head_sha}`;
28+
const marker = `Autopilot Signature: ${signature}`;
29+
30+
const jobs = await github.rest.actions.listJobsForWorkflowRun({
31+
owner,
32+
repo,
33+
run_id: runId,
34+
per_page: 100,
35+
});
36+
37+
const failedSteps = [];
38+
for (const job of jobs.data.jobs) {
39+
if (job.conclusion !== 'success') {
40+
for (const step of job.steps || []) {
41+
if (step.conclusion === 'failure') {
42+
failedSteps.push(`- ${job.name}: ${step.name}`);
43+
}
44+
}
45+
}
46+
}
47+
48+
const stepSummary = failedSteps.length
49+
? failedSteps.join('\n')
50+
: '- (no failed step details available)';
51+
52+
const title = `Autopilot intake: ${run.name} failed on ${run.head_branch}`;
53+
const body = [
54+
marker,
55+
'',
56+
`Workflow: ${run.name}`,
57+
`Branch: ${run.head_branch}`,
58+
`SHA: ${run.head_sha}`,
59+
`Run: ${run.html_url}`,
60+
'',
61+
'Failed steps:',
62+
stepSummary,
63+
'',
64+
'Labels: autofix, queued, safe-small, ci'
65+
].join('\n');
66+
67+
const desiredLabels = ['autofix', 'queued', 'safe-small', 'ci'];
68+
const existingLabels = await github.paginate(github.rest.issues.listLabelsForRepo, {
69+
owner,
70+
repo,
71+
per_page: 100,
72+
});
73+
const existingNames = new Set(existingLabels.map((l) => l.name));
74+
for (const label of desiredLabels) {
75+
if (!existingNames.has(label)) {
76+
await github.rest.issues.createLabel({
77+
owner,
78+
repo,
79+
name: label,
80+
color: 'ededed',
81+
});
82+
}
83+
}
84+
85+
const search = await github.rest.search.issuesAndPullRequests({
86+
q: `repo:${owner}/${repo} is:issue in:body "${marker}"`,
87+
});
88+
89+
if (search.data.items.length > 0) {
90+
const issue = search.data.items[0];
91+
await github.rest.issues.update({
92+
owner,
93+
repo,
94+
issue_number: issue.number,
95+
body,
96+
});
97+
await github.rest.issues.addLabels({
98+
owner,
99+
repo,
100+
issue_number: issue.number,
101+
labels: desiredLabels,
102+
});
103+
} else {
104+
await github.rest.issues.create({
105+
owner,
106+
repo,
107+
title,
108+
body,
109+
labels: desiredLabels,
110+
});
111+
}

.github/workflows/demo-ci.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Demo CI
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [main]
7+
8+
jobs:
9+
demo:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Intentional failure
13+
run: |
14+
echo "Simulated failure for Autopilot demo."
15+
exit 1

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
# autopilot-demo
2-
CI Autopilot demo repo
1+
# Autopilot Demo Repo
2+
3+
Trigger the `Demo CI` workflow to produce a failure. The intake workflow will open an issue with `autofix` and `queued` labels.

0 commit comments

Comments
 (0)