Skip to content
This repository was archived by the owner on May 8, 2024. It is now read-only.

Commit e5fb2d1

Browse files
committed
Respect precreated
1 parent df16aa9 commit e5fb2d1

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

internal/executor/executor.go

+6-12
Original file line numberDiff line numberDiff line change
@@ -204,18 +204,6 @@ func (executor *Executor) PopulateCloneAndWorkingDirEnvironmentVariables(environ
204204
_, hasCloneDir := result["CIRRUS_CLONE_DIR"]
205205
_, hasWorkingDir := result["CIRRUS_WORKING_DIR"]
206206

207-
// Use directory created by the persistent worker if CIRRUS_WORKING_DIR
208-
// was not overridden in the task specification by the user
209-
if executor.preCreatedWorkingDir != "" {
210-
result["CIRRUS_CLONE_DIR"] = executor.preCreatedWorkingDir
211-
hasCloneDir = true
212-
// Need to override working dir too
213-
if hasWorkingDir && !strings.Contains(result["CIRRUS_WORKING_DIR"], "CIRRUS_CLONE_DIR") {
214-
// If working dir doesn't depend on clone dir then we can default clone dir to the one provided by user
215-
result["CIRRUS_WORKING_DIR"] = "$CIRRUS_CLONE_DIR"
216-
}
217-
}
218-
219207
if hasCloneDir && !hasWorkingDir {
220208
// Only clone was overridden. Make sure $CIRRUS_WORKING_DIR is set
221209
result["CIRRUS_WORKING_DIR"] = "$CIRRUS_CLONE_DIR"
@@ -225,6 +213,7 @@ func (executor *Executor) PopulateCloneAndWorkingDirEnvironmentVariables(environ
225213
if !strings.Contains(result["CIRRUS_WORKING_DIR"], "CIRRUS_CLONE_DIR") {
226214
// If working dir doesn't depend on clone dir then we can default clone dir to the one provided by user
227215
result["CIRRUS_CLONE_DIR"] = "$CIRRUS_WORKING_DIR"
216+
hasCloneDir = true
228217
}
229218
}
230219

@@ -233,6 +222,11 @@ func (executor *Executor) PopulateCloneAndWorkingDirEnvironmentVariables(environ
233222
result["CIRRUS_WORKING_DIR"] = "$CIRRUS_CLONE_DIR"
234223
}
235224

225+
if !hasCloneDir && executor.preCreatedWorkingDir != "" {
226+
// none of the dirs are explicitly set. Make sure they'll be the same
227+
result["CIRRUS_CLONE_DIR"] = executor.preCreatedWorkingDir
228+
}
229+
236230
if _, ok := result["CIRRUS_CLONE_DIR"]; !ok {
237231
defaultTempDirPath := filepath.Join(os.TempDir(), "cirrus-ci-build")
238232
if _, err := os.Stat(defaultTempDirPath); os.IsNotExist(err) {

internal/executor/executor_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ func TestPopulateCloneAndWorkingDirEnvironmentVariables(t *testing.T) {
108108
"CIRRUS_WORKING_DIR": "/tmp/foo",
109109
},
110110
map[string]string{
111-
"CIRRUS_CLONE_DIR": "/tmp/precreated-build",
112-
"CIRRUS_WORKING_DIR": "$CIRRUS_CLONE_DIR",
111+
"CIRRUS_CLONE_DIR": "$CIRRUS_WORKING_DIR",
112+
"CIRRUS_WORKING_DIR": "/tmp/foo",
113113
},
114114
},
115115
{
@@ -152,7 +152,7 @@ func TestPopulateCloneAndWorkingDirEnvironmentVariables(t *testing.T) {
152152
"CIRRUS_CLONE_DIR": "/tmp/foo",
153153
},
154154
map[string]string{
155-
"CIRRUS_CLONE_DIR": "/tmp/precreated-build",
155+
"CIRRUS_CLONE_DIR": "/tmp/foo",
156156
"CIRRUS_WORKING_DIR": "$CIRRUS_CLONE_DIR",
157157
},
158158
},
@@ -176,8 +176,8 @@ func TestPopulateCloneAndWorkingDirEnvironmentVariables(t *testing.T) {
176176
"CIRRUS_WORKING_DIR": "/tmp/foo",
177177
},
178178
map[string]string{
179-
"CIRRUS_CLONE_DIR": "/tmp/precreated-build",
180-
"CIRRUS_WORKING_DIR": "$CIRRUS_CLONE_DIR",
179+
"CIRRUS_CLONE_DIR": "/tmp/foo",
180+
"CIRRUS_WORKING_DIR": "/tmp/foo",
181181
},
182182
},
183183
{
@@ -200,7 +200,7 @@ func TestPopulateCloneAndWorkingDirEnvironmentVariables(t *testing.T) {
200200
"CIRRUS_WORKING_DIR": "$CIRRUS_CLONE_DIR/bar",
201201
},
202202
map[string]string{
203-
"CIRRUS_CLONE_DIR": "/tmp/precreated-build",
203+
"CIRRUS_CLONE_DIR": "/tmp/foo",
204204
"CIRRUS_WORKING_DIR": "$CIRRUS_CLONE_DIR/bar",
205205
},
206206
},

0 commit comments

Comments
 (0)