From defd795883e5a0ba2e0a20cdb6f695a6a1aaf24c Mon Sep 17 00:00:00 2001 From: Reegeek <10356780+reegeek@users.noreply.github.com> Date: Wed, 2 Dec 2020 10:45:10 +0100 Subject: [PATCH] Add architecture option. --- README.md | 11 +++++++++++ __tests__/installer.test.ts | 28 +++++++++++++++++++++++----- src/installer.ts | 8 +++++++- src/setup-dotnet.ts | 3 ++- 4 files changed, 43 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 66af02f..045d161 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,17 @@ steps: - run: dotnet build ``` +Architecture: +```yaml +steps: +- uses: actions/checkout@main +- uses: actions/setup-dotnet@v1 + with: + dotnet-version: '3.1.x' # SDK Version to use; x will use the latest version of the 3.1 channel + dotnet-achitecture: 'x86' +- run: dotnet build +``` + Matrix Testing: ```yaml jobs: diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index a7db4ea..c01ff95 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -33,7 +33,7 @@ describe('installer tests', () => { }, 30000); it('Acquires version of dotnet if no matching version is installed', async () => { - await getDotnet('3.1.201'); + await getDotnet('3.1.201', null); 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); @@ -48,7 +48,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', null); var directory = fs .readdirSync(path.join(toolDir, 'sdk')) .filter(fn => fn.startsWith('3.1.')); @@ -65,10 +65,28 @@ describe('installer tests', () => { expect(process.env.PATH?.startsWith(toolDir)).toBe(true); }, 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', 'x86'); + var directory = fs + .readdirSync(path.join(toolDir, 'sdk')) + .filter(fn => fn.startsWith('3.1.')) + expect(directory.length > 0).toBe(true); + if (IS_WINDOWS) { + expect(fs.existsSync(path.join(toolDir, 'dotnet.exe'))).toBe(true); + } else { + expect(fs.existsSync(path.join(toolDir, 'dotnet'))).toBe(true); + } + + expect(process.env.DOTNET_ROOT).toBeDefined; + expect(process.env.PATH).toBeDefined; + expect(process.env.DOTNET_ROOT).toBe(toolDir); + expect(process.env.PATH?.startsWith(toolDir)).toBe(true); + }, 600000); //This needs some time to download on "slower" internet connections + it('Throws if no location contains correct dotnet version', async () => { let thrown = false; try { - await getDotnet('1000.0.0'); + await getDotnet('1000.0.0', null); } catch { thrown = true; } @@ -123,7 +141,7 @@ function normalizeFileContents(contents: string): string { .replace(new RegExp('\r', 'g'), '\n'); } -async function getDotnet(version: string): Promise { - const dotnetInstaller = new installer.DotnetCoreInstaller(version); +async function getDotnet(version: string, architecture: string): Promise { + const dotnetInstaller = new installer.DotnetCoreInstaller(version, architecture); await dotnetInstaller.installDotnet(); } diff --git a/src/installer.ts b/src/installer.ts index f0b48a2..1523100 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -76,8 +76,9 @@ export class DotNetVersionInfo { } export class DotnetCoreInstaller { - constructor(version: string) { + constructor(version: string, architecture:string) { this.version = version; + this.architecture = architecture; } public async installDotnet() { @@ -150,6 +151,10 @@ export class DotnetCoreInstaller { scriptArguments.push('--version', calculatedVersion); } + if (this.architecture) { + scriptArguments.push('--architecture', this.architecture); + } + // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used resultCode = await exec.exec(`"${scriptPath}"`, scriptArguments, { listeners: { @@ -273,6 +278,7 @@ export class DotnetCoreInstaller { } private version: string; + private architecture: string; } const DotNetCoreIndexUrl: string = diff --git a/src/setup-dotnet.ts b/src/setup-dotnet.ts index ec804eb..1fa4164 100644 --- a/src/setup-dotnet.ts +++ b/src/setup-dotnet.ts @@ -14,6 +14,7 @@ export async function run() { // Proxy, auth, (etc) are still set up, even if no version is identified // let version = core.getInput('dotnet-version'); + let architecture = core.getInput('dotnet-architecture'); if (!version) { // Try to fall back to global.json core.debug('No version found, trying to find version from global.json'); @@ -29,7 +30,7 @@ export async function run() { } if (version) { - const dotnetInstaller = new installer.DotnetCoreInstaller(version); + const dotnetInstaller = new installer.DotnetCoreInstaller(version, architecture); await dotnetInstaller.installDotnet(); }