Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop build-reporter dependency #9

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
# Quarkus QE Flaky Run Reporter
This is Maven extensions that accepts build reporter generated by the https://github.com/quarkusio/build-reporter and SureFire / FailSafe reports and creates flaky run reports.
This is Maven extensions that accepts SureFire / FailSafe reports and creates flaky run reports.

## Generate flaky run report
Add Maven extension to your POM file:

```xml
<build>
<extensions>
<extension>
<groupId>io.quarkus.bot</groupId>
<artifactId>build-reporter-maven-extension</artifactId>
<version>${build-reporter-maven-extension.version}</version>
</extension>
<extension>
<groupId>io.quarkus.qe</groupId>
<artifactId>flaky-run-reporter</artifactId>
Expand Down
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<build-reporter-maven-extension.version>3.4.4</build-reporter-maven-extension.version>
<maven-core.version>3.9.6</maven-core.version>
<maven-surefire-report-parser.version>3.2.5</maven-surefire-report-parser.version>
<plexus-containers.version>2.2.0</plexus-containers.version>
Expand All @@ -24,11 +23,6 @@
</properties>

<dependencies>
<dependency>
<groupId>io.quarkus.bot</groupId>
<artifactId>build-reporter-maven-extension-model</artifactId>
<version>${build-reporter-maven-extension.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package io.quarkus.qe.reporter.flakyrun.mavenextension;

import io.quarkus.qe.reporter.flakyrun.reporter.FlakyRunReporter;
import io.quarkus.qe.reporter.flakyrun.reporter.Project;
import org.apache.maven.AbstractMavenLifecycleParticipant;
import org.apache.maven.execution.MavenSession;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger;

import java.nio.file.Path;
import java.util.List;

@Component(role = AbstractMavenLifecycleParticipant.class, hint = "quarkus-qe-flaky-run-reporter")
public class FlakyRunReportingMavenExtension extends AbstractMavenLifecycleParticipant {

Expand All @@ -15,6 +19,16 @@ public class FlakyRunReportingMavenExtension extends AbstractMavenLifecycleParti

@Override
public void afterSessionEnd(MavenSession session) {
new FlakyRunReporter(logger).createFlakyRunReport();
var projects = getProjectsFromMvnSession(session);
if (!projects.isEmpty()) {
new FlakyRunReporter(logger).createReport(projects);
}
}

private static List<Project> getProjectsFromMvnSession(MavenSession session) {
final Path rootPath = Path.of("").toAbsolutePath();
return session.getResult().getTopologicallySortedProjects().stream()
.map(p -> new Project(p.getName(), rootPath.relativize(p.getBasedir().toPath())))
.filter(p -> !p.baseDir().toString().isEmpty()).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import io.quarkus.bot.build.reporting.model.BuildReport;
import io.quarkus.bot.build.reporting.model.ProjectReport;
import org.apache.maven.plugin.surefire.log.api.NullConsoleLogger;
import org.apache.maven.plugins.surefire.report.ReportTestCase;
import org.apache.maven.plugins.surefire.report.ReportTestSuite;
Expand All @@ -23,7 +21,6 @@
public class FlakyRunReporter {
public static final String FLAKY_RUN_REPORT = "flaky-run-report.json";
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
private static final String BUILD_REPORT_JSON_FILENAME = "build-report.json";
private static final String TARGET_DIR = "target";
private static final Path MAVEN_SUREFIRE_REPORTS_PATH = Path.of(TARGET_DIR, "surefire-reports");
private static final Path MAVEN_FAILSAFE_REPORTS_PATH = Path.of(TARGET_DIR, "failsafe-reports");
Expand All @@ -45,13 +42,12 @@ public static List<FlakyTest> parseFlakyTestsReport(Path reportPath) {
}
}

public void createFlakyRunReport() {
createFlakyRunReport(buildReportToFlakyTests(getBuildReporter()));
public void createReport(List<Project> projects) {
createFlakyRunReport(projectsToFlakyTests(projects));
}

private static List<FlakyTest> buildReportToFlakyTests(BuildReport buildReport) {
return buildReport.getProjectReports().stream()
.flatMap(projectReport -> testDirsToFlakyTests(toTestDirs(projectReport), projectReport)).toList();
private static List<FlakyTest> projectsToFlakyTests(List<Project> projects) {
return projects.stream().flatMap(project -> testDirsToFlakyTests(toTestDirs(project), project)).toList();
}

private void createFlakyRunReport(List<FlakyTest> flakyTests) {
Expand All @@ -64,36 +60,18 @@ private void createFlakyRunReport(List<FlakyTest> flakyTests) {
}
}

private static BuildReport getBuildReporter() {
var buildReportPath = Path.of(TARGET_DIR).resolve(BUILD_REPORT_JSON_FILENAME);
if (Files.exists(buildReportPath)) {
try {
return OBJECT_MAPPER.readValue(buildReportPath.toFile(), BuildReport.class);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return new BuildReport();
}

private static List<File> toTestDirs(ProjectReport projectReport) {
return Stream
.of(Path.of(normalizeModuleName(projectReport.getBasedir()))).flatMap(baseDir -> Stream
.of(baseDir.resolve(MAVEN_FAILSAFE_REPORTS_PATH), baseDir.resolve(MAVEN_SUREFIRE_REPORTS_PATH)))
.filter(Files::exists).map(Path::toFile).toList();
private static List<File> toTestDirs(Project project) {
return Stream.of(project.baseDir()).flatMap(baseDir -> Stream.of(baseDir.resolve(MAVEN_FAILSAFE_REPORTS_PATH),
baseDir.resolve(MAVEN_SUREFIRE_REPORTS_PATH))).filter(Files::exists).map(Path::toFile).toList();
}

private static Stream<FlakyTest> testDirsToFlakyTests(List<File> testDirs, ProjectReport projectReport) {
private static Stream<FlakyTest> testDirsToFlakyTests(List<File> testDirs, Project project) {
if (testDirs.isEmpty()) {
return Stream.empty();
}
return new SurefireReportParser(testDirs, new NullConsoleLogger()).parseXMLReportFiles().stream()
.filter(r -> r.getNumberOfFlakes() > 0).map(ReportTestSuite::getTestCases).flatMap(Collection::stream)
.filter(ReportTestCase::hasFlakes)
.flatMap(reportTestCase -> FlakyTest.newInstances(reportTestCase, projectReport));
}

private static String normalizeModuleName(String moduleName) {
return moduleName.replace('\\', '/');
.flatMap(reportTestCase -> FlakyTest.newInstances(reportTestCase, project));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.quarkus.qe.reporter.flakyrun.reporter;

import io.quarkus.bot.build.reporting.model.ProjectReport;
import org.apache.maven.plugins.surefire.report.ReportTestCase;

import java.time.ZonedDateTime;
Expand All @@ -9,18 +8,18 @@
public record FlakyTest(String projectName, String projectBaseDir, String fullTestName, String failureMessage,
String failureType, String failureStackTrace, String dateTime) {

static Stream<FlakyTest> newInstances(ReportTestCase reportTestCase, ProjectReport projectReport) {
static Stream<FlakyTest> newInstances(ReportTestCase reportTestCase, Project project) {
final String now = ZonedDateTime.now().toString();
Stream<FlakyTest> result = Stream.empty();
if (!reportTestCase.getFlakyFailures().isEmpty()) {
result = reportTestCase.getFlakyFailures().stream()
.map(s -> new FlakyTest(projectReport.getName(), projectReport.getBasedir(),
reportTestCase.getFullName(), s.getMessage(), s.getType(), s.getStackTrace(), now));
.map(s -> new FlakyTest(project.name(), project.baseDir().toString(), reportTestCase.getFullName(),
s.getMessage(), s.getType(), s.getStackTrace(), now));
}
if (!reportTestCase.getFlakyErrors().isEmpty()) {
result = Stream.concat(result,
reportTestCase.getFlakyErrors().stream()
.map(s -> new FlakyTest(projectReport.getName(), projectReport.getBasedir(),
.map(s -> new FlakyTest(project.name(), project.baseDir().toString(),
reportTestCase.getFullName(), s.getMessage(), s.getType(), s.getStackTrace(),
now)));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.quarkus.qe.reporter.flakyrun.reporter;

import java.nio.file.Path;

public record Project(String name, Path baseDir) {
}
Loading