* updated @action/core to latest for support for multiline input

* Added seperate input for multiple versions and subsequent logic to handle
  multiple versions from new input
* updated test  for multiple versions logic in installer.test
*Updated README
This commit is contained in:
La'Kaleigh Harris 2021-10-27 18:11:52 +00:00 committed by GitHub
parent fef7aa8f03
commit c810925597
9 changed files with 1506 additions and 101 deletions

View File

@ -48,7 +48,9 @@ jobs:
- name: Setup dotnet 2.2.402 and 3.1.404
uses: ./
with:
dotnet-version: '2.2.402,3.1.404'
dotnet-version: |
2.2.402
3.1.404
- name: Verify dotnet
shell: pwsh
run: __tests__/verify-dotnet.ps1 2.2.402 3.1.404

View File

@ -36,7 +36,9 @@ steps:
- uses: actions/checkout@v2
- uses: actions/setup-dotnet@v1
with:
dotnet-version: '2.2.207 , 3.1.20'
dotnet-version: |
3.1.20
2.2.207
- run: dotnet build <my project>
```
Preview version:

View File

@ -33,7 +33,8 @@ describe('installer tests', () => {
}, 30000);
it('Aquires multiple versions of dotnet', async () => {
await getDotnet('2.2.207,3.1.120');
const versions = ['2.2.207', '3.1.120'];
await getDotnetVersions(versions);
expect(fs.existsSync(path.join(toolDir, 'sdk', '2.2.207'))).toBe(true);
expect(fs.existsSync(path.join(toolDir, 'sdk', '3.1.120'))).toBe(true);
@ -144,3 +145,7 @@ async function getDotnet(version: string): Promise<void> {
const dotnetInstaller = new installer.DotnetCoreInstaller(version);
await dotnetInstaller.installDotnet();
}
async function getDotnetVersions(versions: string[]): Promise<void> {
const dotnetInstaller = new installer.DotnetCoreInstaller('', versions);
await dotnetInstaller.installDotnetVersions();
}

View File

@ -6,7 +6,9 @@ branding:
color: green
inputs:
dotnet-version:
description: 'Optional SDK version(s) to use. If not provided, will install global.json version when available. Examples: 2.2.104, 3.1, 3.1.x'
description: 'Optional SDK version to use. If not provided, will install global.json version when available. Examples: 2.2.104, 3.1, 3.1.x'
dotnet-version:
description: 'Optional SDK versions to use. If not provided, action will use dotnet-version or will install global.json version when available. Examples: 2.2.104, 3.1, 3.1.x'
source-url:
description: 'Optional package source for which to set up authentication. Will consult any existing NuGet.config in the root of the repo and provide a temporary NuGet.config using the NUGET_AUTH_TOKEN environment variable as a ClearTextPassword'
owner:

1425
dist/index.js vendored

File diff suppressed because it is too large Load Diff

22
package-lock.json generated
View File

@ -5,9 +5,22 @@
"requires": true,
"dependencies": {
"@actions/core": {
"version": "1.2.6",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.6.tgz",
"integrity": "sha512-ZQYitnqiyBc3D+k7LsgSBmMDVkOVidaagDG7j3fOym77jNunWRuYx7VSHa9GNfFZh+zh61xsCjRj4JxMZlDqTA=="
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.6.0.tgz",
"integrity": "sha512-NB1UAZomZlCV/LmJqkLhNTqtKfFXJZAUPcfl/zqG7EfsQdeUJtaWO98SGbuQ3pydJ3fHl2CvI/51OKYlCYYcaw==",
"requires": {
"@actions/http-client": "^1.0.11"
},
"dependencies": {
"@actions/http-client": {
"version": "1.0.11",
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.11.tgz",
"integrity": "sha512-VRYHGQV1rqnROJqdMvGUbY/Kn8vriQe/F9HR2AlYHzmKuM/p3kjNuXhmdBfcVgsvRWTz5C5XW5xvndZrVBuAYg==",
"requires": {
"tunnel": "0.0.6"
}
}
}
},
"@actions/exec": {
"version": "1.0.4",
@ -3432,8 +3445,7 @@
"tunnel": {
"version": "0.0.6",
"resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz",
"integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==",
"dev": true
"integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg=="
},
"type-check": {
"version": "0.3.2",

View File

@ -30,7 +30,7 @@
"author": "GitHub",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.2.6",
"@actions/core": "^1.6.0",
"@actions/exec": "^1.0.4",
"@actions/github": "^1.1.0",
"@actions/http-client": "^1.0.8",

View File

@ -79,8 +79,13 @@ export class DotNetVersionInfo {
}
export class DotnetCoreInstaller {
constructor(version: string, includePrerelease: boolean = false) {
constructor(
version: string,
versions: string[] = [],
includePrerelease: boolean = false
) {
this.version = version;
this.versions = versions;
this.includePrerelease = includePrerelease;
}
@ -88,12 +93,116 @@ export class DotnetCoreInstaller {
let output = '';
let resultCode = 0;
if (this.version.includes(',')) {
this.versions = this.version.split(',');
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 {
this.versions.push(this.version);
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
});
}
if (process.env['DOTNET_INSTALL_DIR']) {
core.addPath(process.env['DOTNET_INSTALL_DIR']);
core.exportVariable('DOTNET_ROOT', process.env['DOTNET_INSTALL_DIR']);
} else {
if (IS_WINDOWS) {
// This is the default set in install-dotnet.ps1
core.addPath(
path.join(process.env['LocalAppData'] + '', 'Microsoft', 'dotnet')
);
core.exportVariable(
'DOTNET_ROOT',
path.join(process.env['LocalAppData'] + '', 'Microsoft', 'dotnet')
);
} else {
// This is the default set in install-dotnet.sh
core.addPath(path.join(process.env['HOME'] + '', '.dotnet'));
core.exportVariable(
'DOTNET_ROOT',
path.join(process.env['HOME'] + '', '.dotnet')
);
}
}
console.log(process.env['PATH']);
if (resultCode != 0) {
throw new Error(`Failed to install dotnet ${resultCode}. ${output}`);
}
}
public async installDotnetVersions() {
let output = '';
let resultCode = 0;
for await (const version of this.versions) {
let calculatedVersion = await this.resolveVersion(
new DotNetVersionInfo(version.trim())
@ -295,7 +404,7 @@ export class DotnetCoreInstaller {
}
private version: string;
private versions: string[] = [];
private versions: string[];
private includePrerelease: boolean;
}

View File

@ -14,7 +14,8 @@ export async function run() {
// Proxy, auth, (etc) are still set up, even if no version is identified
//
let version = core.getInput('dotnet-version');
if (!version) {
let versions = core.getMultilineInput('dotnet-versions');
if (!version && !versions.length) {
// Try to fall back to global.json
core.debug('No version found, trying to find version from global.json');
const globalJsonPath = path.join(process.cwd(), 'global.json');
@ -22,7 +23,23 @@ export async function run() {
version = getVersionFromGlobalJson(globalJsonPath);
}
}
if (version && versions) {
core.warning(
"Multiple version inputs have been specified, Please specify either 'dotnet-version' or 'dotnet-versions'"
);
}
if (versions && !version) {
const includePrerelease: boolean =
(core.getInput('include-prerelease') || 'false').toLowerCase() ===
'true';
const dotnetInstaller = new installer.DotnetCoreInstaller(
'',
versions,
includePrerelease
);
await dotnetInstaller.installDotnetVersions();
}
if (version) {
const includePrerelease: boolean =
(core.getInput('include-prerelease') || 'false').toLowerCase() ===
@ -30,6 +47,7 @@ export async function run() {
const dotnetInstaller = new installer.DotnetCoreInstaller(
version,
[],
includePrerelease
);
await dotnetInstaller.installDotnet();