-
Notifications
You must be signed in to change notification settings - Fork 8
209 lines (177 loc) · 7.54 KB
/
test.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
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
name: Update Test Report Issue
on:
push:
branches:
- main
jobs:
update-report:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
- name: Install dependencies
run: |
pip install pytest pytest-html pytest-json-report
- name: Generate timestamp
id: timestamp
run: |
echo "timestamp=$(date +%Y%m%d_%H%M%S)" >> $GITHUB_ENV
echo "formatted_date=$(date -u '+%A, %B %d, %Y %H:%M:%S')" >> $GITHUB_ENV
- name: Run tests
run: |
pytest --tb=no --html=report.html --self-contained-html --json-report --json-report-file=report.json tests
continue-on-error: true
- name: Checkout pages repo
uses: actions/checkout@v4
with:
repository: childmindresearch/niwrap-test-report
token: ${{ secrets.PAGES_DEPLOY_TOKEN }}
path: pages-repo
- name: Copy report to pages repo
run: |
mkdir -p pages-repo/test-reports
cp report.html pages-repo/test-reports/latest.html
cp report.html "pages-repo/test-reports/report-${{ env.timestamp }}-${GITHUB_SHA}.html"
- name: Clean old reports
run: |
cd pages-repo/test-reports
# Keep latest 30 reports plus latest.html
ls -t report-* | tail -n +31 | xargs -r rm
- name: Update index
run: |
cd pages-repo
cat > test-reports/index.html << EOF
<!DOCTYPE html>
<html>
<head>
<title>Test Report History</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th, td {
padding: 12px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background-color: #f6f8fa;
}
tr:hover {
background-color: #f6f8fa;
}
a {
color: #0366d6;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
.latest {
margin: 20px 0;
padding: 15px;
background-color: #f6f8fa;
border-radius: 6px;
}
</style>
</head>
<body>
<h1>Test Report History</h1>
<div class="latest">
<h2>Latest Report</h2>
<p><a href="latest.html?sort=result&visible=failed,error,xfailed,xpassed,rerun">View Latest Test Results</a></p>
</div>
<h2>Historical Reports</h2>
<table>
<thead>
<tr>
<th>Date</th>
<th>Commit</th>
<th>Report</th>
</tr>
</thead>
<tbody>
EOF
ls -t test-reports/report-* | while read file; do
filename=$(basename "$file")
# Extract date and time parts (assuming format: report-YYYYMMDD_HHMMSS-COMMIT.html)
datetime_part=$(echo $filename | cut -d'-' -f2)
commit=$(echo $filename | cut -d'-' -f3 | cut -d'.' -f1)
# Parse date and time
year=${datetime_part:0:4}
month=${datetime_part:4:2}
day=${datetime_part:6:2}
hour=${datetime_part:9:2}
minute=${datetime_part:11:2}
second=${datetime_part:13:2}
# Format date
formatted_date="$year-$month-$day $hour:$minute:$second"
echo "<tr><td>$formatted_date</td><td><a href='https://github.com/${GITHUB_REPOSITORY}/commit/$commit'>${commit:0:7}</a></td><td><a href=\"$filename?sort=result&visible=failed,error,xfailed,xpassed,rerun\">View Report</a></td></tr>" >> test-reports/index.html
done
cat >> test-reports/index.html << EOF
</tbody>
</table>
<footer style="margin-top: 40px; text-align: center; color: #586069;">
<p>Generated by GitHub Actions</p>
</footer>
</body>
</html>
EOF
- name: Commit and push to pages repo
run: |
cd pages-repo
git config user.name github-actions
git config user.email [email protected]
git add test-reports/
git commit -m "Update test report from ${{ github.repository }} @ ${{ github.sha }}"
git push
- name: Update Report Issue
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const report = JSON.parse(fs.readFileSync('report.json', 'utf8'));
const ISSUE_NUMBER = 186;
const REPORT_PARAMS = '?sort=result&visible=failed,error,xfailed,xpassed,rerun';
function formatPercentage(part, total) {
return ((part / total) * 100).toFixed(1) + '%';
}
const summary = `
# Test Status Report
Last updated: ${{ env.formatted_date }} UTC
## Test Coverage
| Category | Count | Percentage |
|----------|--------|------------|
| ✓ Passing | ${report.summary.passed} | ${formatPercentage(report.summary.passed, report.summary.total)} |
| × Failing | ${report.summary.failed} | ${formatPercentage(report.summary.failed, report.summary.total)} |
| ⚠ Skipped | ${report.summary.skipped || 0} | ${formatPercentage(report.summary.skipped || 0, report.summary.total)} |
| **Total** | **${report.summary.total}** | **100%** |
Test duration: ${Math.floor(report.duration * 100) / 100}s
## Quick Links
📊 [Latest Results](https://${context.repo.owner}.github.io/niwrap-test-report/test-reports/latest.html${REPORT_PARAMS})
📈 [Historical Reports](https://${context.repo.owner}.github.io/niwrap-test-report/test-reports/index.html)
🔍 [This Run](https://${context.repo.owner}.github.io/niwrap-test-report/test-reports/report-${{ env.timestamp }}-${context.sha}.html${REPORT_PARAMS})
## Build Details
| Category | Detail |
|----------|---------|
| Branch | \`main\` |
| Commit | [\`${context.sha.substring(0, 7)}\`](https://github.com/${context.repo.owner}/${context.repo.repo}/commit/${context.sha}) |
| Action | [View Run](https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}) |
<sub>🤖 Auto-generated on main branch updates | [View Test Configuration](https://github.com/${context.repo.owner}/${context.repo.repo}/tree/main/tests)</sub>
`;
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ISSUE_NUMBER,
body: summary
});