10000 Always build ci workspace without trailing separator by daniel-mohedano · Pull Request #8788 · DataDog/dd-trace-java · GitHub
[go: up one dir, main page]

Skip to content
8000

Always build ci workspace without trailing separator #8788

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

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
add unit tests and take into account root path
  • Loading branch information
daniel-mohedano committed May 9, 2025
commit de21bd10c227224eb540f02d63e6191ab3ae5a38
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public CIInfo(
this.ciPipelineNumber = ciPipelineNumber;
this.ciPipelineUrl = ciPipelineUrl;
this.ciJobUrl = ciJobUrl;
this.ciWorkspace = ciWorkspace;
this.ciWorkspace = sanitizeWorkspace(ciWorkspace);
this.ciNodeName = ciNodeName;
this.ciNodeLabels = ciNodeLabels;
this.ciEnvVars = ciEnvVars;
Expand Down Expand Up @@ -209,14 +209,20 @@ public String getCiJobUrl() {
return ciJobUrl;
}

/** @return Workspace path without the trailing separator */
public String getCiWorkspace() {
String realCiWorkspace = FileUtils.toRealPath(ciWorkspace);
return (realCiWorkspace == null || !realCiWorkspace.endsWith(File.separator))
private String sanitizeWorkspace(String workspace) {
String realCiWorkspace = FileUtils.toRealPath(workspace);
return (realCiWorkspace == null
|| !realCiWorkspace.endsWith(File.separator)
|| realCiWorkspace.length() == 1) // root path "/"
? realCiWorkspace
: (realCiWorkspace.substring(0, realCiWorkspace.length() - 1));
}

/** @return Workspace path without the trailing separator */
public String getCiWorkspace() {
return ciWorkspace;
}

public String getCiNodeName() {
return ciNodeName;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package datadog.trace.civisibility.ci


import spock.lang.Specification

class CIInfoTest extends Specification {

def "test ci workspace is correctly sanitized #iterationIndex"() {
def builder = CIInfo.builder(null)
builder.ciWorkspace(workspacePath)
def info = builder.build()

info.ciWorkspace == sanitizedPath

where:
workspacePath | sanitizedPath
null | null
"/" | "/"
"/repo/path" | "/repo/path"
"/repo/path/" | "/repo/path"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public GitInfo getGitInfo(@Nullable String repositoryPath) {
repositoryPath = NULL_PATH_STRING;
}

// normalize path to avoid creating two entries in the cache
return gitInfoCache.computeIfAbsent(repositoryPath, this::buildGitInfo);
}

Expand Down
0