Skip to content

Commit 209bf1b

Browse files
authored
Reenable windows upload and fix archive paths (#130577)
When windows builds fail, we need the local logs for diagnosing the issue. This commit re-enables archiving the log files from windows builds for upload. It also fixes that archive to use the correct tar entry path separator on windows. relates #115449
1 parent f3cc0d9 commit 209bf1b

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchBuildCompletePlugin.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,12 @@
3838
import java.io.FileNotFoundException;
3939
import java.io.IOException;
4040
import java.io.OutputStream;
41+
import java.io.UncheckedIOException;
42+
import java.nio.file.FileVisitResult;
4143
import java.nio.file.Files;
4244
import java.nio.file.Path;
45+
import java.nio.file.SimpleFileVisitor;
46+
import java.nio.file.attribute.BasicFileAttributes;
4347
import java.util.ArrayList;
4448
import java.util.Arrays;
4549
import java.util.List;
@@ -66,7 +70,7 @@ public void apply(Project target) {
6670
? System.getenv("BUILD_NUMBER")
6771
: System.getenv("BUILDKITE_BUILD_NUMBER");
6872
String performanceTest = System.getenv("BUILD_PERFORMANCE_TEST");
69-
if (buildNumber != null && performanceTest == null && GradleUtils.isIncludedBuild(target) == false && OS.current() != OS.WINDOWS) {
73+
if (buildNumber != null && performanceTest == null && GradleUtils.isIncludedBuild(target) == false) {
7074
File targetFile = calculateTargetFile(target, buildNumber);
7175
File projectDir = target.getProjectDir();
7276
File gradleWorkersDir = new File(target.getGradle().getGradleUserHomeDir(), "workers/");
@@ -102,6 +106,23 @@ private File calculateTargetFile(Project target, String buildNumber) {
102106
}
103107

104108
private List<File> resolveProjectLogs(File projectDir) {
109+
// HACK: Some tests leave behind symlinks, and gradle throws an exception if it encounters symlinks.
110+
// Here we remove them before collecting logs to upload. We could instead build our own path matcher
111+
// but that seemed more complex than just deleting the irrelevant files.
112+
try {
113+
Files.walkFileTree(projectDir.toPath(), new SimpleFileVisitor<>() {
114+
@Override
115+
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
116+
if (Files.isSymbolicLink(file)) {
117+
Files.delete(file);
118+
}
119+
return FileVisitResult.CONTINUE;
120+
}
121+
});
122+
} catch (IOException e) {
123+
throw new UncheckedIOException(e);
124+
}
125+
105126
var projectDirFiles = getFileOperations().fileTree(projectDir);
106127
projectDirFiles.include("**/*.hprof");
107128
projectDirFiles.include("**/build/reports/configuration-cache/**");
@@ -276,7 +297,12 @@ private static void createBuildArchiveTar(List<File> files, File projectDir, Fil
276297

277298
@NotNull
278299
private static String calculateArchivePath(Path path, Path projectPath) {
279-
return path.startsWith(projectPath) ? projectPath.relativize(path).toString() : path.getFileName().toString();
300+
String archivePath = path.startsWith(projectPath) ? projectPath.relativize(path).toString() : path.getFileName().toString();
301+
if (OS.current() == OS.WINDOWS) {
302+
// tar always uses forward slashes
303+
archivePath = archivePath.replace("\\", "/");
304+
}
305+
return archivePath;
280306
}
281307
}
282308
}

0 commit comments

Comments
 (0)