Skip to content

Commit 7a98346

Browse files
author
Zachary Eisinger
authored
DOTNET_ROOT and short generic versions (#131)
1 parent 9d7c66c commit 7a98346

File tree

6 files changed

+187
-122
lines changed

6 files changed

+187
-122
lines changed

.github/workflows/workflow.yml

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,62 @@ jobs:
7575
run: __tests__/verify-dotnet.sh 3.1.201 2.2.402
7676
- name: Verify dotnet (Windows)
7777
if: runner.os == 'windows'
78-
run: __tests__/verify-dotnet.ps1 3.1.201
78+
run: __tests__/verify-dotnet.ps1 3.1.201 2.2.402
79+
80+
# Set new cache before 2 digit install
81+
- name: Set new tool cache (macOS)
82+
if: runner.os == 'macos'
83+
run: |
84+
echo "::set-env name=DOTNET_INSTALL_DIR::/Users/runner/.dotnet2"
85+
- name: Set new tool cache (Ubuntu)
86+
if: runner.os == 'linux'
87+
run: |
88+
echo "::set-env name=DOTNET_INSTALL_DIR::/home/runner/.dotnet2"
89+
- name: Set new tool cache (Windows)
90+
if: runner.os == 'windows'
91+
run: |
92+
echo "::set-env name=DOTNET_INSTALL_DIR::$env:LocalAppData\Microsoft\dotnet2"
93+
# 2.0, 3.0, 5.0 needs to be in single quotes to interpret as a string instead of as an integer
94+
- name: Setup dotnet '2.0'
95+
uses: ./
96+
with:
97+
dotnet-version: '2.0'
98+
99+
# Clear cache before .x version install
100+
- name: Set new tool cache (macOS)
101+
if: runner.os == 'macos'
102+
run: |
103+
echo "::set-env name=DOTNET_INSTALL_DIR::/Users/runner/.dotnet3"
104+
- name: Set new tool cache (Ubuntu)
105+
if: runner.os == 'linux'
106+
run: |
107+
echo "::set-env name=DOTNET_INSTALL_DIR::/home/runner/.dotnet3"
108+
- name: Set new tool cache (Windows)
109+
if: runner.os == 'windows'
110+
run: |
111+
echo "::set-env name=DOTNET_INSTALL_DIR::$env:LocalAppData\Microsoft\dotnet3"
112+
- name: Setup dotnet 2.0.x
113+
uses: ./
114+
with:
115+
dotnet-version: 2.0.x
116+
117+
# Clear cache before .* version install
118+
- name: Set new tool cache (macOS)
119+
if: runner.os == 'macos'
120+
run: |
121+
echo "::set-env name=DOTNET_INSTALL_DIR::/Users/runner/.dotnet4"
122+
- name: Set new tool cache (Ubuntu)
123+
if: runner.os == 'linux'
124+
run: |
125+
echo "::set-env name=DOTNET_INSTALL_DIR::/home/runner/.dotnet4"
126+
- name: Set new tool cache (Windows)
127+
if: runner.os == 'windows'
128+
run: |
129+
echo "::set-env name=DOTNET_INSTALL_DIR::$env:LocalAppData\Microsoft\dotnet4"
130+
- name: Setup dotnet 2.0.*
131+
uses: ./
132+
with:
133+
dotnet-version: 2.0.*
79134

80135
test-proxy:
81136
runs-on: ubuntu-latest

__tests__/installer.test.ts

Lines changed: 19 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -4,79 +4,21 @@ import os = require('os');
44
import path = require('path');
55
import hc = require('@actions/http-client');
66

7-
import each from 'jest-each';
8-
97
const toolDir = path.join(__dirname, 'runner', 'tools');
108
const tempDir = path.join(__dirname, 'runner', 'temp');
119

1210
process.env['RUNNER_TOOL_CACHE'] = toolDir;
1311
process.env['RUNNER_TEMP'] = tempDir;
14-
import * as setup from '../src/setup-dotnet';
1512
import * as installer from '../src/installer';
1613

1714
const IS_WINDOWS = process.platform === 'win32';
1815

19-
describe('version tests', () => {
20-
each(['3.1.999', '3.1.101-preview.3']).test(
21-
"Exact version '%s' should be the same",
22-
vers => {
23-
let versInfo = new installer.DotNetVersionInfo(vers);
24-
25-
expect(versInfo.isExactVersion()).toBe(true);
26-
expect(versInfo.version()).toBe(vers);
27-
}
28-
);
29-
30-
each([
31-
['3.1.x', '3.1'],
32-
['1.1.*', '1.1'],
33-
['2.0', '2.0']
34-
]).test("Generic version '%s' should be '%s'", (vers, resVers) => {
35-
let versInfo = new installer.DotNetVersionInfo(vers);
36-
37-
expect(versInfo.isExactVersion()).toBe(false);
38-
expect(versInfo.version()).toBe(resVers);
39-
});
40-
41-
each([
42-
'',
43-
'.',
44-
'..',
45-
' . ',
46-
'. ',
47-
' .',
48-
' . . ',
49-
' .. ',
50-
' . ',
51-
'-1.-1',
52-
'-1',
53-
'-1.-1.-1',
54-
'..3',
55-
'1..3',
56-
'1..',
57-
'.2.3',
58-
'.2.x',
59-
'1',
60-
'2.x',
61-
'*.*.1',
62-
'*.1',
63-
'*.',
64-
'1.2.',
65-
'1.2.-abc',
66-
'a.b',
67-
'a.b.c',
68-
'a.b.c-preview',
69-
' 0 . 1 . 2 '
70-
]).test("Malformed version '%s' should throw", vers => {
71-
expect(() => new installer.DotNetVersionInfo(vers)).toThrow();
72-
});
73-
});
74-
7516
describe('installer tests', () => {
7617
beforeAll(async () => {
7718
process.env.RUNNER_TOOL_CACHE = toolDir;
7819
process.env.DOTNET_INSTALL_DIR = toolDir;
7920
process.env.RUNNER_TEMP = tempDir;
21+
process.env.DOTNET_ROOT = '';
8022
await io.rmRF(toolDir);
8123
await io.rmRF(tempDir);
8224
});
@@ -90,47 +32,6 @@ describe('installer tests', () => {
9032
}
9133
}, 30000);
9234

93-
it('Resolving a normal generic version works', async () => {
94-
const dotnetInstaller = new installer.DotnetCoreInstaller('3.1.x');
95-
let versInfo = await dotnetInstaller.resolveVersion(
96-
new installer.DotNetVersionInfo('3.1.x')
97-
);
98-
99-
expect(versInfo.startsWith('3.1.'));
100-
}, 100000);
101-
102-
it('Resolving a nonexistent generic version fails', async () => {
103-
const dotnetInstaller = new installer.DotnetCoreInstaller('999.1.x');
104-
try {
105-
await dotnetInstaller.resolveVersion(
106-
new installer.DotNetVersionInfo('999.1.x')
107-
);
108-
fail();
109-
} catch {
110-
expect(true);
111-
}
112-
}, 100000);
113-
114-
it('Resolving a exact stable version works', async () => {
115-
const dotnetInstaller = new installer.DotnetCoreInstaller('3.1.201');
116-
let versInfo = await dotnetInstaller.resolveVersion(
117-
new installer.DotNetVersionInfo('3.1.201')
118-
);
119-
120-
expect(versInfo).toBe('3.1.201');
121-
}, 100000);
122-
123-
it('Resolving a exact preview version works', async () => {
124-
const dotnetInstaller = new installer.DotnetCoreInstaller(
125-
'5.0.0-preview.6'
126-
);
127-
let versInfo = await dotnetInstaller.resolveVersion(
128-
new installer.DotNetVersionInfo('5.0.0-preview.6')
129-
);
130-
131-
expect(versInfo).toBe('5.0.0-preview.6');
132-
}, 100000);
133-
13435
it('Acquires version of dotnet if no matching version is installed', async () => {
13536
await getDotnet('3.1.201');
13637
expect(fs.existsSync(path.join(toolDir, 'sdk', '3.1.201'))).toBe(true);
@@ -139,24 +40,30 @@ describe('installer tests', () => {
13940
} else {
14041
expect(fs.existsSync(path.join(toolDir, 'dotnet'))).toBe(true);
14142
}
142-
}, 400000); //This needs some time to download on "slower" internet connections
14343

144-
it('Acquires version of dotnet from global.json if no matching version is installed', async () => {
145-
const globalJsonPath = path.join(process.cwd(), 'global.json');
146-
const jsonContents = `{${os.EOL}"sdk": {${os.EOL}"version": "3.1.201"${os.EOL}}${os.EOL}}`;
147-
if (!fs.existsSync(globalJsonPath)) {
148-
fs.writeFileSync(globalJsonPath, jsonContents);
149-
}
150-
await setup.run();
151-
152-
expect(fs.existsSync(path.join(toolDir, 'sdk', '3.1.201'))).toBe(true);
44+
expect(process.env.DOTNET_ROOT).toBeDefined;
45+
expect(process.env.PATH).toBeDefined;
46+
expect(process.env.DOTNET_ROOT).toBe(toolDir);
47+
expect(process.env.PATH?.startsWith(toolDir)).toBe(true);
48+
}, 600000); //This needs some time to download on "slower" internet connections
49+
50+
it('Acquires generic version of dotnet if no matching version is installed', async () => {
51+
await getDotnet('3.1');
52+
var directory = fs
53+
.readdirSync(path.join(toolDir, 'sdk'))
54+
.filter(fn => fn.startsWith('3.1.'));
55+
expect(directory.length > 0).toBe(true);
15356
if (IS_WINDOWS) {
15457
expect(fs.existsSync(path.join(toolDir, 'dotnet.exe'))).toBe(true);
15558
} else {
15659
expect(fs.existsSync(path.join(toolDir, 'dotnet'))).toBe(true);
15760
}
158-
fs.unlinkSync(globalJsonPath);
159-
}, 100000);
61+
62+
expect(process.env.DOTNET_ROOT).toBeDefined;
63+
expect(process.env.PATH).toBeDefined;
64+
expect(process.env.DOTNET_ROOT).toBe(toolDir);
65+
expect(process.env.PATH?.startsWith(toolDir)).toBe(true);
66+
}, 600000); //This needs some time to download on "slower" internet connections
16067

16168
it('Throws if no location contains correct dotnet version', async () => {
16269
let thrown = false;

__tests__/setup-dotnet.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('setup-dotnet tests', () => {
2929
}
3030
}, 30000);
3131

32-
it('Acquires version of dotnet if no matching version is installed', async () => {
32+
it('Acquires version of dotnet from global.json if no matching version is installed', async () => {
3333
const globalJsonPath = path.join(process.cwd(), 'global.json');
3434
const jsonContents = `{${os.EOL}"sdk": {${os.EOL}"version": "3.1.201"${os.EOL}}${os.EOL}}`;
3535
if (!fs.existsSync(globalJsonPath)) {
@@ -43,6 +43,5 @@ describe('setup-dotnet tests', () => {
4343
} else {
4444
expect(fs.existsSync(path.join(toolDir, 'dotnet'))).toBe(true);
4545
}
46-
fs.unlinkSync(globalJsonPath);
47-
}, 100000);
46+
}, 400000);
4847
});

__tests__/versionutil.test.ts

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import each from 'jest-each';
2+
import * as installer from '../src/installer';
3+
4+
describe('version tests', () => {
5+
each(['3.1.999', '3.1.101-preview.3']).test(
6+
"Exact version '%s' should be the same",
7+
vers => {
8+
let versInfo = new installer.DotNetVersionInfo(vers);
9+
10+
expect(versInfo.isExactVersion()).toBe(true);
11+
expect(versInfo.version()).toBe(vers);
12+
}
13+
);
14+
15+
each([
16+
['3.1.x', '3.1'],
17+
['1.1.*', '1.1'],
18+
['2.0', '2.0']
19+
]).test("Generic version '%s' should be '%s'", (vers, resVers) => {
20+
let versInfo = new installer.DotNetVersionInfo(vers);
21+
22+
expect(versInfo.isExactVersion()).toBe(false);
23+
expect(versInfo.version()).toBe(resVers);
24+
});
25+
26+
each([
27+
'',
28+
'.',
29+
'..',
30+
' . ',
31+
'. ',
32+
' .',
33+
' . . ',
34+
' .. ',
35+
' . ',
36+
'-1.-1',
37+
'-1',
38+
'-1.-1.-1',
39+
'..3',
40+
'1..3',
41+
'1..',
42+
'.2.3',
43+
'.2.x',
44+
'1',
45+
'2.x',
46+
'*.*.1',
47+
'*.1',
48+
'*.',
49+
'1.2.',
50+
'1.2.-abc',
51+
'a.b',
52+
'a.b.c',
53+
'a.b.c-preview',
54+
' 0 . 1 . 2 '
55+
]).test("Malformed version '%s' should throw", vers => {
56+
expect(() => new installer.DotNetVersionInfo(vers)).toThrow();
57+
});
58+
59+
each([
60+
['3.1.x', '3.1.'],
61+
['3.1.*', '3.1.'],
62+
['3.1', '3.1.'],
63+
['5.0.0-preview.6', '5.0.0-preview.6'],
64+
['3.1.201', '3.1.201']
65+
]).test(
66+
"Resolving version '%s' as '%s'",
67+
async (input, expectedVersion) => {
68+
const dotnetInstaller = new installer.DotnetCoreInstaller(input);
69+
let versInfo = await dotnetInstaller.resolveVersion(
70+
new installer.DotNetVersionInfo(input)
71+
);
72+
console.log(versInfo);
73+
74+
expect(versInfo.startsWith(expectedVersion));
75+
},
76+
100000
77+
);
78+
79+
it('Resolving a nonexistent generic version fails', async () => {
80+
const dotnetInstaller = new installer.DotnetCoreInstaller('999.1.x');
81+
try {
82+
await dotnetInstaller.resolveVersion(
83+
new installer.DotNetVersionInfo('999.1.x')
84+
);
85+
fail();
86+
} catch {
87+
expect(true);
88+
}
89+
}, 100000);
90+
});

dist/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16901,8 +16901,8 @@ class DotnetCoreInstaller {
1690116901
fs_1.chmodSync(escapedScript, '777');
1690216902
const scriptPath = yield io.which(escapedScript, true);
1690316903
let scriptArguments = [];
16904-
if (this.version) {
16905-
scriptArguments.push('--version', this.version);
16904+
if (calculatedVersion) {
16905+
scriptArguments.push('--version', calculatedVersion);
1690616906
}
1690716907
// process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
1690816908
resultCode = yield exec.exec(`"${scriptPath}"`, scriptArguments, {
@@ -16916,6 +16916,7 @@ class DotnetCoreInstaller {
1691616916
}
1691716917
if (process.env['DOTNET_INSTALL_DIR']) {
1691816918
core.addPath(process.env['DOTNET_INSTALL_DIR']);
16919+
core.exportVariable('DOTNET_ROOT', process.env['DOTNET_INSTALL_DIR']);
1691916920
}
1692016921
else {
1692116922
if (IS_WINDOWS) {
@@ -16926,6 +16927,7 @@ class DotnetCoreInstaller {
1692616927
else {
1692716928
// This is the default set in install-dotnet.sh
1692816929
core.addPath(path.join(process.env['HOME'] + '', '.dotnet'));
16930+
core.exportVariable('DOTNET_ROOT', path.join(process.env['HOME'] + '', '.dotnet'));
1692916931
}
1693016932
}
1693116933
console.log(process.env['PATH']);
@@ -16972,7 +16974,8 @@ class DotnetCoreInstaller {
1697216974
releasesInfo = releasesInfo.filter((info) => {
1697316975
// channel-version is the first 2 elements of the version (e.g. 2.1), filter out versions that don't match 2.1.x.
1697416976
const sdkParts = info['channel-version'].split('.');
16975-
if (versionParts.length >= 2 && versionParts[1] != 'x') {
16977+
if (versionParts.length >= 2 &&
16978+
!(versionParts[1] == 'x' || versionParts[1] == '*')) {
1697616979
return versionParts[0] == sdkParts[0] && versionParts[1] == sdkParts[1];
1697716980
}
1697816981
return versionParts[0] == sdkParts[0];

0 commit comments

Comments
 (0)