Skip to content

Commit 0483262

Browse files
Add warning for invalid nunit xml files (#286)
* Allow ResultsParser to fail on non-nunit xml files * yarn build * Add file check for NUnit XML format before parsing * yarn build * Update src/model/results-check.ts Co-authored-by: Koji Hasegawa <[email protected]> --------- Co-authored-by: Koji Hasegawa <[email protected]>
1 parent 05a00ef commit 0483262

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

dist/index.js

Lines changed: 13 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/model/results-check.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,18 @@ const ResultsCheck = {
2222
files.map(async filepath => {
2323
if (!filepath.endsWith('.xml')) return;
2424
core.info(`Processing file ${filepath}...`);
25-
const fileData = await ResultsParser.parseResults(path.join(artifactsPath, filepath));
26-
core.info(fileData.summary);
27-
runs.push(fileData);
25+
try {
26+
const content = fs.readFileSync(path.join(artifactsPath, filepath), 'utf8');
27+
if (!content.includes('<test-run')) {
28+
// noinspection ExceptionCaughtLocallyJS
29+
throw new Error('File does not appear to be a NUnit XML file');
30+
}
31+
const fileData = await ResultsParser.parseResults(path.join(artifactsPath, filepath));
32+
core.info(fileData.summary);
33+
runs.push(fileData);
34+
} catch (error: any) {
35+
core.warning(`Failed to parse ${filepath}: ${error.message}`);
36+
}
2837
}),
2938
);
3039

0 commit comments

Comments
 (0)