-
Notifications
You must be signed in to change notification settings - Fork 1
231 lines (205 loc) · 7.07 KB
/
ci-full.yml
File metadata and controls
231 lines (205 loc) · 7.07 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
name: CI (full)
on:
push:
branches: [main, master]
workflow_dispatch:
jobs:
quality-checks:
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: write
env:
NODE_OPTIONS: --max-old-space-size=4096 # increase default to 4GB for all steps in this job
strategy:
fail-fast: false
matrix:
python-version: ['3.12'] # Can add '3.13' when dependencies support it
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Ensure empty .env (for safety)
run: |
rm -f .env
touch .env
- name: Install uv
uses: astral-sh/setup-uv@v6
with:
version: "latest"
- name: Set up Python
run: uv python install ${{ matrix.python-version }}
- name: Cache uv dependencies
uses: actions/cache@v4
with:
path: ~/.cache/uv
key: ${{ runner.os }}-uv-${{ hashFiles('uv.lock', 'pyproject.toml') }}
restore-keys: |
${{ runner.os }}-uv-
- name: Install dependencies
run: make install
- name: Check notebooks have no outputs
run: uv run make check-notebooks
- name: Run linting
run: uv run make lint
- name: Run full test suite with coverage
run: uv run make coverage
- name: Coverage comment (update baseline)
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
continue-on-error: true
uses: py-cov-action/python-coverage-comment-action@v3
with:
GITHUB_TOKEN: ${{ github.token }}
MERGE_COVERAGE_FILES: false
- name: Upload coverage artifacts
if: always() && hashFiles('logs/coverage/**') != ''
uses: actions/upload-artifact@v4
with:
name: coverage-report-${{ matrix.python-version }}
path: logs/coverage/
open-issue-on-failure:
name: Open issue on full CI failure
runs-on: ubuntu-latest
needs: quality-checks
if: always() && github.event_name == 'push' && needs.quality-checks.result == 'failure'
permissions:
contents: read
issues: write
steps:
- name: Open or update issue on failure
continue-on-error: true
uses: actions/github-script@v7
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const branchName = context.ref.replace("refs/heads/", "");
const shortSha = context.sha.substring(0, 7);
const runUrl = `${context.serverUrl}/${owner}/${repo}/actions/runs/${context.runId}`;
const actorLogin = context.actor;
const issueLabel = "ci-failure";
const marker = `<!-- ci-full-failure:${branchName} -->`;
let labelExists = true;
try {
await github.rest.issues.getLabel({
owner,
repo,
name: issueLabel,
});
} catch (error) {
if (error.status === 404) {
labelExists = false;
try {
await github.rest.issues.createLabel({
owner,
repo,
name: issueLabel,
color: "B60205",
description: "Automated full CI failure tracker",
});
labelExists = true;
} catch (labelCreateError) {
if (labelCreateError.status === 422) {
labelExists = true;
} else {
core.warning(`Could not create label "${issueLabel}": ${labelCreateError.message}`);
}
}
} else {
throw error;
}
}
const openIssues = await github.paginate(github.rest.issues.listForRepo, {
owner,
repo,
state: "open",
per_page: 100,
});
const existingIssue = openIssues.find(
(issue) => !issue.pull_request && issue.body && issue.body.includes(marker),
);
const failureSummaryLine = `- ${new Date().toISOString()}: \`${shortSha}\` by @${actorLogin} ([run link](${runUrl}))`;
if (existingIssue) {
await github.rest.issues.createComment({
owner,
repo,
issue_number: existingIssue.number,
body: [
"Another `CI (full)` failure was detected on this branch.",
"",
failureSummaryLine,
].join("\n"),
});
} else {
const labels = labelExists ? [issueLabel] : [];
await github.rest.issues.create({
owner,
repo,
title: `CI (full) failing on ${branchName}`,
body: [
`The full CI workflow failed after a push to \`${branchName}\`.`,
"",
`- **Latest commit:** ${context.sha}`,
`- **Actor:** @${actorLogin}`,
`- **Failed run:** ${runUrl}`,
"",
"This issue is automatically updated while failures continue on this branch.",
"",
"Recent failures:",
failureSummaryLine,
"",
marker,
].join("\n"),
labels,
});
}
close-issue-on-success:
name: Close issue when full CI recovers
runs-on: ubuntu-latest
needs: quality-checks
if: always() && github.event_name == 'push' && needs.quality-checks.result == 'success'
permissions:
contents: read
issues: write
steps:
- name: Close matching failure issue on success
continue-on-error: true
uses: actions/github-script@v7
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const branchName = context.ref.replace("refs/heads/", "");
const shortSha = context.sha.substring(0, 7);
const runUrl = `${context.serverUrl}/${owner}/${repo}/actions/runs/${context.runId}`;
const marker = `<!-- ci-full-failure:${branchName} -->`;
const openIssues = await github.paginate(github.rest.issues.listForRepo, {
owner,
repo,
state: "open",
per_page: 100,
});
const matchingIssue = openIssues.find(
(issue) => !issue.pull_request && issue.body && issue.body.includes(marker),
);
if (!matchingIssue) {
return;
}
await github.rest.issues.createComment({
owner,
repo,
issue_number: matchingIssue.number,
body: [
"Full CI is passing again on this branch.",
"",
`- **Recovered commit:** ${context.sha}`,
`- **Successful run:** ${runUrl}`,
"",
`Closing this issue after recovery at \`${shortSha}\`.`,
].join("\n"),
});
await github.rest.issues.update({
owner,
repo,
issue_number: matchingIssue.number,
state: "closed",
});