-
Notifications
You must be signed in to change notification settings - Fork 0
143 lines (127 loc) · 5.56 KB
/
test-issues.yml
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
name: Test Issue Management
on:
workflow_run:
workflows: ["Tests"]
types:
- completed
permissions:
issues: write
contents: read
jobs:
manage-test-issues:
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'failure'
steps:
- uses: actions/checkout@v4
- name: Get test results
id: test-results
uses: dawidd6/action-download-artifact@bf251b5aa9c2f7eeb574a96ee720e24f801b7c11
with:
workflow: tests.yml
run_id: ${{ github.event.workflow_run.id }}
name: pytest-results-3.11
path: test-results-3.11
continue-on-error: true
- name: Get test results (Python 3.12)
id: test-results-3-12
uses: dawidd6/action-download-artifact@bf251b5aa9c2f7eeb574a96ee720e24f801b7c11
with:
workflow: tests.yml
run_id: ${{ github.event.workflow_run.id }}
name: pytest-results-3.12
path: test-results-3.12
continue-on-error: true
- name: Get test results (Python 3.13)
id: test-results-3-13
uses: dawidd6/action-download-artifact@bf251b5aa9c2f7eeb574a96ee720e24f801b7c11
with:
workflow: tests.yml
run_id: ${{ github.event.workflow_run.id }}
name: pytest-results-3.13
path: test-results-3.13
continue-on-error: true
- name: Process test results
if: steps.test-results.outcome == 'success' || steps.test-results-3-12.outcome == 'success' || steps.test-results-3-13.outcome == 'success'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = require('path');
try {
// Process results from all Python versions
const versions = ['3.11', '3.12', '3.13'];
const allTests = new Set();
const failedTests = new Set();
for (const version of versions) {
const resultsPath = path.join(process.env.GITHUB_WORKSPACE, `test-results-${version}`, 'results.json');
if (!fs.existsSync(resultsPath)) {
console.log(`No test results found for Python ${version}`);
continue;
}
// Read test results
const results = JSON.parse(fs.readFileSync(resultsPath, 'utf8'));
if (!results.tests || !Array.isArray(results.tests)) {
console.log(`Invalid test results format for Python ${version}`);
continue;
}
// Process each test
for (const test of results.tests) {
const testName = `${test.nodeid}`;
const shortTestName = testName.split('::').pop();
allTests.add(shortTestName);
if (test.outcome === 'failed') {
failedTests.add({
shortTestName,
testName,
errorMessage: test.call?.longrepr || 'No error message available',
version
});
}
}
}
// Process failed tests
for (const failedTest of failedTests) {
// Search for existing issues
const issues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'all',
labels: ['tests']
});
// Find issue with matching test name in title
const existingIssue = issues.data.find(issue =>
issue.title === `Test Failure: ${failedTest.shortTestName}`
);
if (existingIssue) {
// Issue exists, reopen if closed
if (existingIssue.state === 'closed') {
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: existingIssue.number,
state: 'open'
});
// Add comment only when reopening
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: existingIssue.number,
body: `Test failed again in commit ${context.sha} (Python ${failedTest.version})\n\nFull test name: ${failedTest.testName}\n\nError message:\n\`\`\`\n${failedTest.errorMessage}\n\`\`\``
});
}
// No comment if issue is already open
} else {
// Create new issue
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `Test Failure: ${failedTest.shortTestName}`,
body: `Test failed in commit ${context.sha} (Python ${failedTest.version})\n\nFull test name: ${failedTest.testName}\n\nError message:\n\`\`\`\n${failedTest.errorMessage}\n\`\`\``,
labels: ['tests']
});
}
}
} catch (error) {
console.error('Error processing test results:', error);
core.setFailed(error.message);
}