Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to force the architecture #338

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
24 changes: 22 additions & 2 deletions __tests__/installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -278,11 +296,13 @@ function normalizeFileContents(contents: string): string {

async function getDotnet(
version: string,
quality: 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();
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +20 to +22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
architecture:
description: 'Optional architecture to use. If not provided, will default to the OS architecture.'
required: False
architecture:
description: 'Optional architecture of the .NET binaries to install. Possible values: amd64, x64, x86, arm64, arm, and s390x, if not provided, defaults to the OS architecture.'

outputs:
dotnet-version:
description: 'Contains the installed by action .NET SDK version for reuse.'
Expand Down
12 changes: 10 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,10 @@ class DotnetVersionResolver {
exports.DotnetVersionResolver = DotnetVersionResolver;
DotnetVersionResolver.DotNetCoreIndexUrl = 'https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/releases-index.json';
class DotnetCoreInstaller {
constructor(version, quality) {
constructor(version, quality, architecture = '') {
this.version = version;
this.quality = quality;
this.architecture = architecture;
}
static convertInstallPathToAbsolute(installDir) {
let transformedPath;
Expand Down Expand Up @@ -352,6 +353,9 @@ 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 = {
Expand Down Expand Up @@ -471,6 +475,10 @@ function run() {
//
const versions = core.getMultilineInput('dotnet-version');
const installedDotnetVersions = [];
let architecture = core.getInput('architecture');
if (!architecture) {
architecture = '';
}
const globalJsonFileInput = core.getInput('global-json-file');
if (globalJsonFileInput) {
const globalJsonPath = path_1.default.join(process.cwd(), globalJsonFileInput);
Expand All @@ -495,7 +503,7 @@ 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 = yield dotnetInstaller.installDotnet();
installedDotnetVersions.push(installedVersion);
}
Expand Down
12 changes: 11 additions & 1 deletion src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export class DotnetVersionResolver {
export class DotnetCoreInstaller {
private version: string;
private quality: QualityOptions;
private architecture: string;

static {
const installationDirectoryWindows = path.join(
Expand Down Expand Up @@ -140,9 +141,14 @@ export class DotnetCoreInstaller {
}
}

constructor(version: string, quality: QualityOptions) {
constructor(
version: string,
quality: QualityOptions,
architecture: string = ''
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
architecture: string = ''
architecture: string

Do we need a default value here? As I wrote in another comment, the default value for the empty input will be an empty string.

) {
this.version = version;
this.quality = quality;
this.architecture = architecture;
}

private static convertInstallPathToAbsolute(installDir: string): string {
Expand Down Expand Up @@ -230,6 +236,10 @@ export class DotnetCoreInstaller {
if (this.quality) {
this.setQuality(dotnetVersion, scriptArguments);
}

if (this.architecture != '') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (this.architecture != '') {
if (this.architecture) {

scriptArguments.push('--architecture', this.architecture);
}
Comment on lines +239 to +242
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest adding the same code for Windows.

}
// process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
const getExecOutputOptions = {
Expand Down
11 changes: 10 additions & 1 deletion src/setup-dotnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export async function run() {
//
const versions = core.getMultilineInput('dotnet-version');
const installedDotnetVersions: string[] = [];
let architecture = core.getInput('architecture');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let architecture = core.getInput('architecture');
const architecture = core.getInput('architecture');


if (!architecture) {
architecture = '';
}
Comment on lines +33 to +35
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that we need this check here. If the architecture input is not supplied function core.getInput() will return an empty string by default.


const globalJsonFileInput = core.getInput('global-json-file');
if (globalJsonFileInput) {
Expand Down Expand Up @@ -61,7 +66,11 @@ 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);
}
Expand Down