Add a way to force the architecture

This commit is contained in:
Kevin Gosse 2022-06-22 15:36:47 +02:00
parent c0d4ad69d8
commit 90312b694f
4 changed files with 49 additions and 3 deletions

View File

@ -51,6 +51,16 @@ steps:
include-prerelease: true include-prerelease: true
- run: dotnet build <my project> - run: dotnet build <my project>
``` ```
Specific architecture:
```yml
steps:
- uses: actions/checkout@v3
- uses: actions/setup-dotnet@v2
with:
dotnet-version: '6.0.x'
architecture: 'x86'
- run: dotnet build <my project>
```
global.json in a subdirectory: global.json in a subdirectory:
```yml ```yml
steps: steps:

View File

@ -86,6 +86,26 @@ 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 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 () => { it('Throws if no location contains correct dotnet version', async () => {
let thrown = false; let thrown = false;
try { try {
@ -144,8 +164,8 @@ 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();
installer.DotnetCoreInstaller.addToPath(); installer.DotnetCoreInstaller.addToPath();
} }

View File

@ -79,8 +79,9 @@ export class DotNetVersionInfo {
} }
export class DotnetCoreInstaller { export class DotnetCoreInstaller {
constructor(version: string, includePrerelease: boolean = false) { constructor(version: string, architecture:string = '', includePrerelease: boolean = false) {
this.version = version; this.version = version;
this.architecture = architecture;
this.includePrerelease = includePrerelease; this.includePrerelease = includePrerelease;
} }
@ -115,6 +116,10 @@ export class DotnetCoreInstaller {
command += ` -ProxyBypassList ${process.env['no_proxy']}`; 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 // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
const powershellPath = await io.which('powershell', true); const powershellPath = await io.which('powershell', true);
@ -154,6 +159,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: {
@ -296,6 +305,7 @@ export class DotnetCoreInstaller {
} }
private version: string; private version: string;
private architecture: string;
private includePrerelease: boolean; private includePrerelease: boolean;
} }

View File

@ -16,6 +16,11 @@ 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 versions = core.getMultilineInput('dotnet-version'); let versions = core.getMultilineInput('dotnet-version');
let architecture = core.getInput('architecture');
if (!architecture){
architecture = '';
}
const globalJsonFileInput = core.getInput('global-json-file'); const globalJsonFileInput = core.getInput('global-json-file');
if (globalJsonFileInput) { if (globalJsonFileInput) {
@ -45,6 +50,7 @@ export async function run() {
for (const version of new Set<string>(versions)) { for (const version of new Set<string>(versions)) {
dotnetInstaller = new installer.DotnetCoreInstaller( dotnetInstaller = new installer.DotnetCoreInstaller(
version, version,
architecture,
includePrerelease includePrerelease
); );
await dotnetInstaller.installDotnet(); await dotnetInstaller.installDotnet();