-
Notifications
You must be signed in to change notification settings - Fork 0
94 lines (80 loc) · 3.28 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
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
path: test-results
continue-on-error: true
- name: Process test results
if: steps.test-results.outcome == 'success'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = require('path');
try {
const resultsPath = path.join(process.env.GITHUB_WORKSPACE, 'test-results', 'results.json');
if (!fs.existsSync(resultsPath)) {
console.log('No test results file found');
return;
}
// Read test results
const results = JSON.parse(fs.readFileSync(resultsPath, 'utf8'));
if (!results.tests || !Array.isArray(results.tests)) {
console.log('Invalid test results format');
return;
}
// Get list of all test nodeids
const testNodeIds = results.tests.map(test => test.nodeid);
// 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];
// Find corresponding test in results
const test = results.tests.find(t => t.nodeid.split('::').pop() === shortTestName);
// Close if test is passing or if test no longer exists
if (!test || test.outcome === 'passed') {
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
state: 'closed'
});
const closeReason = test ? 'Test passed' : 'Test was removed';
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: `${closeReason} in commit ${context.sha}`
});
}
}
} catch (error) {
console.error('Error processing test results:', error);
core.setFailed(error.message);
}