-
Notifications
You must be signed in to change notification settings - Fork 0
135 lines (116 loc) · 5.06 KB
/
close-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
name: Close Test Issues
on:
workflow_run:
workflows: ["Tests"]
types:
- completed
permissions:
issues: write
contents: read
jobs:
close-test-issues:
runs-on: ubuntu-latest
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 testOutcomes = new Map(); // Track outcomes per test across versions
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 shortTestName = test.nodeid.split('::').pop();
allTests.add(shortTestName);
// Track test outcome
if (!testOutcomes.has(shortTestName)) {
testOutcomes.set(shortTestName, { passed: false, exists: true });
}
// Update outcome - a test passes if it passes in any version
if (test.outcome === 'passed') {
testOutcomes.get(shortTestName).passed = true;
}
}
}
// Get open test failure issues
const issues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
labels: ['tests']
});
// Close issues for tests that are now passing or no longer exist
for (const issue of issues.data) {
// Extract test name from issue title
const match = issue.title.match(/^Test Failure: (.+)$/);
if (!match) continue;
const shortTestName = match[1];
const testOutcome = testOutcomes.get(shortTestName);
// Close if test is passing in any version or if test no longer exists
if (!testOutcome || testOutcome.passed) {
const closeReason = !testOutcome ? 'Test was removed' : 'Test passed';
// Add comment first
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: `${closeReason} in commit ${context.sha}`
});
// Then close the issue
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
state: 'closed'
});
}
}
} catch (error) {
console.error('Error processing test results:', error);
core.setFailed(error.message);
}