Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesnetherton committed Apr 29, 2024
1 parent a00d4aa commit badb56f
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions .github/actions/test-summary/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,65 @@ inputs:
runs:
using: "composite"
steps:
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install script dependencies
shell: bash
run: |
npm install junit2json
- name: Generate test summary
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const junit = require('junit2json');
const testReportGlobPattern = "${{ inputs.test-report-xml-base-dir }}/${{ inputs.test-report-xml-includes }}"
const summaryData = [];
summaryData.push([{data: 'Test Class', header: true}, {data: 'Test Name', header: true}, {data: 'Failure', header: true}, {data: 'Details', header: true}]);
// Determine the report heading. Use the base path of where to search for JUnit reports if not test-report-summary-heading is not provided
let testReportHeading = "${{ inputs.test-report-summary-heading }}"
if (!testReportHeading) {
testReportHeading = testReportHeading.replace(/-/g, ' ').replace(/(^\w{1})|(\s+\w{1})/g, wordFirstLetter => wordFirstLetter.toUpperCase());
}
if (!testReportHeading.endsWith(" Test Results")) {
testReportHeading += " Test Results";
}
// Iterate and parse surefire / failsafe reports and use the info to build the summary
const globber = await glob.create(testReportGlobPattern);
for await (const reportFile of globber.globGenerator()) {
const file = fs.readFileSync(reportFile);
const report = junit.parse(file).then((report) => {
if (report.errors > 0 || report.failures > 0) {
report.testcase.forEach((testCase) => {
if (testCase.failure !== undefined) {
const shortClassName = `<code>${testCase.classname.substring(testCase.classname.lastIndexOf('.') + 1)}</code>`;
const className = `<details><summary>${shortClassName}</summary>\n${testCase.classname}</details>`;
const details = `<details><summary>View</summary>\n<code>${testCase.failure[0].inner}</code></details>`;
let testName = `<code><${testCase.name}</code>`;
if (testName.length > 25) {
testName = `<details><summary>View</summary>\n<code><${testCase.name}</code></details>`;
}
let message = `<code>testCase.failure[0].message</code>`;
if (message.length > 50) {
message = `<details><summary>View</summary>\n${message}</details>`;
}
summaryData.push([className, testName, message, details]);
}
});
}
});
}
// Write the summary data if there were test failures
if (summaryData.length > 1) {
await core.summary
.addHeading(testReportHeading)
.addTable(summaryData)
.write();
}

0 comments on commit badb56f

Please sign in to comment.