-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from quarkus-qe/feature/add-github-pr-commentator
Add JBang script that will crunch Flaky Run reports and create comment that can be printed in GitHub PRs where flakiness occurred
- Loading branch information
Showing
7 changed files
with
216 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,10 +48,11 @@ jobs: | |
git checkout ${{github.base_ref}} | ||
git rebase release | ||
mvn -B release:perform -DskipITs -DskipTests -Prelease,framework -s maven-settings.xml | ||
- name: Bump dependency version used in JBang script to the released version | ||
- name: Bump dependency version used in JBang scripts to the released version | ||
run: | | ||
sed -i "s#DEPS io.quarkus.qe:flaky-run-reporter:.*#DEPS io.quarkus.qe:flaky-run-reporter:${{steps.metadata.outputs.current-version}}#" ./jbang-scripts/FlakyTestRunSummarizer.java | ||
git commit -am "Update JBang script dependency version to ${{steps.metadata.outputs.current-version}}" | ||
sed -i "s#DEPS io.quarkus.qe:flaky-run-reporter:.*#DEPS io.quarkus.qe:flaky-run-reporter:${{steps.metadata.outputs.current-version}}#" ./jbang-scripts/GitHubPrCommentator.java | ||
git commit -am "Update JBang scripts dependency version to ${{steps.metadata.outputs.current-version}}" | ||
- name: Push changes to ${{github.base_ref}} | ||
uses: ad-m/[email protected] | ||
with: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//usr/bin/env jbang "$0" "$@" ; exit $? | ||
|
||
//DEPS io.quarkus.qe:flaky-run-reporter:0.1.2.Beta1 | ||
|
||
import io.quarkus.qe.reporter.flakyrun.commentator.CreateGhPrComment; | ||
|
||
public class GitHubPrCommentator { | ||
public static void main(String... args) { | ||
try { | ||
new CreateGhPrComment(args).printToStdOut(); | ||
System.exit(0); | ||
} catch (Exception e) { | ||
System.exit(1); | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/main/java/io/quarkus/qe/reporter/flakyrun/FlakyReporterUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package io.quarkus.qe.reporter.flakyrun; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
public final class FlakyReporterUtils { | ||
|
||
private static final String EQUALS = "="; | ||
|
||
private FlakyReporterUtils() { | ||
} | ||
|
||
public static boolean isArgument(String argumentKey, String argument) { | ||
return argument.startsWith(argumentKey + EQUALS); | ||
} | ||
|
||
public static int parseIntArgument(String argumentKey, String argument) { | ||
return Integer.parseInt(argument.substring((argumentKey + EQUALS).length())); | ||
} | ||
|
||
public static String parseStringArgument(String argumentKey, String argument) { | ||
return argument.substring((argumentKey + EQUALS).length()); | ||
} | ||
|
||
public static String getRequiredArgument(String argumentKey, String[] arguments) { | ||
String argument = null; | ||
for (String a : arguments) { | ||
if (a != null && isArgument(argumentKey, a)) { | ||
argument = a; | ||
} | ||
} | ||
if (argument == null) { | ||
throw new IllegalArgumentException("Argument '" + argument + "' is missing"); | ||
} | ||
return parseStringArgument(argumentKey, argument); | ||
} | ||
|
||
public static String readFile(Path overviewPath) { | ||
try { | ||
return Files.readString(overviewPath); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public static String[] createCommandArgs(String... args) { | ||
if (args.length % 2 != 0) { | ||
throw new IllegalArgumentException("Args must be even"); | ||
} | ||
String[] result = new String[args.length / 2]; | ||
for (int i = 0; i < result.length; i++) { | ||
int j = i * 2; | ||
result[i] = args[j] + EQUALS + args[j + 1]; | ||
} | ||
return result; | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
src/main/java/io/quarkus/qe/reporter/flakyrun/commentator/CreateGhPrComment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package io.quarkus.qe.reporter.flakyrun.commentator; | ||
|
||
import io.quarkus.qe.reporter.flakyrun.reporter.FlakyRunReporter; | ||
import io.quarkus.qe.reporter.flakyrun.reporter.FlakyTest; | ||
import io.quarkus.qe.reporter.flakyrun.summary.FlakyRunSummaryReporter; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
import static io.quarkus.qe.reporter.flakyrun.FlakyReporterUtils.getRequiredArgument; | ||
import static io.quarkus.qe.reporter.flakyrun.FlakyReporterUtils.readFile; | ||
|
||
/** | ||
* This class is used by a Jbang script to simplify commenting in GitHub PRs when a flake were detected. | ||
*/ | ||
public final class CreateGhPrComment { | ||
|
||
public static final String TEST_BASE_DIR = CreateGhPrComment.class.getSimpleName() + ".test-base-dir"; | ||
public static final String OVERVIEW_FILE_KEY = "overview-file"; | ||
public static final String FLAKY_REPORTS_FILE_PREFIX_KEY = "flaky-reports-file-prefix"; | ||
private static final Path CURRENT_DIR = Path.of("."); | ||
private final String comment; | ||
private final Path baseDir; | ||
|
||
public CreateGhPrComment(String[] args) { | ||
if (System.getProperty(TEST_BASE_DIR) != null) { | ||
baseDir = Path.of(System.getProperty(TEST_BASE_DIR)); | ||
} else { | ||
baseDir = CURRENT_DIR; | ||
} | ||
var failureOverview = getFailureOverview(args); | ||
var flakyTestsReports = getFlakyTestReports(args); | ||
this.comment = """ | ||
Following jobs contain at least one flaky test: %s | ||
%s | ||
""".formatted(failureOverview, flakyTestsReports); | ||
} | ||
|
||
public String getComment() { | ||
return comment; | ||
} | ||
|
||
public void printToStdOut() { | ||
System.out.println(comment); | ||
} | ||
|
||
private String getFlakyTestReports(String[] args) { | ||
var reportFilePrefix = getRequiredArgument(FLAKY_REPORTS_FILE_PREFIX_KEY, args); | ||
var listOfDirFiles = baseDir.toFile().listFiles(); | ||
if (listOfDirFiles == null || listOfDirFiles.length == 0) { | ||
return "No flaky test reports found"; | ||
} | ||
var result = new StringBuilder(); | ||
for (File file : listOfDirFiles) { | ||
if (file.getName().startsWith(reportFilePrefix)) { | ||
var flakyTests = FlakyRunReporter.parseFlakyTestsReport(file.toPath()); | ||
if (!flakyTests.isEmpty()) { | ||
result.append("**Artifact `%s` contains following failures:**".formatted(file.getName())); | ||
for (FlakyTest flakyTest : flakyTests) { | ||
result.append(""" | ||
- Test name: `%s` | ||
Date and time: %s | ||
Failure message: `%s` | ||
Failure stacktrace: | ||
``` | ||
%s | ||
``` | ||
""".formatted(flakyTest.fullTestName(), flakyTest.dateTime(), | ||
flakyTest.failureMessage(), flakyTest.failureStackTrace())); | ||
} | ||
result.append(System.lineSeparator()); | ||
} | ||
} | ||
} | ||
return result.toString(); | ||
} | ||
|
||
private String getFailureOverview(String[] args) { | ||
var overviewPath = baseDir.resolve(getRequiredArgument(OVERVIEW_FILE_KEY, args)); | ||
if (Files.exists(overviewPath)) { | ||
return readFile(overviewPath); | ||
} | ||
throw new IllegalStateException("File '" + overviewPath + "' not found"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
'PR - Linux - JVM build - Latest Version', 'PR - Linux - Native build - Latest Version', 'PR - Windows - JVM build - Latest Version' |