Skip to content

Commit

Permalink
Add warning for invalid nunit xml files (#286)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
GabLeRoux and nowsprinting authored Nov 8, 2024
1 parent 05a00ef commit 0483262
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
16 changes: 13 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions src/model/results-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,18 @@ const ResultsCheck = {
files.map(async filepath => {
if (!filepath.endsWith('.xml')) return;
core.info(`Processing file ${filepath}...`);
const fileData = await ResultsParser.parseResults(path.join(artifactsPath, filepath));
core.info(fileData.summary);
runs.push(fileData);
try {
const content = fs.readFileSync(path.join(artifactsPath, filepath), 'utf8');
if (!content.includes('<test-run')) {
// noinspection ExceptionCaughtLocallyJS
throw new Error('File does not appear to be a NUnit XML file');
}
const fileData = await ResultsParser.parseResults(path.join(artifactsPath, filepath));
core.info(fileData.summary);
runs.push(fileData);
} catch (error: any) {
core.warning(`Failed to parse ${filepath}: ${error.message}`);
}
}),
);

Expand Down

0 comments on commit 0483262

Please sign in to comment.