From 80f4b133c449e5b255e35bd0d45223366d2c1bc1 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Wed, 18 Oct 2023 13:37:41 +0200 Subject: [PATCH] Avoid duplicates and make sure tests are sorted by name --- .../BuildReporterEventHandler.java | 10 +++ .../githubactions/BuildReports.java | 61 +++++++++++++++++++ .../githubactions/BuildReportsUnarchiver.java | 4 +- .../githubactions/WorkflowRunAnalyzer.java | 10 +-- .../report/WorkflowReportTestCase.java | 22 ++++++- 5 files changed, 100 insertions(+), 7 deletions(-) diff --git a/build-reporter-github-actions/src/main/java/io/quarkus/bot/buildreporter/githubactions/BuildReporterEventHandler.java b/build-reporter-github-actions/src/main/java/io/quarkus/bot/buildreporter/githubactions/BuildReporterEventHandler.java index c44e830..022aba7 100644 --- a/build-reporter-github-actions/src/main/java/io/quarkus/bot/buildreporter/githubactions/BuildReporterEventHandler.java +++ b/build-reporter-github-actions/src/main/java/io/quarkus/bot/buildreporter/githubactions/BuildReporterEventHandler.java @@ -8,9 +8,11 @@ import java.util.Collections; import java.util.Comparator; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; @@ -301,7 +303,13 @@ private Map> downloadBuildReports(WorkflowContext .sorted((a1, a2) -> a1.getName().compareTo(a2.getName())) .collect(Collectors.toList()); + Set alreadyHandledArtifacts = new HashSet<>(); + for (GHArtifact artifact : buildReportsArtifacts) { + if (alreadyHandledArtifacts.contains(artifact.getName())) { + continue; + } + Path jobDirectory = allBuildReportsDirectory.resolve(artifact.getName()); Optional buildReportsOptional = buildReportsUnarchiver.getBuildReports(workflowContext, @@ -309,6 +317,8 @@ private Map> downloadBuildReports(WorkflowContext buildReportsMap.put(artifact.getName().replace(WorkflowConstants.BUILD_REPORTS_ARTIFACT_PREFIX, ""), buildReportsOptional); + + alreadyHandledArtifacts.add(artifact.getName()); } return buildReportsMap; diff --git a/build-reporter-github-actions/src/main/java/io/quarkus/bot/buildreporter/githubactions/BuildReports.java b/build-reporter-github-actions/src/main/java/io/quarkus/bot/buildreporter/githubactions/BuildReports.java index 3dfe83c..df731bc 100644 --- a/build-reporter-github-actions/src/main/java/io/quarkus/bot/buildreporter/githubactions/BuildReports.java +++ b/build-reporter-github-actions/src/main/java/io/quarkus/bot/buildreporter/githubactions/BuildReports.java @@ -2,6 +2,7 @@ import java.nio.file.Path; import java.util.Collections; +import java.util.Objects; import java.util.Set; import java.util.TreeSet; @@ -99,6 +100,26 @@ public String getModuleName(Path jobDirectory) { public int compareTo(TestResultsPath o) { return path.compareTo(o.getPath()); } + + @Override + public int hashCode() { + return Objects.hash(path); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + SurefireTestResultsPath other = (SurefireTestResultsPath) obj; + return Objects.equals(path, other.path); + } } static class FailsafeTestResultsPath implements TestResultsPath { @@ -123,6 +144,26 @@ public String getModuleName(Path jobDirectory) { public int compareTo(TestResultsPath o) { return path.compareTo(o.getPath()); } + + @Override + public int hashCode() { + return Objects.hash(path); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + FailsafeTestResultsPath other = (FailsafeTestResultsPath) obj; + return Objects.equals(path, other.path); + } } static class GradleTestResultsPath implements TestResultsPath { @@ -147,5 +188,25 @@ public String getModuleName(Path jobDirectory) { public int compareTo(TestResultsPath o) { return path.compareTo(o.getPath()); } + + @Override + public int hashCode() { + return Objects.hash(path); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + GradleTestResultsPath other = (GradleTestResultsPath) obj; + return Objects.equals(path, other.path); + } } } \ No newline at end of file diff --git a/build-reporter-github-actions/src/main/java/io/quarkus/bot/buildreporter/githubactions/BuildReportsUnarchiver.java b/build-reporter-github-actions/src/main/java/io/quarkus/bot/buildreporter/githubactions/BuildReportsUnarchiver.java index 06a6a64..31da34a 100644 --- a/build-reporter-github-actions/src/main/java/io/quarkus/bot/buildreporter/githubactions/BuildReportsUnarchiver.java +++ b/build-reporter-github-actions/src/main/java/io/quarkus/bot/buildreporter/githubactions/BuildReportsUnarchiver.java @@ -39,7 +39,7 @@ public Optional getBuildReports(WorkflowContext workflowContext, Awaitility.await() .atMost(Duration.ofMinutes(5)) .pollDelay(Duration.ofSeconds(5)) - .pollInterval(Duration.ofSeconds(30)) + .pollInterval(Duration.ofSeconds(60)) .until(artifactIsDownloaded); } catch (ConditionTimeoutException e) { LOG.warn(workflowContext.getLogContext() @@ -73,7 +73,7 @@ public Boolean call() { try { retry++; buildReports = buildReportsArtifact - .download((is) -> unzip(is, jobDirectory)); + .download((is) -> unzip(is, jobDirectory.resolve("retry-" + retry))); return true; } catch (Exception e) { LOG.error(workflowContext.getLogContext() + " - Unable to download artifact " diff --git a/build-reporter-github-actions/src/main/java/io/quarkus/bot/buildreporter/githubactions/WorkflowRunAnalyzer.java b/build-reporter-github-actions/src/main/java/io/quarkus/bot/buildreporter/githubactions/WorkflowRunAnalyzer.java index 2a17a3f..00d37fc 100644 --- a/build-reporter-github-actions/src/main/java/io/quarkus/bot/buildreporter/githubactions/WorkflowRunAnalyzer.java +++ b/build-reporter-github-actions/src/main/java/io/quarkus/bot/buildreporter/githubactions/WorkflowRunAnalyzer.java @@ -189,6 +189,8 @@ private List getModules( } } + Collections.sort(workflowReportTestCases); + WorkflowReportModule module = new WorkflowReportModule( moduleName, moduleReports.getProjectReport(), @@ -219,7 +221,7 @@ private static Map mapModuleReports(BuildReport buildRepo buildReport.getProjectReports().stream().filter(pr -> normalizeModuleName(pr.getBasedir()).equals(module)) .findFirst().orElse(null), testResultsPaths.stream().filter(trp -> normalizeModuleName(trp.getModuleName(jobDirectory)).equals(module)) - .collect(Collectors.toList()))); + .collect(Collectors.toCollection(TreeSet::new)))); } return moduleReports; @@ -280,9 +282,9 @@ private static String firstLines(String string, int numberOfLines) { private static class ModuleReports { private final ProjectReport projectReport; - private final List testResultsPaths; + private final Set testResultsPaths; - private ModuleReports(ProjectReport projectReport, List testResultsPaths) { + private ModuleReports(ProjectReport projectReport, Set testResultsPaths) { this.projectReport = projectReport; this.testResultsPaths = testResultsPaths; } @@ -291,7 +293,7 @@ public ProjectReport getProjectReport() { return projectReport; } - public List getTestResultsPaths() { + public Set getTestResultsPaths() { return testResultsPaths; } } diff --git a/build-reporter-github-actions/src/main/java/io/quarkus/bot/buildreporter/githubactions/report/WorkflowReportTestCase.java b/build-reporter-github-actions/src/main/java/io/quarkus/bot/buildreporter/githubactions/report/WorkflowReportTestCase.java index 2c5ec99..2a888c8 100644 --- a/build-reporter-github-actions/src/main/java/io/quarkus/bot/buildreporter/githubactions/report/WorkflowReportTestCase.java +++ b/build-reporter-github-actions/src/main/java/io/quarkus/bot/buildreporter/githubactions/report/WorkflowReportTestCase.java @@ -5,7 +5,7 @@ import io.quarkus.runtime.annotations.RegisterForReflection; @RegisterForReflection -public class WorkflowReportTestCase { +public class WorkflowReportTestCase implements Comparable { private final String classPath; private final String fullName; @@ -66,4 +66,24 @@ public String getFailureUrl() { public String getShortenedFailureUrl() { return shortenedFailureUrl; } + + @Override + public int compareTo(WorkflowReportTestCase o) { + int compare = this.fullName.compareTo(o.fullName); + + if (compare != 0 || + this.failureErrorLine == null || this.failureErrorLine.isBlank() || + o.failureErrorLine == null || o.failureErrorLine.isBlank()) { + return compare; + } + + try { + Integer thisLine = Integer.valueOf(this.failureErrorLine); + Integer otherLine = Integer.valueOf(o.failureErrorLine); + + return thisLine.compareTo(otherLine); + } catch (NumberFormatException e) { + return compare; + } + } } \ No newline at end of file