Add an optional architecture parameter to set the target architecture (x86, x64, arm64, ...).

This commit is contained in:
Kevin Gosse 2022-10-21 16:22:30 +02:00
parent 4d4a70f4a5
commit 2f8de776e1
5 changed files with 48 additions and 3 deletions

View File

@ -28,6 +28,17 @@ steps:
- 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>
```
**Multiple version installation**:
```yml
steps:

View File

@ -107,6 +107,24 @@ describe('DotnetCoreInstaller 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', '', 'x64');
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('Returns string with installed SDK version', async () => {
const version = '3.1.120';
let installedVersion: string;
@ -279,10 +297,12 @@ function normalizeFileContents(contents: string): string {
async function getDotnet(
version: string,
quality: string = ''
architecture: string = ''
): Promise<string> {
const dotnetInstaller = new installer.DotnetCoreInstaller(
version,
quality as QualityOptions
quality as QualityOptions,
architecture
);
const installedVersion = await dotnetInstaller.installDotnet();
installer.DotnetCoreInstaller.addToPath();

View File

@ -17,6 +17,9 @@ inputs:
description: 'Optional OWNER for using packages from GitHub Package Registry organizations/users other than the current repository''s owner. Only used if a GPR URL is also provided in source-url'
config-file:
description: 'Optional NuGet.config location, if your NuGet.config isn''t located in the root of the repo.'
architecture:
description: 'Optional architecture to use. If not provided, will default to the OS architecture.'
required: False
outputs:
dotnet-version:
description: 'Contains the installed by action .NET SDK version for reuse.'

View File

@ -20,9 +20,11 @@ export interface DotnetVersion {
export class DotnetVersionResolver {
private inputVersion: string;
private resolvedArgument: DotnetVersion;
private architecture: string;
constructor(version: string) {
constructor(version: string, architecture: string = '') {
this.inputVersion = version.trim();
this.architecture = architecture;
this.resolvedArgument = {type: '', value: '', qualityFlag: false};
}
@ -230,6 +232,10 @@ export class DotnetCoreInstaller {
if (this.quality) {
this.setQuality(dotnetVersion, scriptArguments);
}
if (this.architecture != '') {
scriptArguments.push('--architecture', this.architecture);
}
}
// process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
const getExecOutputOptions = {

View File

@ -28,6 +28,11 @@ export async function run() {
//
const versions = core.getMultilineInput('dotnet-version');
const installedDotnetVersions: string[] = [];
let architecture = core.getInput('architecture');
if (!architecture) {
architecture = '';
}
const globalJsonFileInput = core.getInput('global-json-file');
if (globalJsonFileInput) {
@ -61,7 +66,7 @@ export async function run() {
let dotnetInstaller: DotnetCoreInstaller;
const uniqueVersions = new Set<string>(versions);
for (const version of uniqueVersions) {
dotnetInstaller = new DotnetCoreInstaller(version, quality);
dotnetInstaller = new DotnetCoreInstaller(version, quality, architecture);
const installedVersion = await dotnetInstaller.installDotnet();
installedDotnetVersions.push(installedVersion);
}