mirror of
https://github.com/actions/setup-dotnet.git
synced 2025-08-20 23:50:19 +00:00
* 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:
parent
fef7aa8f03
commit
c810925597
4
.github/workflows/workflow.yml
vendored
4
.github/workflows/workflow.yml
vendored
@ -48,7 +48,9 @@ jobs:
|
|||||||
- name: Setup dotnet 2.2.402 and 3.1.404
|
- name: Setup dotnet 2.2.402 and 3.1.404
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
dotnet-version: '2.2.402,3.1.404'
|
dotnet-version: |
|
||||||
|
2.2.402
|
||||||
|
3.1.404
|
||||||
- name: Verify dotnet
|
- name: Verify dotnet
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
run: __tests__/verify-dotnet.ps1 2.2.402 3.1.404
|
run: __tests__/verify-dotnet.ps1 2.2.402 3.1.404
|
||||||
|
@ -36,7 +36,9 @@ steps:
|
|||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-dotnet@v1
|
- uses: actions/setup-dotnet@v1
|
||||||
with:
|
with:
|
||||||
dotnet-version: '2.2.207 , 3.1.20'
|
dotnet-version: |
|
||||||
|
3.1.20
|
||||||
|
2.2.207
|
||||||
- run: dotnet build <my project>
|
- run: dotnet build <my project>
|
||||||
```
|
```
|
||||||
Preview version:
|
Preview version:
|
||||||
|
@ -33,7 +33,8 @@ describe('installer tests', () => {
|
|||||||
}, 30000);
|
}, 30000);
|
||||||
|
|
||||||
it('Aquires multiple versions of dotnet', async () => {
|
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', '2.2.207'))).toBe(true);
|
||||||
expect(fs.existsSync(path.join(toolDir, 'sdk', '3.1.120'))).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);
|
const dotnetInstaller = new installer.DotnetCoreInstaller(version);
|
||||||
await dotnetInstaller.installDotnet();
|
await dotnetInstaller.installDotnet();
|
||||||
}
|
}
|
||||||
|
async function getDotnetVersions(versions: string[]): Promise<void> {
|
||||||
|
const dotnetInstaller = new installer.DotnetCoreInstaller('', versions);
|
||||||
|
await dotnetInstaller.installDotnetVersions();
|
||||||
|
}
|
||||||
|
@ -6,7 +6,9 @@ branding:
|
|||||||
color: green
|
color: green
|
||||||
inputs:
|
inputs:
|
||||||
dotnet-version:
|
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:
|
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'
|
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:
|
owner:
|
||||||
|
1415
dist/index.js
vendored
1415
dist/index.js
vendored
File diff suppressed because it is too large
Load Diff
22
package-lock.json
generated
22
package-lock.json
generated
@ -5,9 +5,22 @@
|
|||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": {
|
"@actions/core": {
|
||||||
"version": "1.2.6",
|
"version": "1.6.0",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.6.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.6.0.tgz",
|
||||||
"integrity": "sha512-ZQYitnqiyBc3D+k7LsgSBmMDVkOVidaagDG7j3fOym77jNunWRuYx7VSHa9GNfFZh+zh61xsCjRj4JxMZlDqTA=="
|
"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": {
|
"@actions/exec": {
|
||||||
"version": "1.0.4",
|
"version": "1.0.4",
|
||||||
@ -3432,8 +3445,7 @@
|
|||||||
"tunnel": {
|
"tunnel": {
|
||||||
"version": "0.0.6",
|
"version": "0.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz",
|
||||||
"integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==",
|
"integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"type-check": {
|
"type-check": {
|
||||||
"version": "0.3.2",
|
"version": "0.3.2",
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
"author": "GitHub",
|
"author": "GitHub",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.2.6",
|
"@actions/core": "^1.6.0",
|
||||||
"@actions/exec": "^1.0.4",
|
"@actions/exec": "^1.0.4",
|
||||||
"@actions/github": "^1.1.0",
|
"@actions/github": "^1.1.0",
|
||||||
"@actions/http-client": "^1.0.8",
|
"@actions/http-client": "^1.0.8",
|
||||||
|
121
src/installer.ts
121
src/installer.ts
@ -79,8 +79,13 @@ export class DotNetVersionInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class DotnetCoreInstaller {
|
export class DotnetCoreInstaller {
|
||||||
constructor(version: string, includePrerelease: boolean = false) {
|
constructor(
|
||||||
|
version: string,
|
||||||
|
versions: string[] = [],
|
||||||
|
includePrerelease: boolean = false
|
||||||
|
) {
|
||||||
this.version = version;
|
this.version = version;
|
||||||
|
this.versions = versions;
|
||||||
this.includePrerelease = includePrerelease;
|
this.includePrerelease = includePrerelease;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,12 +93,116 @@ export class DotnetCoreInstaller {
|
|||||||
let output = '';
|
let output = '';
|
||||||
let resultCode = 0;
|
let resultCode = 0;
|
||||||
|
|
||||||
if (this.version.includes(',')) {
|
let calculatedVersion = await this.resolveVersion(
|
||||||
this.versions = this.version.split(',');
|
new DotNetVersionInfo(this.version)
|
||||||
} else {
|
);
|
||||||
this.versions.push(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');
|
||||||
|
|
||||||
|
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) {
|
for await (const version of this.versions) {
|
||||||
let calculatedVersion = await this.resolveVersion(
|
let calculatedVersion = await this.resolveVersion(
|
||||||
new DotNetVersionInfo(version.trim())
|
new DotNetVersionInfo(version.trim())
|
||||||
@ -295,7 +404,7 @@ export class DotnetCoreInstaller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private version: string;
|
private version: string;
|
||||||
private versions: string[] = [];
|
private versions: string[];
|
||||||
private includePrerelease: boolean;
|
private includePrerelease: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,8 @@ export async function run() {
|
|||||||
// Proxy, auth, (etc) are still set up, even if no version is identified
|
// Proxy, auth, (etc) are still set up, even if no version is identified
|
||||||
//
|
//
|
||||||
let version = core.getInput('dotnet-version');
|
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
|
// Try to fall back to global.json
|
||||||
core.debug('No version found, trying to find version from global.json');
|
core.debug('No version found, trying to find version from global.json');
|
||||||
const globalJsonPath = path.join(process.cwd(), 'global.json');
|
const globalJsonPath = path.join(process.cwd(), 'global.json');
|
||||||
@ -22,7 +23,23 @@ export async function run() {
|
|||||||
version = getVersionFromGlobalJson(globalJsonPath);
|
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) {
|
if (version) {
|
||||||
const includePrerelease: boolean =
|
const includePrerelease: boolean =
|
||||||
(core.getInput('include-prerelease') || 'false').toLowerCase() ===
|
(core.getInput('include-prerelease') || 'false').toLowerCase() ===
|
||||||
@ -30,6 +47,7 @@ export async function run() {
|
|||||||
|
|
||||||
const dotnetInstaller = new installer.DotnetCoreInstaller(
|
const dotnetInstaller = new installer.DotnetCoreInstaller(
|
||||||
version,
|
version,
|
||||||
|
[],
|
||||||
includePrerelease
|
includePrerelease
|
||||||
);
|
);
|
||||||
await dotnetInstaller.installDotnet();
|
await dotnetInstaller.installDotnet();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user