Skip to content

Commit f5b29e1

Browse files
authored
Fix Conda Environment on Hosted Linux Preview (#8427) (#8447)
* Make sure `conda` is in PATH before calling `sudo` * bump patch version * only pass full path as the arg to sudo * update tests * don't need to "mock" temp directory (which breaks mock-task)
1 parent 61c4345 commit f5b29e1

File tree

7 files changed

+22
-11
lines changed

7 files changed

+22
-11
lines changed

Tasks/CondaEnvironmentV1/Tests/L0.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('CondaEnvironment L0 Suite', function () {
2424
if (getPlatform() === Platform.Windows) {
2525
assert(testRunner.ran('conda create --quiet --prefix \\miniconda\\envs\\test --mkdir --yes'));
2626
} else {
27-
assert(testRunner.ran('sudo conda create --quiet --prefix /miniconda/envs/test --mkdir --yes'));
27+
assert(testRunner.ran('sudo /miniconda/bin/conda create --quiet --prefix /miniconda/envs/test --mkdir --yes'));
2828
}
2929

3030
assert.strictEqual(testRunner.stderr.length, 0, 'should not have written to stderr');
@@ -40,7 +40,7 @@ describe('CondaEnvironment L0 Suite', function () {
4040
if (getPlatform() === Platform.Windows) {
4141
assert(testRunner.ran('conda install python=3 --quiet --yes --json'));
4242
} else {
43-
assert(testRunner.ran('sudo conda install python=3 --quiet --yes --json'));
43+
assert(testRunner.ran('sudo /miniconda/bin/conda install python=3 --quiet --yes --json'));
4444
}
4545

4646
assert.strictEqual(testRunner.stderr.length, 0, 'should not have written to stderr');

Tasks/CondaEnvironmentV1/Tests/L0BaseEnvironment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ taskRunner.setAnswers({
1616
'conda': '/miniconda/bin/conda'
1717
},
1818
exec: {
19-
'sudo conda install python=3 --quiet --yes --json': {
19+
'sudo /miniconda/bin/conda install python=3 --quiet --yes --json': {
2020
code: 0
2121
},
2222
'conda install python=3 --quiet --yes --json': {

Tasks/CondaEnvironmentV1/Tests/L0CreateEnvironment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ taskRunner.setAnswers({
1616
'conda': '/miniconda/bin/conda'
1717
},
1818
exec: {
19-
'sudo conda create --quiet --prefix /miniconda/envs/test --mkdir --yes': {
19+
'sudo /miniconda/bin/conda create --quiet --prefix /miniconda/envs/test --mkdir --yes': {
2020
code: 0
2121
},
2222
'conda create --quiet --prefix \\miniconda\\envs\\test --mkdir --yes': {

Tasks/CondaEnvironmentV1/Tests/L0_conda_internal.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ it('finds the Conda installation with PATH', async function () {
120120
});
121121

122122
it('creates Conda environment', async function () {
123+
mockTask.setAnswers({
124+
which: {
125+
'conda': '/miniconda/bin/conda'
126+
}
127+
});
128+
123129
mockery.registerMock('vsts-task-lib/task', mockTask);
124130
mockery.registerMock('vsts-task-lib/toolrunner', mockToolRunner);
125131
const uut = reload('../conda_internal');
@@ -138,7 +144,7 @@ it('creates Conda environment', async function () {
138144
} else {
139145
mockToolRunner.setAnswers({
140146
exec: {
141-
[`sudo conda create --quiet --prefix ${path.join('envsDir', 'env')} --mkdir --yes`]: {
147+
[`sudo /miniconda/bin/conda create --quiet --prefix ${path.join('envsDir', 'env')} --mkdir --yes`]: {
142148
code: 0
143149
}
144150
}
@@ -159,7 +165,7 @@ it('creates Conda environment', async function () {
159165
} else {
160166
mockToolRunner.setAnswers({
161167
exec: {
162-
[`sudo conda create --quiet --prefix ${path.join('envsDir', 'env')} --mkdir --yes`]: {
168+
[`sudo /miniconda/bin/conda create --quiet --prefix ${path.join('envsDir', 'env')} --mkdir --yes`]: {
163169
code: 1
164170
}
165171
}

Tasks/CondaEnvironmentV1/conda_internal.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,16 @@ function binaryDir(environmentRoot: string, platform: Platform): string {
3535
}
3636
}
3737

38-
function sudo(toolPath: string, platform: Platform): ToolRunner {
38+
/**
39+
* Run a tool with `sudo` on Linux and macOS
40+
* Precondition: `toolName` executable is in PATH
41+
*/
42+
function sudo(toolName: string, platform: Platform): ToolRunner {
3943
if (platform === Platform.Windows) {
40-
return task.tool('conda');
44+
return task.tool(toolName);
4145
} else {
42-
return task.tool('sudo').line('conda');
46+
const toolPath = task.which(toolName);
47+
return task.tool('sudo').line(toolPath);
4348
}
4449
}
4550

Tasks/CondaEnvironmentV1/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"version": {
1414
"Major": 1,
1515
"Minor": 140,
16-
"Patch": 1
16+
"Patch": 2
1717
},
1818
"demands": [],
1919
"instanceNameFormat": "Conda environment $(environmentName)",

Tasks/CondaEnvironmentV1/task.loc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"version": {
1414
"Major": 1,
1515
"Minor": 140,
16-
"Patch": 1
16+
"Patch": 2
1717
},
1818
"demands": [],
1919
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",

0 commit comments

Comments
 (0)