refactored version logic

This commit is contained in:
La'Kaleigh Harris 2021-11-09 15:14:49 +00:00 committed by GitHub
parent aca1816f14
commit 866d7435eb
6 changed files with 161 additions and 175 deletions

View File

@ -34,7 +34,10 @@ describe('installer tests', () => {
it('Aquires multiple versions of dotnet', async () => {
const versions = ['2.2.207', '3.1.120'];
await getDotnet(versions);
for (const version of versions) {
await getDotnet(version);
}
expect(fs.existsSync(path.join(toolDir, 'sdk', '2.2.207'))).toBe(true);
expect(fs.existsSync(path.join(toolDir, 'sdk', '3.1.120'))).toBe(true);
@ -51,7 +54,7 @@ describe('installer tests', () => {
}, 600000);
it('Acquires version of dotnet if no matching version is installed', async () => {
await getDotnet(['3.1.201']);
await getDotnet('3.1.201');
expect(fs.existsSync(path.join(toolDir, 'sdk', '3.1.201'))).toBe(true);
if (IS_WINDOWS) {
expect(fs.existsSync(path.join(toolDir, 'dotnet.exe'))).toBe(true);
@ -66,7 +69,7 @@ describe('installer tests', () => {
}, 600000); //This needs some time to download on "slower" internet connections
it('Acquires generic version of dotnet if no matching version is installed', async () => {
await getDotnet(['3.1']);
await getDotnet('3.1');
var directory = fs
.readdirSync(path.join(toolDir, 'sdk'))
.filter(fn => fn.startsWith('3.1.'));
@ -86,7 +89,7 @@ describe('installer tests', () => {
it('Throws if no location contains correct dotnet version', async () => {
let thrown = false;
try {
await getDotnet(['1000.0.0']);
await getDotnet('1000.0.0');
} catch {
thrown = true;
}
@ -141,7 +144,7 @@ function normalizeFileContents(contents: string): string {
.replace(new RegExp('\r', 'g'), '\n');
}
async function getDotnet(versions: string[]): Promise<void> {
const dotnetInstaller = new installer.DotnetCoreInstaller(versions);
async function getDotnet(version: string): Promise<void> {
const dotnetInstaller = new installer.DotnetCoreInstaller(version);
await dotnetInstaller.installDotnet();
}

View File

@ -53,10 +53,10 @@ describe('setup-dotnet tests', () => {
fs.writeFileSync(globalJsonPath, jsonContents);
}
const version = ['3.1'];
const version = '3.1';
const installer = new dotnetInstaller.DotnetCoreInstaller(version);
const patchVersion = await installer.resolveVersion(
new dotnetInstaller.DotNetVersionInfo(version[0])
new dotnetInstaller.DotNetVersionInfo(version)
);
await setup.run();

View File

@ -78,7 +78,7 @@ describe('version tests', () => {
);
it('Resolving a nonexistent generic version fails', async () => {
const dotnetInstaller = new installer.DotnetCoreInstaller(['999.1.x']);
const dotnetInstaller = new installer.DotnetCoreInstaller('999.1.x');
try {
await dotnetInstaller.resolveVersion(
new installer.DotNetVersionInfo('999.1.x')

151
dist/index.js vendored
View File

@ -8686,8 +8686,11 @@ function run() {
if (versions) {
const includePrerelease = (core.getInput('include-prerelease') || 'false').toLowerCase() ===
'true';
const dotnetInstaller = new installer.DotnetCoreInstaller(versions, includePrerelease);
yield dotnetInstaller.installDotnet();
let dotnetInstaller;
for (const version of versions) {
dotnetInstaller = new installer.DotnetCoreInstaller(version, includePrerelease);
yield dotnetInstaller.installDotnet();
}
}
const sourceUrl = core.getInput('source-url');
const configFile = core.getInput('config-file');
@ -17963,13 +17966,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __asyncValues = (this && this.__asyncValues) || function (o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DotnetCoreInstaller = exports.DotNetVersionInfo = void 0;
// Load tempDirectory before it gets wiped by tool-cache
@ -18035,90 +18031,77 @@ class DotNetVersionInfo {
}
exports.DotNetVersionInfo = DotNetVersionInfo;
class DotnetCoreInstaller {
constructor(versions, includePrerelease = false) {
this.versions = versions;
constructor(version, includePrerelease = false) {
this.version = version;
this.includePrerelease = includePrerelease;
}
installDotnet() {
var e_1, _a;
return __awaiter(this, void 0, void 0, function* () {
let output = '';
let resultCode = 0;
try {
for (var _b = __asyncValues(this.versions), _c; _c = yield _b.next(), !_c.done;) {
const version = _c.value;
let calculatedVersion = yield this.resolveVersion(new DotNetVersionInfo(version));
var envVariables = {};
for (let key in process.env) {
if (process.env[key]) {
let value = process.env[key];
envVariables[key] = value;
}
}
if (IS_WINDOWS) {
let escapedScript = path
.join(__dirname, '..', 'externals', 'install-dotnet.ps1')
.replace(/'/g, "''");
let command = `& '${escapedScript}'`;
if (calculatedVersion) {
command += ` -Version ${calculatedVersion}`;
}
if (process.env['https_proxy'] != null) {
command += ` -ProxyAddress ${process.env['https_proxy']}`;
}
// This is not currently an option
if (process.env['no_proxy'] != null) {
command += ` -ProxyBypassList ${process.env['no_proxy']}`;
}
// process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
const powershellPath = yield io.which('powershell', true);
var options = {
listeners: {
stdout: (data) => {
output += data.toString();
}
},
env: envVariables
};
resultCode = yield exec.exec(`"${powershellPath}"`, [
'-NoLogo',
'-Sta',
'-NoProfile',
'-NonInteractive',
'-ExecutionPolicy',
'Unrestricted',
'-Command',
command
], options);
}
else {
let escapedScript = path
.join(__dirname, '..', 'externals', 'install-dotnet.sh')
.replace(/'/g, "''");
fs_1.chmodSync(escapedScript, '777');
const scriptPath = yield io.which(escapedScript, true);
let scriptArguments = [];
if (calculatedVersion) {
scriptArguments.push('--version', calculatedVersion);
}
// process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
resultCode = yield exec.exec(`"${scriptPath}"`, scriptArguments, {
listeners: {
stdout: (data) => {
output += data.toString();
}
},
env: envVariables
});
}
let calculatedVersion = yield this.resolveVersion(new DotNetVersionInfo(this.version));
var envVariables = {};
for (let key in process.env) {
if (process.env[key]) {
let value = process.env[key];
envVariables[key] = value;
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b);
if (IS_WINDOWS) {
let escapedScript = path
.join(__dirname, '..', 'externals', 'install-dotnet.ps1')
.replace(/'/g, "''");
let command = `& '${escapedScript}'`;
if (calculatedVersion) {
command += ` -Version ${calculatedVersion}`;
}
finally { if (e_1) throw e_1.error; }
if (process.env['https_proxy'] != null) {
command += ` -ProxyAddress ${process.env['https_proxy']}`;
}
// This is not currently an option
if (process.env['no_proxy'] != null) {
command += ` -ProxyBypassList ${process.env['no_proxy']}`;
}
// process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
const powershellPath = yield io.which('powershell', true);
var options = {
listeners: {
stdout: (data) => {
output += data.toString();
}
},
env: envVariables
};
resultCode = yield exec.exec(`"${powershellPath}"`, [
'-NoLogo',
'-Sta',
'-NoProfile',
'-NonInteractive',
'-ExecutionPolicy',
'Unrestricted',
'-Command',
command
], options);
}
else {
let escapedScript = path
.join(__dirname, '..', 'externals', 'install-dotnet.sh')
.replace(/'/g, "''");
fs_1.chmodSync(escapedScript, '777');
const scriptPath = yield io.which(escapedScript, true);
let scriptArguments = [];
if (calculatedVersion) {
scriptArguments.push('--version', calculatedVersion);
}
// process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
resultCode = yield exec.exec(`"${scriptPath}"`, scriptArguments, {
listeners: {
stdout: (data) => {
output += data.toString();
}
},
env: envVariables
});
}
if (process.env['DOTNET_INSTALL_DIR']) {
core.addPath(process.env['DOTNET_INSTALL_DIR']);

View File

@ -79,8 +79,8 @@ export class DotNetVersionInfo {
}
export class DotnetCoreInstaller {
constructor(versions: string[], includePrerelease: boolean = false) {
this.versions = versions;
constructor(version: string, includePrerelease: boolean = false) {
this.version = version;
this.includePrerelease = includePrerelease;
}
@ -88,83 +88,81 @@ export class DotnetCoreInstaller {
let output = '';
let resultCode = 0;
for await (const version of this.versions) {
let calculatedVersion = await this.resolveVersion(
new DotNetVersionInfo(version)
let calculatedVersion = await this.resolveVersion(
new DotNetVersionInfo(this.version)
);
var envVariables: {[key: string]: string} = {};
for (let key in process.env) {
if (process.env[key]) {
let value: any = process.env[key];
envVariables[key] = value;
}
}
if (IS_WINDOWS) {
let escapedScript = path
.join(__dirname, '..', 'externals', 'install-dotnet.ps1')
.replace(/'/g, "''");
let command = `& '${escapedScript}'`;
if (calculatedVersion) {
command += ` -Version ${calculatedVersion}`;
}
if (process.env['https_proxy'] != null) {
command += ` -ProxyAddress ${process.env['https_proxy']}`;
}
// This is not currently an option
if (process.env['no_proxy'] != null) {
command += ` -ProxyBypassList ${process.env['no_proxy']}`;
}
// process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
const powershellPath = await io.which('powershell', true);
var options: ExecOptions = {
listeners: {
stdout: (data: Buffer) => {
output += data.toString();
}
},
env: envVariables
};
resultCode = await exec.exec(
`"${powershellPath}"`,
[
'-NoLogo',
'-Sta',
'-NoProfile',
'-NonInteractive',
'-ExecutionPolicy',
'Unrestricted',
'-Command',
command
],
options
);
} else {
let escapedScript = path
.join(__dirname, '..', 'externals', 'install-dotnet.sh')
.replace(/'/g, "''");
chmodSync(escapedScript, '777');
var envVariables: {[key: string]: string} = {};
for (let key in process.env) {
if (process.env[key]) {
let value: any = process.env[key];
envVariables[key] = value;
}
const scriptPath = await io.which(escapedScript, true);
let scriptArguments: string[] = [];
if (calculatedVersion) {
scriptArguments.push('--version', calculatedVersion);
}
if (IS_WINDOWS) {
let escapedScript = path
.join(__dirname, '..', 'externals', 'install-dotnet.ps1')
.replace(/'/g, "''");
let command = `& '${escapedScript}'`;
if (calculatedVersion) {
command += ` -Version ${calculatedVersion}`;
}
if (process.env['https_proxy'] != null) {
command += ` -ProxyAddress ${process.env['https_proxy']}`;
}
// This is not currently an option
if (process.env['no_proxy'] != null) {
command += ` -ProxyBypassList ${process.env['no_proxy']}`;
}
// process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
const powershellPath = await io.which('powershell', true);
var options: ExecOptions = {
listeners: {
stdout: (data: Buffer) => {
output += data.toString();
}
},
env: envVariables
};
resultCode = await exec.exec(
`"${powershellPath}"`,
[
'-NoLogo',
'-Sta',
'-NoProfile',
'-NonInteractive',
'-ExecutionPolicy',
'Unrestricted',
'-Command',
command
],
options
);
} else {
let escapedScript = path
.join(__dirname, '..', 'externals', 'install-dotnet.sh')
.replace(/'/g, "''");
chmodSync(escapedScript, '777');
const scriptPath = await io.which(escapedScript, true);
let scriptArguments: string[] = [];
if (calculatedVersion) {
scriptArguments.push('--version', calculatedVersion);
}
// process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
resultCode = await exec.exec(`"${scriptPath}"`, scriptArguments, {
listeners: {
stdout: (data: Buffer) => {
output += data.toString();
}
},
env: envVariables
});
}
// process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
resultCode = await exec.exec(`"${scriptPath}"`, scriptArguments, {
listeners: {
stdout: (data: Buffer) => {
output += data.toString();
}
},
env: envVariables
});
}
if (process.env['DOTNET_INSTALL_DIR']) {
core.addPath(process.env['DOTNET_INSTALL_DIR']);
@ -287,7 +285,7 @@ export class DotnetCoreInstaller {
return releasesInfo[0]['releases.json'];
}
private versions: string[];
private version: string;
private includePrerelease: boolean;
}

View File

@ -27,12 +27,14 @@ export async function run() {
const includePrerelease: boolean =
(core.getInput('include-prerelease') || 'false').toLowerCase() ===
'true';
const dotnetInstaller = new installer.DotnetCoreInstaller(
versions,
includePrerelease
);
await dotnetInstaller.installDotnet();
let dotnetInstaller: installer.DotnetCoreInstaller;
for (const version of versions) {
dotnetInstaller = new installer.DotnetCoreInstaller(
version,
includePrerelease
);
await dotnetInstaller.installDotnet();
}
}
const sourceUrl: string = core.getInput('source-url');