Add support for optional architecture input for cross-architecture .NET installs (#700)

* fix basic validation with npm command

* Revert "fix basic validation with npm command"

This reverts commit 27a0803a2a.

* add architecture support

* updated installdir logic

* update architecture resolution

* update normalizeArch
This commit is contained in:
priya-kinthali
2026-02-27 00:47:54 +05:30
committed by GitHub
parent 16c7b3c2fa
commit 02574b18e2
8 changed files with 401 additions and 8 deletions

View File

@@ -1,9 +1,14 @@
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import {DotnetCoreInstaller, DotnetInstallDir} from './installer';
import {
DotnetCoreInstaller,
DotnetInstallDir,
normalizeArch
} from './installer';
import * as fs from 'fs';
import path from 'path';
import semver from 'semver';
import os from 'os';
import * as auth from './authutil';
import {isCacheFeatureAvailable} from './cache-utils';
import {restoreCache} from './cache-restore';
@@ -17,6 +22,17 @@ const qualityOptions = [
'preview',
'ga'
] as const;
const supportedArchitectures = [
'x64',
'x86',
'arm64',
'amd64',
'arm',
's390x',
'ppc64le',
'riscv64'
] as const;
type SupportedArchitecture = (typeof supportedArchitectures)[number];
export type QualityOptions = (typeof qualityOptions)[number];
@@ -33,6 +49,7 @@ export async function run() {
//
const versions = core.getMultilineInput('dotnet-version');
const installedDotnetVersions: (string | null)[] = [];
const architecture = getArchitectureInput();
const globalJsonFileInput = core.getInput('global-json-file');
if (globalJsonFileInput) {
@@ -70,10 +87,23 @@ 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);
}
if (
architecture &&
normalizeArch(architecture) !== normalizeArch(os.arch())
) {
process.env['DOTNET_INSTALL_DIR'] = path.join(
DotnetInstallDir.dirPath,
architecture
);
}
DotnetInstallDir.addToPath();
const workloadsInput = core.getInput('workloads');
@@ -119,6 +149,20 @@ export async function run() {
}
}
function getArchitectureInput(): SupportedArchitecture | '' {
const raw = (core.getInput('architecture') || '').trim();
if (!raw) return '';
const normalized = raw.toLowerCase();
if ((supportedArchitectures as readonly string[]).includes(normalized)) {
return normalizeArch(normalized) as SupportedArchitecture;
}
throw new Error(
`Value '${raw}' is not supported for the 'architecture' option. Supported values are: ${supportedArchitectures.join(
', '
)}.`
);
}
function getVersionFromGlobalJson(globalJsonPath: string): string {
let version = '';
const globalJson = JSON5.parse(