From 6aa94371a277f6363ebbbc82af5ea52d072e296d Mon Sep 17 00:00:00 2001 From: Artem Eroshenko Date: Tue, 16 Jul 2024 16:59:43 +0300 Subject: [PATCH] add marathon integration --- .github/workflows/build.yml | 4 ++ .../export/Allure2ExportFormatter.java | 22 +++++++-- .../xcresults/export/ExportCommand.java | 40 +++++++++++++--- .../io/eroshenkoam/xcresults/SimpleTest.java | 46 +++++++++++++++++++ 4 files changed, 100 insertions(+), 12 deletions(-) create mode 100644 src/test/java/io/eroshenkoam/xcresults/SimpleTest.java diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d42807b..2d25c39 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,3 +16,7 @@ jobs: distribution: 'graalvm' - run: ./gradlew build - run: ./gradlew nativeCompile + - uses: actions/upload-artifact@v3 + with: + path: ./build/native/nativeCompile/xcresults + name: xcresults diff --git a/src/main/java/io/eroshenkoam/xcresults/export/Allure2ExportFormatter.java b/src/main/java/io/eroshenkoam/xcresults/export/Allure2ExportFormatter.java index b1bda3e..b6d12af 100644 --- a/src/main/java/io/eroshenkoam/xcresults/export/Allure2ExportFormatter.java +++ b/src/main/java/io/eroshenkoam/xcresults/export/Allure2ExportFormatter.java @@ -29,6 +29,8 @@ public class Allure2ExportFormatter implements ExportFormatter { private static final String IDENTIFIER = "identifier"; + private static final String IDENTIFIER_URL = "identifierURL"; + private static final String DURATION = "duration"; private static final String STATUS = "testStatus"; private static final String FAILURE_SUMMARIES = "failureSummaries"; @@ -74,11 +76,10 @@ public TestResult format(final ExportMeta meta, final JsonNode node) { if (node.has(NAME)) { result.setName(node.get(NAME).get(VALUE).asText()); } - if (node.has(IDENTIFIER)) { - final String identifier = node.get(IDENTIFIER).get(VALUE).asText(); - result.setHistoryId(getHistoryId(meta, identifier)); - result.setFullName(identifier); - } + getFullName(node).ifPresent(fullName -> { + result.setFullName(fullName); + result.setHistoryId(fullName); + }); if (node.has(STATUS)) { result.setStatus(getTestStatus(node)); } @@ -412,6 +413,17 @@ public StepContext child(final ExecutableItem next) { } } + private Optional getFullName(final JsonNode node) { + if (node.has(IDENTIFIER_URL)) { + final String identifier = node.get(IDENTIFIER_URL).get(VALUE).asText(); + return Optional.of(identifier + .replaceFirst("test://com.apple.xcode//", "") + .replace("/", ".") + ); + } + return Optional.empty(); + } + private String getHistoryId(final ExportMeta meta, final String identifier) { final String suite = meta.getLabels().getOrDefault(SUITE, "Default"); return String.format("%s/%s", suite, identifier); diff --git a/src/main/java/io/eroshenkoam/xcresults/export/ExportCommand.java b/src/main/java/io/eroshenkoam/xcresults/export/ExportCommand.java index 912088d..063ad6e 100644 --- a/src/main/java/io/eroshenkoam/xcresults/export/ExportCommand.java +++ b/src/main/java/io/eroshenkoam/xcresults/export/ExportCommand.java @@ -3,11 +3,17 @@ import org.apache.commons.io.FileUtils; import picocli.CommandLine; +import java.io.IOException; +import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; -import java.util.Arrays; +import java.nio.file.PathMatcher; +import java.nio.file.Paths; import java.util.List; import java.util.Objects; +import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.Stream; @CommandLine.Command( name = "export", mixinStandardHelpOptions = true, @@ -36,7 +42,7 @@ public class ExportCommand implements Runnable { @CommandLine.Parameters( description = "The directories with *.xcresults" ) - protected List inputPath; + protected List inputPath; @CommandLine.Option( names = {"-o", "--output"}, @@ -58,7 +64,7 @@ public void run() { FileUtils.deleteDirectory(output.toFile()); } Files.createDirectories(output); - for (Path path: input) { + for (Path path : input) { runUnsafe(path, output); } } catch (Exception e) { @@ -66,7 +72,7 @@ public void run() { } } - private void runUnsafe(final Path input, final Path output) throws Exception { + private void runUnsafe(final Path input, final Path output) throws Exception { System.out.printf("Export xcresults from [%s] to [%s]\n", input, output); final ExportProcessor processor = new ExportProcessor( input, output, addCarouselAttachment, carouselTemplatePath @@ -76,18 +82,38 @@ private void runUnsafe(final Path input, final Path output) throws Exception { private List getInputPaths() { if (inputPath.size() == 2 && Objects.isNull(outputPath)) { - return Arrays.asList(inputPath.get(0)); + return findGlob(inputPath.get(0)); } else { - return inputPath; + return inputPath.stream() + .flatMap(i -> findGlob(i).stream()) + .collect(Collectors.toList()); } } private Path getOutputPath() { if (inputPath.size() == 2 && Objects.isNull(outputPath)) { - return inputPath.get(1); + return Path.of(inputPath.get(1)); } else { return outputPath; } } + private List findGlob(final String input) { + final Path path = Paths.get(input); + if (path.isAbsolute()) { + return List.of(path); + } + final Path workDir = Path.of(Optional.ofNullable(System.getProperty("user.dir")).orElse("")); + final String pattern = String.format("glob:%s", input); + final PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher(pattern); + try (final Stream walk = Files.walk(workDir)) { + return walk.map(workDir::relativize) + .filter(pathMatcher::matches) + .map(workDir::resolve) + .collect(Collectors.toList()); + } catch (IOException e) { + return List.of(); + } + } + } diff --git a/src/test/java/io/eroshenkoam/xcresults/SimpleTest.java b/src/test/java/io/eroshenkoam/xcresults/SimpleTest.java new file mode 100644 index 0000000..cc71c84 --- /dev/null +++ b/src/test/java/io/eroshenkoam/xcresults/SimpleTest.java @@ -0,0 +1,46 @@ +package io.eroshenkoam.xcresults; + +import io.eroshenkoam.xcresults.util.FreemarkerUtil; +import org.junit.Test; + +import picocli.CommandLine; + +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.PathMatcher; +import java.util.Map; +import java.util.stream.Stream; + +public class SimpleTest { + + @Test + public void testCommand() { + System.setProperty("user.dir", "/Users/eroshenkoam/Downloads"); + final CommandLine cmd = new CommandLine(new MainCommand()); + cmd.execute( + "export", + "marathon-uiTests/device-files/omni/*/xcresult/*.xcresult", + "-o", "/Users/eroshenkoam/Downloads/allure-results" + ); + } + + @Test + public void testTempplate() throws Exception { + FreemarkerUtil.render(Path.of("/Users/eroshenkoam/Developer/eroshenkoam/xcresults/src/main/resources/templates/carousel.ftl"), Map.of("ca", "")); + } + + @Test + public void testGlob() throws Exception { + final String dir = "/Users/eroshenkoam/Downloads"; + final String input = "marathon-uiTests/device-files/omni/*/xcresult/*.xcresult"; + +// final String input = "glob:marathon-uiTests/allure-results/*.json"; + final String pattern = String.format("glob:%s", Path.of(input).toAbsolutePath()); + System.out.println(pattern); + final PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher(pattern); + final Stream walk = Files.walk(Path.of(dir)); + walk.filter(pathMatcher::matches).forEach(System.out::println); + } + +}