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

Add marathon integration #71

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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();
}
}

}
Loading