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 <hasegawa@nowsprinting.com>

---------

Co-authored-by: Koji Hasegawa <hasegawa@nowsprinting.com>
pull/282/head^2
Gabriel Le Breton 2024-11-08 17:43:21 -05:00 committed by GitHub
parent 05a00ef5ac
commit 0483262850
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 7 deletions

16
dist/index.js generated vendored
View File

@ -1014,9 +1014,19 @@ const ResultsCheck = {
if (!filepath.endsWith('.xml'))
return;
core.info(`Processing file ${filepath}...`);
const fileData = yield results_parser_1.default.parseResults(path_1.default.join(artifactsPath, filepath));
core.info(fileData.summary);
runs.push(fileData);
try {
const content = fs.readFileSync(path_1.default.join(artifactsPath, filepath), 'utf8');
if (!content.includes('<test-results') && !content.includes('<test-run')) {
// noinspection ExceptionCaughtLocallyJS
throw new Error('File does not appear to be a NUnit XML file');
}
const fileData = yield results_parser_1.default.parseResults(path_1.default.join(artifactsPath, filepath));
core.info(fileData.summary);
runs.push(fileData);
}
catch (error) {
core.warning(`Failed to parse ${filepath}: ${error.message}`);
}
})));
// Combine all results into a single run summary
const runSummary = new results_meta_1.RunMeta(checkName);

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -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}`);
}
}),
);