Add architecture option.

This commit is contained in:
Reegeek 2020-12-02 10:45:10 +01:00
parent 8336fd394b
commit defd795883
4 changed files with 43 additions and 7 deletions

View File

@ -30,6 +30,17 @@ steps:
- run: dotnet build <my project> - run: dotnet build <my project>
``` ```
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 <my project>
```
Matrix Testing: Matrix Testing:
```yaml ```yaml
jobs: jobs:

View File

@ -33,7 +33,7 @@ describe('installer tests', () => {
}, 30000); }, 30000);
it('Acquires version of dotnet if no matching version is installed', async () => { 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); expect(fs.existsSync(path.join(toolDir, 'sdk', '3.1.201'))).toBe(true);
if (IS_WINDOWS) { if (IS_WINDOWS) {
expect(fs.existsSync(path.join(toolDir, 'dotnet.exe'))).toBe(true); 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 }, 600000); //This needs some time to download on "slower" internet connections
it('Acquires generic version of dotnet if no matching version is installed', async () => { 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 var directory = fs
.readdirSync(path.join(toolDir, 'sdk')) .readdirSync(path.join(toolDir, 'sdk'))
.filter(fn => fn.startsWith('3.1.')); .filter(fn => fn.startsWith('3.1.'));
@ -65,10 +65,28 @@ describe('installer tests', () => {
expect(process.env.PATH?.startsWith(toolDir)).toBe(true); expect(process.env.PATH?.startsWith(toolDir)).toBe(true);
}, 600000); //This needs some time to download on "slower" internet connections }, 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 () => { it('Throws if no location contains correct dotnet version', async () => {
let thrown = false; let thrown = false;
try { try {
await getDotnet('1000.0.0'); await getDotnet('1000.0.0', null);
} catch { } catch {
thrown = true; thrown = true;
} }
@ -123,7 +141,7 @@ function normalizeFileContents(contents: string): string {
.replace(new RegExp('\r', 'g'), '\n'); .replace(new RegExp('\r', 'g'), '\n');
} }
async function getDotnet(version: string): Promise<void> { async function getDotnet(version: string, architecture: string): Promise<void> {
const dotnetInstaller = new installer.DotnetCoreInstaller(version); const dotnetInstaller = new installer.DotnetCoreInstaller(version, architecture);
await dotnetInstaller.installDotnet(); await dotnetInstaller.installDotnet();
} }

View File

@ -76,8 +76,9 @@ export class DotNetVersionInfo {
} }
export class DotnetCoreInstaller { export class DotnetCoreInstaller {
constructor(version: string) { constructor(version: string, architecture:string) {
this.version = version; this.version = version;
this.architecture = architecture;
} }
public async installDotnet() { public async installDotnet() {
@ -150,6 +151,10 @@ export class DotnetCoreInstaller {
scriptArguments.push('--version', calculatedVersion); 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 // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
resultCode = await exec.exec(`"${scriptPath}"`, scriptArguments, { resultCode = await exec.exec(`"${scriptPath}"`, scriptArguments, {
listeners: { listeners: {
@ -273,6 +278,7 @@ export class DotnetCoreInstaller {
} }
private version: string; private version: string;
private architecture: string;
} }
const DotNetCoreIndexUrl: string = const DotNetCoreIndexUrl: string =

View File

@ -14,6 +14,7 @@ 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');
let architecture = core.getInput('dotnet-architecture');
if (!version) { if (!version) {
// 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');
@ -29,7 +30,7 @@ export async function run() {
} }
if (version) { if (version) {
const dotnetInstaller = new installer.DotnetCoreInstaller(version); const dotnetInstaller = new installer.DotnetCoreInstaller(version, architecture);
await dotnetInstaller.installDotnet(); await dotnetInstaller.installDotnet();
} }