diff --git a/README.md b/README.md index a8656e0..3e822b9 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,16 @@ steps: include-prerelease: true - run: dotnet build ``` +Specific architecture: +```yml +steps: +- uses: actions/checkout@v3 +- uses: actions/setup-dotnet@v2 + with: + dotnet-version: '6.0.x' + architecture: 'x86' +- run: dotnet build +``` global.json in a subdirectory: ```yml steps: diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index 532da18..b5ad51d 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -86,6 +86,26 @@ describe('installer tests', () => { expect(process.env.PATH?.startsWith(toolDir)).toBe(true); }, 600000); //This needs some time to download on "slower" internet connections + + it('Acquires architecture-specific 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 { @@ -144,8 +164,8 @@ 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(); installer.DotnetCoreInstaller.addToPath(); } diff --git a/src/installer.ts b/src/installer.ts index c25d23a..53b2871 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -79,8 +79,9 @@ export class DotNetVersionInfo { } export class DotnetCoreInstaller { - constructor(version: string, includePrerelease: boolean = false) { + constructor(version: string, architecture:string = '', includePrerelease: boolean = false) { this.version = version; + this.architecture = architecture; this.includePrerelease = includePrerelease; } @@ -115,6 +116,10 @@ export class DotnetCoreInstaller { command += ` -ProxyBypassList ${process.env['no_proxy']}`; } + if (this.architecture != ''){ + command += ` -Architecture ${this.architecture}`; + } + // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used const powershellPath = await io.which('powershell', true); @@ -154,6 +159,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: { @@ -296,6 +305,7 @@ export class DotnetCoreInstaller { } private version: string; + private architecture: string; private includePrerelease: boolean; } diff --git a/src/setup-dotnet.ts b/src/setup-dotnet.ts index 64f3149..2768ec0 100644 --- a/src/setup-dotnet.ts +++ b/src/setup-dotnet.ts @@ -16,6 +16,11 @@ export async function run() { // Proxy, auth, (etc) are still set up, even if no version is identified // let versions = core.getMultilineInput('dotnet-version'); + let architecture = core.getInput('architecture'); + + if (!architecture){ + architecture = ''; + } const globalJsonFileInput = core.getInput('global-json-file'); if (globalJsonFileInput) { @@ -45,6 +50,7 @@ export async function run() { for (const version of new Set(versions)) { dotnetInstaller = new installer.DotnetCoreInstaller( version, + architecture, includePrerelease ); await dotnetInstaller.installDotnet();