2019-06-20 04:22:22 +08:00
|
|
|
import io = require('@actions/io');
|
|
|
|
import fs = require('fs');
|
|
|
|
import os = require('os');
|
|
|
|
import path = require('path');
|
2020-01-26 14:37:54 +08:00
|
|
|
import hc = require('@actions/http-client');
|
2019-06-20 04:22:22 +08:00
|
|
|
|
2020-04-05 21:37:29 +08:00
|
|
|
import each from 'jest-each';
|
2019-06-20 04:22:22 +08:00
|
|
|
|
|
|
|
const toolDir = path.join(__dirname, 'runner', 'tools');
|
|
|
|
const tempDir = path.join(__dirname, 'runner', 'temp');
|
|
|
|
|
2019-07-31 00:53:06 +08:00
|
|
|
process.env['RUNNER_TOOL_CACHE'] = toolDir;
|
|
|
|
process.env['RUNNER_TEMP'] = tempDir;
|
2019-08-13 00:14:43 +08:00
|
|
|
import * as setup from '../src/setup-dotnet';
|
2019-06-20 04:22:22 +08:00
|
|
|
import * as installer from '../src/installer';
|
|
|
|
|
2019-06-21 20:21:08 +08:00
|
|
|
const IS_WINDOWS = process.platform === 'win32';
|
|
|
|
|
2020-04-05 01:23:59 +08:00
|
|
|
describe('version tests', () => {
|
2020-05-21 19:02:58 +08:00
|
|
|
each(['3.1.999', '3.1.101-preview.3']).test(
|
2020-04-10 01:38:39 +08:00
|
|
|
"Exact version '%s' should be the same",
|
|
|
|
vers => {
|
|
|
|
let versInfo = new installer.DotNetVersionInfo(vers);
|
2020-04-05 01:23:59 +08:00
|
|
|
|
2020-04-10 01:38:39 +08:00
|
|
|
expect(versInfo.isExactVersion()).toBe(true);
|
|
|
|
expect(versInfo.version()).toBe(vers);
|
|
|
|
}
|
|
|
|
);
|
2020-04-05 01:23:59 +08:00
|
|
|
|
2020-09-22 03:49:32 +08:00
|
|
|
each([
|
|
|
|
['3.1.x', '3.1'],
|
|
|
|
['1.1.*', '1.1'],
|
|
|
|
['2.0', '2.0']
|
|
|
|
]).test("Generic version '%s' should be '%s'", (vers, resVers) => {
|
|
|
|
let versInfo = new installer.DotNetVersionInfo(vers);
|
|
|
|
|
|
|
|
expect(versInfo.isExactVersion()).toBe(false);
|
|
|
|
expect(versInfo.version()).toBe(resVers);
|
|
|
|
});
|
2020-04-05 21:37:29 +08:00
|
|
|
|
|
|
|
each([
|
2020-04-10 01:38:39 +08:00
|
|
|
'',
|
|
|
|
'.',
|
|
|
|
'..',
|
|
|
|
' . ',
|
|
|
|
'. ',
|
|
|
|
' .',
|
|
|
|
' . . ',
|
|
|
|
' .. ',
|
|
|
|
' . ',
|
|
|
|
'-1.-1',
|
|
|
|
'-1',
|
|
|
|
'-1.-1.-1',
|
|
|
|
'..3',
|
|
|
|
'1..3',
|
|
|
|
'1..',
|
|
|
|
'.2.3',
|
|
|
|
'.2.x',
|
|
|
|
'1',
|
|
|
|
'2.x',
|
|
|
|
'*.*.1',
|
|
|
|
'*.1',
|
|
|
|
'*.',
|
|
|
|
'1.2.',
|
|
|
|
'1.2.-abc',
|
|
|
|
'a.b',
|
|
|
|
'a.b.c',
|
|
|
|
'a.b.c-preview',
|
|
|
|
' 0 . 1 . 2 '
|
2020-04-05 21:37:29 +08:00
|
|
|
]).test("Malformed version '%s' should throw", vers => {
|
|
|
|
expect(() => new installer.DotNetVersionInfo(vers)).toThrow();
|
2020-04-10 01:38:39 +08:00
|
|
|
});
|
|
|
|
});
|
2020-04-05 01:23:59 +08:00
|
|
|
|
2019-06-20 04:22:22 +08:00
|
|
|
describe('installer tests', () => {
|
|
|
|
beforeAll(async () => {
|
2020-09-16 00:36:09 +08:00
|
|
|
process.env.RUNNER_TOOL_CACHE = toolDir;
|
|
|
|
process.env.DOTNET_INSTALL_DIR = toolDir;
|
|
|
|
process.env.RUNNER_TEMP = tempDir;
|
2019-06-20 04:22:22 +08:00
|
|
|
await io.rmRF(toolDir);
|
|
|
|
await io.rmRF(tempDir);
|
|
|
|
});
|
|
|
|
|
2019-06-21 20:21:08 +08:00
|
|
|
afterAll(async () => {
|
|
|
|
try {
|
|
|
|
await io.rmRF(toolDir);
|
|
|
|
await io.rmRF(tempDir);
|
|
|
|
} catch {
|
|
|
|
console.log('Failed to remove test directories');
|
|
|
|
}
|
2020-09-16 00:36:09 +08:00
|
|
|
}, 30000);
|
2019-06-21 20:21:08 +08:00
|
|
|
|
2020-04-10 01:38:39 +08:00
|
|
|
it('Resolving a normal generic version works', async () => {
|
2020-04-05 01:34:45 +08:00
|
|
|
const dotnetInstaller = new installer.DotnetCoreInstaller('3.1.x');
|
2020-09-16 00:36:09 +08:00
|
|
|
let versInfo = await dotnetInstaller.resolveVersion(
|
2020-04-10 01:38:39 +08:00
|
|
|
new installer.DotNetVersionInfo('3.1.x')
|
|
|
|
);
|
2020-04-05 01:34:45 +08:00
|
|
|
|
2020-09-16 00:36:09 +08:00
|
|
|
expect(versInfo.startsWith('3.1.'));
|
2020-04-05 01:34:45 +08:00
|
|
|
}, 100000);
|
|
|
|
|
2020-04-10 01:38:39 +08:00
|
|
|
it('Resolving a nonexistent generic version fails', async () => {
|
2020-04-05 01:44:50 +08:00
|
|
|
const dotnetInstaller = new installer.DotnetCoreInstaller('999.1.x');
|
2020-04-10 01:38:39 +08:00
|
|
|
try {
|
2020-09-16 00:36:09 +08:00
|
|
|
await dotnetInstaller.resolveVersion(
|
2020-04-10 01:38:39 +08:00
|
|
|
new installer.DotNetVersionInfo('999.1.x')
|
|
|
|
);
|
2020-04-05 01:44:50 +08:00
|
|
|
fail();
|
|
|
|
} catch {
|
|
|
|
expect(true);
|
|
|
|
}
|
|
|
|
}, 100000);
|
|
|
|
|
2020-05-21 19:02:58 +08:00
|
|
|
it('Resolving a exact stable version works', async () => {
|
2020-04-05 01:44:50 +08:00
|
|
|
const dotnetInstaller = new installer.DotnetCoreInstaller('3.1.201');
|
2020-09-16 00:36:09 +08:00
|
|
|
let versInfo = await dotnetInstaller.resolveVersion(
|
2020-04-10 01:38:39 +08:00
|
|
|
new installer.DotNetVersionInfo('3.1.201')
|
|
|
|
);
|
2020-04-05 01:44:50 +08:00
|
|
|
|
2020-09-16 00:36:09 +08:00
|
|
|
expect(versInfo).toBe('3.1.201');
|
2020-04-05 01:44:50 +08:00
|
|
|
}, 100000);
|
2020-04-05 01:34:45 +08:00
|
|
|
|
2020-05-21 19:02:58 +08:00
|
|
|
it('Resolving a exact preview version works', async () => {
|
2020-05-21 19:23:34 +08:00
|
|
|
const dotnetInstaller = new installer.DotnetCoreInstaller(
|
2020-09-16 00:36:09 +08:00
|
|
|
'5.0.0-preview.6'
|
2020-05-21 19:23:34 +08:00
|
|
|
);
|
2020-09-16 00:36:09 +08:00
|
|
|
let versInfo = await dotnetInstaller.resolveVersion(
|
|
|
|
new installer.DotNetVersionInfo('5.0.0-preview.6')
|
2020-05-21 19:02:58 +08:00
|
|
|
);
|
|
|
|
|
2020-09-16 00:36:09 +08:00
|
|
|
expect(versInfo).toBe('5.0.0-preview.6');
|
2020-05-21 19:02:58 +08:00
|
|
|
}, 100000);
|
|
|
|
|
2019-06-21 20:21:08 +08:00
|
|
|
it('Acquires version of dotnet if no matching version is installed', async () => {
|
2020-09-16 00:36:09 +08:00
|
|
|
await getDotnet('3.1.201');
|
|
|
|
expect(fs.existsSync(path.join(toolDir, 'sdk', '3.1.201'))).toBe(true);
|
2019-06-21 20:21:08 +08:00
|
|
|
if (IS_WINDOWS) {
|
2020-09-16 00:36:09 +08:00
|
|
|
expect(fs.existsSync(path.join(toolDir, 'dotnet.exe'))).toBe(true);
|
2019-06-21 20:21:08 +08:00
|
|
|
} else {
|
2020-09-16 00:36:09 +08:00
|
|
|
expect(fs.existsSync(path.join(toolDir, 'dotnet'))).toBe(true);
|
2019-06-21 20:21:08 +08:00
|
|
|
}
|
2020-04-10 01:26:10 +08:00
|
|
|
}, 400000); //This needs some time to download on "slower" internet connections
|
2019-06-21 20:21:08 +08:00
|
|
|
|
2020-09-16 00:36:09 +08:00
|
|
|
it('Acquires version of dotnet from global.json if no matching version is installed', async () => {
|
2019-08-13 00:14:43 +08:00
|
|
|
const globalJsonPath = path.join(process.cwd(), 'global.json');
|
2020-09-16 00:36:09 +08:00
|
|
|
const jsonContents = `{${os.EOL}"sdk": {${os.EOL}"version": "3.1.201"${os.EOL}}${os.EOL}}`;
|
2019-08-13 00:17:46 +08:00
|
|
|
if (!fs.existsSync(globalJsonPath)) {
|
2019-08-13 00:14:43 +08:00
|
|
|
fs.writeFileSync(globalJsonPath, jsonContents);
|
|
|
|
}
|
|
|
|
await setup.run();
|
|
|
|
|
2020-09-16 00:36:09 +08:00
|
|
|
expect(fs.existsSync(path.join(toolDir, 'sdk', '3.1.201'))).toBe(true);
|
2019-08-13 00:14:43 +08:00
|
|
|
if (IS_WINDOWS) {
|
2020-09-16 00:36:09 +08:00
|
|
|
expect(fs.existsSync(path.join(toolDir, 'dotnet.exe'))).toBe(true);
|
2019-08-13 00:14:43 +08:00
|
|
|
} else {
|
2020-09-16 00:36:09 +08:00
|
|
|
expect(fs.existsSync(path.join(toolDir, 'dotnet'))).toBe(true);
|
2019-08-13 00:14:43 +08:00
|
|
|
}
|
|
|
|
fs.unlinkSync(globalJsonPath);
|
|
|
|
}, 100000);
|
|
|
|
|
2019-06-21 20:21:08 +08:00
|
|
|
it('Throws if no location contains correct dotnet version', async () => {
|
|
|
|
let thrown = false;
|
|
|
|
try {
|
|
|
|
await getDotnet('1000.0.0');
|
|
|
|
} catch {
|
|
|
|
thrown = true;
|
|
|
|
}
|
|
|
|
expect(thrown).toBe(true);
|
2020-09-16 00:36:09 +08:00
|
|
|
}, 30000);
|
2019-06-21 20:21:08 +08:00
|
|
|
|
|
|
|
it('Uses an up to date bash download script', async () => {
|
2020-01-26 14:37:54 +08:00
|
|
|
const httpCallbackClient = new hc.HttpClient('setup-dotnet-test', [], {
|
|
|
|
allowRetries: true,
|
|
|
|
maxRetries: 3
|
|
|
|
});
|
|
|
|
const response: hc.HttpClientResponse = await httpCallbackClient.get(
|
2019-06-21 20:21:08 +08:00
|
|
|
'https://dot.net/v1/dotnet-install.sh'
|
|
|
|
);
|
2020-01-26 14:37:54 +08:00
|
|
|
expect(response.message.statusCode).toBe(200);
|
2019-06-21 20:21:08 +08:00
|
|
|
const upToDateContents: string = await response.readBody();
|
|
|
|
const currentContents: string = fs
|
|
|
|
.readFileSync(
|
|
|
|
path.join(__dirname, '..', 'externals', 'install-dotnet.sh')
|
|
|
|
)
|
|
|
|
.toString();
|
|
|
|
expect(normalizeFileContents(currentContents)).toBe(
|
|
|
|
normalizeFileContents(upToDateContents)
|
|
|
|
);
|
2020-09-16 00:36:09 +08:00
|
|
|
}, 30000);
|
2019-06-21 20:21:08 +08:00
|
|
|
|
|
|
|
it('Uses an up to date powershell download script', async () => {
|
2020-01-26 14:37:54 +08:00
|
|
|
var httpCallbackClient = new hc.HttpClient('setup-dotnet-test', [], {
|
|
|
|
allowRetries: true,
|
|
|
|
maxRetries: 3
|
|
|
|
});
|
|
|
|
const response: hc.HttpClientResponse = await httpCallbackClient.get(
|
2019-06-21 20:21:08 +08:00
|
|
|
'https://dot.net/v1/dotnet-install.ps1'
|
|
|
|
);
|
2020-01-26 14:37:54 +08:00
|
|
|
expect(response.message.statusCode).toBe(200);
|
2019-06-21 20:21:08 +08:00
|
|
|
const upToDateContents: string = await response.readBody();
|
|
|
|
const currentContents: string = fs
|
|
|
|
.readFileSync(
|
|
|
|
path.join(__dirname, '..', 'externals', 'install-dotnet.ps1')
|
|
|
|
)
|
|
|
|
.toString();
|
|
|
|
expect(normalizeFileContents(currentContents)).toBe(
|
|
|
|
normalizeFileContents(upToDateContents)
|
|
|
|
);
|
2020-09-16 00:36:09 +08:00
|
|
|
}, 30000);
|
2019-06-20 04:22:22 +08:00
|
|
|
});
|
2019-06-21 20:21:08 +08:00
|
|
|
|
|
|
|
function normalizeFileContents(contents: string): string {
|
|
|
|
return contents
|
|
|
|
.trim()
|
|
|
|
.replace(new RegExp('\r\n', 'g'), '\n')
|
|
|
|
.replace(new RegExp('\r', 'g'), '\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getDotnet(version: string): Promise<void> {
|
|
|
|
const dotnetInstaller = new installer.DotnetCoreInstaller(version);
|
|
|
|
await dotnetInstaller.installDotnet();
|
|
|
|
}
|