Add CI test workflow with job summaries
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env node
|
||||
const fs = require('fs');
|
||||
|
||||
const [, , resultsPath, label] = process.argv;
|
||||
const raw = fs.readFileSync(resultsPath, 'utf-8');
|
||||
const data = JSON.parse(raw);
|
||||
|
||||
const lines = [];
|
||||
lines.push(`## ${label || 'Test'} Results`);
|
||||
lines.push('');
|
||||
lines.push('| | Count |');
|
||||
lines.push('|---|---|');
|
||||
lines.push(`| ✅ Passed | ${data.numPassedTests} |`);
|
||||
lines.push(`| ❌ Failed | ${data.numFailedTests} |`);
|
||||
lines.push(`| ⏭️ Skipped | ${data.numPendingTests} |`);
|
||||
lines.push(`| **Total** | **${data.numTotalTests}** |`);
|
||||
lines.push('');
|
||||
|
||||
if (data.numFailedTests > 0) {
|
||||
lines.push('### Failures');
|
||||
lines.push('');
|
||||
for (const suite of data.testResults) {
|
||||
for (const t of suite.testResults) {
|
||||
if (t.status === 'failed') {
|
||||
lines.push(`- **${t.fullName}**`);
|
||||
const msg = t.failureMessages && t.failureMessages[0]
|
||||
? t.failureMessages[0].split('\n')[0]
|
||||
: 'see job log for details';
|
||||
lines.push(` \`${msg}\``);
|
||||
}
|
||||
}
|
||||
}
|
||||
lines.push('');
|
||||
}
|
||||
|
||||
const summaryPath = process.env.GITEA_STEP_SUMMARY || process.env.GITHUB_STEP_SUMMARY;
|
||||
if (summaryPath) {
|
||||
fs.appendFileSync(summaryPath, lines.join('\n') + '\n');
|
||||
} else {
|
||||
console.log(lines.join('\n'));
|
||||
}
|
||||
|
||||
process.exit(data.numFailedTests > 0 ? 1 : 0);
|
||||
Reference in New Issue
Block a user