mirror of
https://github.com/actions/setup-dotnet.git
synced 2026-03-21 22:22:17 +08:00
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:
65
dist/setup/index.js
vendored
65
dist/setup/index.js
vendored
@@ -54714,6 +54714,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.DotnetCoreInstaller = exports.DotnetInstallDir = exports.DotnetInstallScript = exports.DotnetVersionResolver = void 0;
|
||||
exports.normalizeArch = normalizeArch;
|
||||
// Load tempDirectory before it gets wiped by tool-cache
|
||||
const core = __importStar(__nccwpck_require__(42186));
|
||||
const exec = __importStar(__nccwpck_require__(71514));
|
||||
@@ -54859,6 +54860,13 @@ class DotnetInstallScript {
|
||||
this.scriptArguments.push(...args);
|
||||
return this;
|
||||
}
|
||||
// When architecture is empty/undefined, the installer auto-detects the current runner architecture.
|
||||
useArchitecture(architecture) {
|
||||
if (!architecture)
|
||||
return this;
|
||||
this.useArguments(utils_1.IS_WINDOWS ? '-Architecture' : '--architecture', architecture);
|
||||
return this;
|
||||
}
|
||||
useVersion(dotnetVersion, quality) {
|
||||
if (dotnetVersion.type) {
|
||||
this.useArguments(dotnetVersion.type, dotnetVersion.value);
|
||||
@@ -54907,30 +54915,53 @@ class DotnetInstallDir {
|
||||
}
|
||||
}
|
||||
exports.DotnetInstallDir = DotnetInstallDir;
|
||||
function normalizeArch(arch) {
|
||||
switch (arch.toLowerCase()) {
|
||||
case 'amd64':
|
||||
return 'x64';
|
||||
case 'ia32':
|
||||
return 'x86';
|
||||
default:
|
||||
return arch.toLowerCase();
|
||||
}
|
||||
}
|
||||
class DotnetCoreInstaller {
|
||||
version;
|
||||
quality;
|
||||
architecture;
|
||||
static {
|
||||
DotnetInstallDir.setEnvironmentVariable();
|
||||
}
|
||||
constructor(version, quality) {
|
||||
constructor(version, quality, architecture) {
|
||||
this.version = version;
|
||||
this.quality = quality;
|
||||
this.architecture = architecture;
|
||||
}
|
||||
async installDotnet() {
|
||||
const versionResolver = new DotnetVersionResolver(this.version);
|
||||
const dotnetVersion = await versionResolver.createDotnetVersion();
|
||||
const architectureArguments = this.architecture &&
|
||||
normalizeArch(this.architecture) !== normalizeArch(os_1.default.arch())
|
||||
? [
|
||||
utils_1.IS_WINDOWS ? '-InstallDir' : '--install-dir',
|
||||
utils_1.IS_WINDOWS
|
||||
? `"${path_1.default.join(DotnetInstallDir.dirPath, this.architecture)}"`
|
||||
: path_1.default.join(DotnetInstallDir.dirPath, this.architecture)
|
||||
]
|
||||
: [];
|
||||
/**
|
||||
* Install dotnet runitme first in order to get
|
||||
* Install dotnet runtime first in order to get
|
||||
* the latest stable version of dotnet CLI
|
||||
*/
|
||||
const runtimeInstallOutput = await new DotnetInstallScript()
|
||||
.useArchitecture(this.architecture)
|
||||
// If dotnet CLI is already installed - avoid overwriting it
|
||||
.useArguments(utils_1.IS_WINDOWS ? '-SkipNonVersionedFiles' : '--skip-non-versioned-files')
|
||||
// Install only runtime + CLI
|
||||
.useArguments(utils_1.IS_WINDOWS ? '-Runtime' : '--runtime', 'dotnet')
|
||||
// Use latest stable version
|
||||
.useArguments(utils_1.IS_WINDOWS ? '-Channel' : '--channel', 'LTS')
|
||||
.useArguments(...architectureArguments)
|
||||
.execute();
|
||||
if (runtimeInstallOutput.exitCode) {
|
||||
/**
|
||||
@@ -54944,10 +54975,12 @@ class DotnetCoreInstaller {
|
||||
* dotnet CLI
|
||||
*/
|
||||
const dotnetInstallOutput = await new DotnetInstallScript()
|
||||
.useArchitecture(this.architecture)
|
||||
// Don't overwrite CLI because it should be already installed
|
||||
.useArguments(utils_1.IS_WINDOWS ? '-SkipNonVersionedFiles' : '--skip-non-versioned-files')
|
||||
// Use version provided by user
|
||||
.useVersion(dotnetVersion, this.quality)
|
||||
.useArguments(...architectureArguments)
|
||||
.execute();
|
||||
if (dotnetInstallOutput.exitCode) {
|
||||
throw new Error(`Failed to install dotnet, exit code: ${dotnetInstallOutput.exitCode}. ${dotnetInstallOutput.stderr}`);
|
||||
@@ -55018,6 +55051,7 @@ const installer_1 = __nccwpck_require__(12574);
|
||||
const fs = __importStar(__nccwpck_require__(57147));
|
||||
const path_1 = __importDefault(__nccwpck_require__(71017));
|
||||
const semver_1 = __importDefault(__nccwpck_require__(11383));
|
||||
const os_1 = __importDefault(__nccwpck_require__(22037));
|
||||
const auth = __importStar(__nccwpck_require__(17573));
|
||||
const cache_utils_1 = __nccwpck_require__(41678);
|
||||
const cache_restore_1 = __nccwpck_require__(19517);
|
||||
@@ -55030,6 +55064,16 @@ const qualityOptions = [
|
||||
'preview',
|
||||
'ga'
|
||||
];
|
||||
const supportedArchitectures = [
|
||||
'x64',
|
||||
'x86',
|
||||
'arm64',
|
||||
'amd64',
|
||||
'arm',
|
||||
's390x',
|
||||
'ppc64le',
|
||||
'riscv64'
|
||||
];
|
||||
async function run() {
|
||||
try {
|
||||
//
|
||||
@@ -55043,6 +55087,7 @@ async function run() {
|
||||
//
|
||||
const versions = core.getMultilineInput('dotnet-version');
|
||||
const installedDotnetVersions = [];
|
||||
const architecture = getArchitectureInput();
|
||||
const globalJsonFileInput = core.getInput('global-json-file');
|
||||
if (globalJsonFileInput) {
|
||||
const globalJsonPath = path_1.default.resolve(process.cwd(), globalJsonFileInput);
|
||||
@@ -55070,10 +55115,14 @@ async function run() {
|
||||
let dotnetInstaller;
|
||||
const uniqueVersions = new Set(versions);
|
||||
for (const version of uniqueVersions) {
|
||||
dotnetInstaller = new installer_1.DotnetCoreInstaller(version, quality);
|
||||
dotnetInstaller = new installer_1.DotnetCoreInstaller(version, quality, architecture);
|
||||
const installedVersion = await dotnetInstaller.installDotnet();
|
||||
installedDotnetVersions.push(installedVersion);
|
||||
}
|
||||
if (architecture &&
|
||||
(0, installer_1.normalizeArch)(architecture) !== (0, installer_1.normalizeArch)(os_1.default.arch())) {
|
||||
process.env['DOTNET_INSTALL_DIR'] = path_1.default.join(installer_1.DotnetInstallDir.dirPath, architecture);
|
||||
}
|
||||
installer_1.DotnetInstallDir.addToPath();
|
||||
const workloadsInput = core.getInput('workloads');
|
||||
if (workloadsInput) {
|
||||
@@ -55111,6 +55160,16 @@ async function run() {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
}
|
||||
function getArchitectureInput() {
|
||||
const raw = (core.getInput('architecture') || '').trim();
|
||||
if (!raw)
|
||||
return '';
|
||||
const normalized = raw.toLowerCase();
|
||||
if (supportedArchitectures.includes(normalized)) {
|
||||
return (0, installer_1.normalizeArch)(normalized);
|
||||
}
|
||||
throw new Error(`Value '${raw}' is not supported for the 'architecture' option. Supported values are: ${supportedArchitectures.join(', ')}.`);
|
||||
}
|
||||
function getVersionFromGlobalJson(globalJsonPath) {
|
||||
let version = '';
|
||||
const globalJson = json5_1.default.parse(
|
||||
|
||||
Reference in New Issue
Block a user