Skip to content

Commit

Permalink
GH-184: ignore incompatible XML reports (#198)
Browse files Browse the repository at this point in the history
Fixes #184

Ignore files that don't have testsuites
Reorganize the folders
  • Loading branch information
ghaiszaher authored Jan 15, 2024
1 parent a27556b commit 687f107
Show file tree
Hide file tree
Showing 31 changed files with 109 additions and 73 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,33 @@ jobs:
java-version: 8
distribution: 'temurin'
cache: 'maven'
- run: cd tests && mvn clean test --batch-mode -Dmaven.test.failure.ignore=true
- run: cd integration-tests/maven && mvn clean verify --batch-mode -Dmaven.test.failure.ignore=true
- uses: ./
if: github.ref != 'refs/heads/master'
with:
check_name: Example Surefire Test Report
report_paths: '**/surefire-reports/*.xml, **/failsafe-reports/*.xml'
- uses: cclauss/GitHub-Action-for-pytest@0.5.0
with:
args: pytest --junit-xml=python/report.xml python/ || exit 0
args: pytest integration-tests/python/ --junit-xml=integration-tests/python/report.xml || exit 0
- uses: ./
if: github.ref != 'refs/heads/master'
with:
check_name: Example Pytest Report
report_paths: python/report.xml
report_paths: integration-tests/python/report.xml
- uses: actions/setup-go@v5
with:
go-version: 1.18.x
go-version: 1.21.x
- run: |
cd go &&
cd integration-tests/go &&
go install github.com/jstemmer/go-junit-report/v2@latest &&
go test -v 2>&1 ./... |
go-junit-report -out report.xml
- uses: ./
if: github.ref != 'refs/heads/master'
with:
check_name: Example Go Report
report_paths: go/report.xml
report_paths: integration-tests/go/report.xml
file_name_in_stack_trace: true
- uses: actions/setup-node@v4
with:
Expand Down
24 changes: 12 additions & 12 deletions action.test.fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const finishedWithFailures = {
annotations: [
{
path:
'tests/email/src/test/java/action/surefire/report/email/EmailAddressTest.java',
'integration-tests/maven/email/src/test/java/action/surefire/report/email/EmailAddressTest.java',
start_line: 39,
end_line: 39,
start_column: 0,
Expand All @@ -22,7 +22,7 @@ const finishedWithFailures = {
},
{
path:
'tests/email/src/test/java/action/surefire/report/email/EmailAddressTest.java',
'integration-tests/maven/email/src/test/java/action/surefire/report/email/EmailAddressTest.java',
start_line: 49,
end_line: 49,
start_column: 0,
Expand All @@ -35,7 +35,7 @@ const finishedWithFailures = {
},
{
path:
'tests/email/src/test/java/action/surefire/report/email/EmailAddressTest.java',
'integration-tests/maven/email/src/test/java/action/surefire/report/email/EmailAddressTest.java',
start_line: 57,
end_line: 57,
start_column: 0,
Expand All @@ -48,7 +48,7 @@ const finishedWithFailures = {
},
{
path:
'tests/email/src/test/java/action/surefire/report/email/EmailAddressTest.java',
'integration-tests/maven/email/src/test/java/action/surefire/report/email/EmailAddressTest.java',
start_line: 18,
end_line: 18,
start_column: 0,
Expand All @@ -61,7 +61,7 @@ const finishedWithFailures = {
},
{
path:
'tests/email/src/test/java/action/surefire/report/email/EmailAddressTest.java',
'integration-tests/maven/email/src/test/java/action/surefire/report/email/EmailAddressTest.java',
start_line: 32,
end_line: 32,
start_column: 0,
Expand All @@ -74,7 +74,7 @@ const finishedWithFailures = {
},
{
path:
'tests/email/src/test/java/action/surefire/report/email/EmailAddressTest.java',
'integration-tests/maven/email/src/test/java/action/surefire/report/email/EmailAddressTest.java',
start_line: 25,
end_line: 25,
start_column: 0,
Expand All @@ -88,7 +88,7 @@ const finishedWithFailures = {
},
{
path:
'tests/email/src/test/java/action/surefire/report/email/EmailAddressTest.java',
'integration-tests/maven/email/src/test/java/action/surefire/report/email/EmailAddressTest.java',
start_line: 66,
end_line: 66,
start_column: 0,
Expand All @@ -101,7 +101,7 @@ const finishedWithFailures = {
},
{
path:
'tests/evil_twins/src/test/java/action/surefire/report/twin/second/TwinTest.java',
'integration-tests/maven/evil_twins/src/test/java/action/surefire/report/twin/second/TwinTest.java',
start_line: 13,
end_line: 13,
start_column: 0,
Expand All @@ -113,7 +113,7 @@ const finishedWithFailures = {
"java.lang.AssertionError: \n\nExpected: \"Good Twin\"\n but: was \"Evil Twin\"\n\tat action.surefire.report.twin.second.TwinTest.should_always_fail(TwinTest.java:13)"
},
{
path: 'tests/utils/src/test/java/action/surefire/report/calc/CalcUtilsTest.kt',
path: 'integration-tests/maven/utils/src/test/java/action/surefire/report/calc/CalcUtilsTest.kt',
start_line: 27,
end_line: 27,
start_column: 0,
Expand All @@ -126,7 +126,7 @@ const finishedWithFailures = {
'java.lang.AssertionError: unexpected exception type thrown; expected:<java.lang.IllegalStateException> but was:<java.lang.IllegalArgumentException>\n\tat action.surefire.report.calc.CalcUtilsTest.test error handling(CalcUtilsTest.kt:27)\nCaused by: java.lang.IllegalArgumentException: Amount must have max 2 non-zero decimal places\n\tat action.surefire.report.calc.CalcUtilsTest.scale(CalcUtilsTest.kt:31)\n\tat action.surefire.report.calc.CalcUtilsTest.access$scale(CalcUtilsTest.kt:9)\n\tat action.surefire.report.calc.CalcUtilsTest.test error handling(CalcUtilsTest.kt:27)'
},
{
path: 'tests/utils/src/test/java/action/surefire/report/calc/CalcUtilsTest.kt',
path: 'integration-tests/maven/utils/src/test/java/action/surefire/report/calc/CalcUtilsTest.kt',
start_line: 15,
end_line: 15,
start_column: 0,
Expand All @@ -138,7 +138,7 @@ const finishedWithFailures = {
'java.lang.AssertionError: \n\nExpected: <100.10>\n but: was <100.11>\n\tat action.surefire.report.calc.CalcUtilsTest.test scale(CalcUtilsTest.kt:15)'
},
{
path: 'tests/utils/src/test/java/action/surefire/report/calc/StringUtilsTest.java',
path: 'integration-tests/maven/utils/src/test/java/action/surefire/report/calc/StringUtilsTest.java',
start_line: 27,
end_line: 27,
start_column: 0,
Expand All @@ -151,7 +151,7 @@ const finishedWithFailures = {
'java.lang.AssertionError: \n\nExpected: (an instance of java.lang.IllegalArgumentException and exception with message a string containing "This is unexpected")\n but: exception with message a string containing "This is unexpected" message was "Input=\'\' didn\'t match condition."\nStacktrace was: java.lang.IllegalArgumentException: Input=\'\' didn\'t match condition.\n\tat action.surefire.report.calc.StringUtils.requireNotBlank(StringUtils.java:25)\n\tat action.surefire.report.calc.StringUtils.requireNotBlank(StringUtils.java:18)\n\tat action.surefire.report.calc.StringUtilsTest.require_fail(StringUtilsTest.java:27)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n\tat java.lang.reflect.Method.invoke(Method.java:498)\n\tat org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)\n\tat org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)\n\tat org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)\n\tat org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)\n\tat org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:258)\n\tat org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)\n\tat org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)\n\tat org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)\n\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)\n\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)\n\tat org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)\n\tat org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)\n\tat org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)\n\tat org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)\n\tat org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)\n\tat org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)\n\tat org.junit.runners.ParentRunner.run(ParentRunner.java:413)\n\tat org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:365)\n\tat org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:273)\n\tat org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:238)\n\tat org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:159)\n\tat org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:384)\n\tat org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:345)\n\tat org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:126)\n\tat org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:418)'
},
{
path: 'tests/utils/src/test/java/action/surefire/report/calc/StringUtilsTest.java',
path: 'integration-tests/maven/utils/src/test/java/action/surefire/report/calc/StringUtilsTest.java',
start_line: 20,
end_line: 20,
start_column: 0,
Expand Down
46 changes: 29 additions & 17 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ class OidcClient {
.catch(error => {
throw new Error(`Failed to get ID Token. \n
Error Code : ${error.statusCode}\n
Error Message: ${error.result.message}`);
Error Message: ${error.message}`);
});
const id_token = (_a = res.result) === null || _a === void 0 ? void 0 : _a.value;
if (!id_token) {
Expand Down Expand Up @@ -19994,24 +19994,24 @@ const resolveFileAndLine = (file, classname, output, isFilenameInOutput) => {
let filenameWithPackage;
if (isFilenameInOutput) {
filename = output.split(':')[0].trim();
filenameWithPackage = filename
filenameWithPackage = filename;
} else {
filename = file ? file : classname.split('.').slice(-1)[0].split('(')[0];
filenameWithPackage = classname.replace(/\./g, "/");
filenameWithPackage = classname.replace(/\./g, '/');
}
const matches = output.match(new RegExp(`${filename}.*?:\\d+`, 'g'));
if (!matches) return { filename: filename, filenameWithPackage: filenameWithPackage, line: 1 };
if (!matches) return {filename: filename, filenameWithPackage: filenameWithPackage, line: 1};

const [lastItem] = matches.slice(-1);
const [, line] = lastItem.split(':');
core.debug(`Resolved file ${filenameWithPackage} with name ${filename} and line ${line}`);

return { filename, filenameWithPackage, line: parseInt(line) };
return {filename, filenameWithPackage, line: parseInt(line)};
};

const resolvePath = async filenameWithPackage => {
core.debug(`Resolving path for ${filenameWithPackage}`);
const globber = await glob.create([`**/${filenameWithPackage}.*`, `**/${filenameWithPackage}`].join('\n'), { followSymbolicLinks: false });
const globber = await glob.create([`**/${filenameWithPackage}.*`, `**/${filenameWithPackage}`].join('\n'), {followSymbolicLinks: false});
const results = await globber.glob();
core.debug(`Matched files: ${results}`);
const searchPath = globber.getSearchPaths()[0];
Expand All @@ -20034,6 +20034,19 @@ const resolvePath = async filenameWithPackage => {
return canonicalPath;
};

function getTestsuites(report) {
if (report.testsuite) {
return [report.testsuite];
}
if (!report.testsuites || !report.testsuites.testsuite) {
return [];
}
if (Array.isArray(report.testsuites.testsuite)) {
return report.testsuites.testsuite;
}
return [report.testsuites.testsuite];
}

async function parseFile(file, isFilenameInStackTrace) {
core.debug(`Parsing file ${file}`);
let count = 0;
Expand All @@ -20042,12 +20055,11 @@ async function parseFile(file, isFilenameInStackTrace) {

const data = await fs.promises.readFile(file);

const report = JSON.parse(parser.xml2json(data, { compact: true }));
const testsuites = report.testsuite
? [report.testsuite]
: Array.isArray(report.testsuites.testsuite)
? report.testsuites.testsuite
: [report.testsuites.testsuite];
const report = JSON.parse(parser.xml2json(data, {compact: true}));
core.debug(`parsed report: ${JSON.stringify(report)}`);

const testsuites = getTestsuites(report);
core.debug(`test suites: ${JSON.stringify(testsuites)}`);

for (const testsuite of testsuites) {
const testcases = Array.isArray(testsuite.testcase)
Expand Down Expand Up @@ -20084,7 +20096,7 @@ async function parseFile(file, isFilenameInStackTrace) {
testcase._attributes.name
).trim();

const { filename, filenameWithPackage, line } = resolveFileAndLine(
const {filename, filenameWithPackage, line} = resolveFileAndLine(
testcase._attributes.file,
testcase._attributes.classname,
stackTrace,
Expand All @@ -20109,22 +20121,22 @@ async function parseFile(file, isFilenameInStackTrace) {
}
}
}
return { count, skipped, annotations };
return {count, skipped, annotations};
}

const parseTestReports = async (reportPaths, isFilenameInStackTrace) => {
const globber = await glob.create(reportPaths, { followSymbolicLinks: false });
const globber = await glob.create(reportPaths, {followSymbolicLinks: false});
let annotations = [];
let count = 0;
let skipped = 0;
for await (const file of globber.globGenerator()) {
const { count: c, skipped: s, annotations: a } = await parseFile(file, isFilenameInStackTrace);
const {count: c, skipped: s, annotations: a} = await parseFile(file, isFilenameInStackTrace);
if (c === 0) continue;
count += c;
skipped += s;
annotations = annotations.concat(a);
}
return { count, skipped, annotations };
return {count, skipped, annotations};
};

module.exports = { resolveFileAndLine, resolvePath, parseFile, parseTestReports };
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions tests/pom.xml → integration-tests/maven/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ public void require_withNullMsg() {
thrown.expectMessage("Input='' didn't match condition.");
StringUtils.requireNotBlank("");
}
}
}
File renamed without changes.
File renamed without changes.
Binary file not shown.
Loading

0 comments on commit 687f107

Please sign in to comment.