Skip to content

Commit

Permalink
add marathon integration
Browse files Browse the repository at this point in the history
  • Loading branch information
eroshenkoam committed Jul 16, 2024
1 parent f19db33 commit 6aa9437
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 12 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -412,6 +413,17 @@ public StepContext child(final ExecutableItem next) {
}
}

private Optional<String> 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);
Expand Down
40 changes: 33 additions & 7 deletions src/main/java/io/eroshenkoam/xcresults/export/ExportCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -36,7 +42,7 @@ public class ExportCommand implements Runnable {
@CommandLine.Parameters(
description = "The directories with *.xcresults"
)
protected List<Path> inputPath;
protected List<String> inputPath;

@CommandLine.Option(
names = {"-o", "--output"},
Expand All @@ -58,15 +64,15 @@ public void run() {
FileUtils.deleteDirectory(output.toFile());
}
Files.createDirectories(output);
for (Path path: input) {
for (Path path : input) {
runUnsafe(path, output);
}
} catch (Exception e) {
e.printStackTrace(System.out);
}
}

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
Expand All @@ -76,18 +82,38 @@ private void runUnsafe(final Path input, final Path output) throws Exception {

private List<Path> 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<Path> 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<Path> walk = Files.walk(workDir)) {
return walk.map(workDir::relativize)
.filter(pathMatcher::matches)
.map(workDir::resolve)
.collect(Collectors.toList());
} catch (IOException e) {
return List.of();
}
}

}
46 changes: 46 additions & 0 deletions src/test/java/io/eroshenkoam/xcresults/SimpleTest.java
Original file line number Diff line number Diff line change
@@ -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<Path> walk = Files.walk(Path.of(dir));
walk.filter(pathMatcher::matches).forEach(System.out::println);
}

}

0 comments on commit 6aa9437

Please sign in to comment.