Skip to content

Commit

Permalink
Added option that can be used to specify the architecture.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemstra committed Nov 19, 2023
1 parent 2216f56 commit a5b55f4
Show file tree
Hide file tree
Showing 8 changed files with 395 additions and 242 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ steps:
```
> **Warning**: Unless a concrete version is specified in the [`global.json`](https://learn.microsoft.com/en-us/dotnet/core/tools/global-json) file, **_the latest .NET version installed on the runner (including preinstalled versions) will be used [by default](https://learn.microsoft.com/en-us/dotnet/core/versions/selection#the-sdk-uses-the-latest-installed-version)_**. Please refer to the [documentation](https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-software) for the currently preinstalled .NET SDK versions.

**Specific architecture:**
```yml
steps:
- uses: actions/checkout@v3
- uses: actions/setup-dotnet@v2
with:
dotnet-version: '8.0.x'
architecture: 'x86'
- run: dotnet build <my project>
```

**Multiple version installation**:
```yml
steps:
Expand All @@ -49,8 +60,7 @@ The `dotnet-version` input supports following syntax:
- **A.B.C** (e.g 6.0.400, 7.0.100-preview.7.22377.5) - installs exact version of .NET SDK
- **A.B** or **A.B.x** (e.g. 3.1, 3.1.x) - installs the latest patch version of .NET SDK on the channel `3.1`, including prerelease versions (preview, rc)
- **A** or **A.x** (e.g. 3, 3.x) - installs the latest minor version of the specified major tag, including prerelease versions (preview, rc)
- **A.B.Cxx** (e.g. 6.0.4xx) - available since `.NET 5.0` release. Installs the latest version of the specific SDK release, including prerelease versions (preview, rc).

- **A.B.Cxx** (e.g. 6.0.4xx) - available since `.NET 5.0` release. Installs the latest version of the specific SDK release, including prerelease versions (preview, rc).

## Using the `dotnet-quality` input
This input sets up the action to install the latest build of the specified quality in the channel. The possible values of `dotnet-quality` are: **daily**, **signed**, **validated**, **preview**, **ga**.
Expand Down
82 changes: 81 additions & 1 deletion __tests__/installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as io from '@actions/io';
import * as installer from '../src/installer';

import {IS_WINDOWS} from '../src/utils';
import {QualityOptions} from '../src/setup-dotnet';
import {QualityOptions, ArchitectureOptions} from '../src/setup-dotnet';

describe('installer tests', () => {
const env = process.env;
Expand Down Expand Up @@ -119,6 +119,86 @@ describe('installer tests', () => {
expect(scriptArguments).toContain(expectedArgument);
});

it(`should not supply 'architecture' argument to the installation script when architecture is an empty string`, async () => {
const inputVersion = '6.0.300';
const inputQuality = '' as QualityOptions;
const inputArchitecture = '' as ArchitectureOptions;
const stdout = `Fictitious dotnet version ${inputVersion} is installed`;

getExecOutputSpy.mockImplementation(() => {
return Promise.resolve({
exitCode: 0,
stdout: `${stdout}`,
stderr: ''
});
});
maxSatisfyingSpy.mockImplementation(() => inputVersion);

const dotnetInstaller = new installer.DotnetCoreInstaller(
inputVersion,
inputQuality,
inputArchitecture
);

await dotnetInstaller.installDotnet();

/**
* First time script would be called to
* install runtime, here we checking only the
* second one that installs actual SDK. i.e. 1
*/
const callIndex = 1;

const scriptArguments = (
getExecOutputSpy.mock.calls[callIndex][1] as string[]
).join(' ');
const unexpectedArgument = IS_WINDOWS
? `-Architecture`
: `--architecture`;

expect(scriptArguments).not.toContain(unexpectedArgument);
});

it(`should supply 'architecture' argument to the installation script when arrchitecture is supplied`, async () => {
const inputVersion = '6.0.300';
const inputQuality = '' as QualityOptions;
const inputArchitecture = 'x86';
const stdout = `Fictitious dotnet version ${inputVersion} is installed`;

getExecOutputSpy.mockImplementation(() => {
return Promise.resolve({
exitCode: 0,
stdout: `${stdout}`,
stderr: ''
});
});
maxSatisfyingSpy.mockImplementation(() => inputVersion);

const dotnetInstaller = new installer.DotnetCoreInstaller(
inputVersion,
inputQuality,
inputArchitecture
);

await dotnetInstaller.installDotnet();

/**
* First time script would be called to
* install runtime, here we checking only the
* second one that installs actual SDK. i.e. 1
*/
const callIndex = 1;

const scriptArguments = (
getExecOutputSpy.mock.calls[callIndex][1] as string[]
).join(' ');
const expectedArgument = IS_WINDOWS
? `-Architecture ${inputArchitecture}`
: `--architecture ${inputArchitecture}`;

expect(scriptArguments).toContain(expectedArgument);
});

it(`should warn if the 'quality' input is set and the supplied version is in A.B.C syntax`, async () => {
const inputVersion = '6.0.300';
const inputQuality = 'ga' as QualityOptions;
Expand Down
27 changes: 13 additions & 14 deletions __tests__/setup-dotnet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as cacheUtils from '../src/cache-utils';
import * as cacheRestore from '../src/cache-restore';

describe('setup-dotnet tests', () => {
const inputs = {} as any;
let inputs = {} as any;

const getInputSpy = jest.spyOn(core, 'getInput');
const getMultilineInputSpy = jest.spyOn(core, 'getMultilineInput');
Expand Down Expand Up @@ -49,6 +49,7 @@ describe('setup-dotnet tests', () => {
DotnetInstallDir.addToPath = addToPathOriginal;
jest.clearAllMocks();
jest.resetAllMocks();
inputs = {};
});

it('should fail the action if global-json-file input is present, but the file does not exist in the file system', async () => {
Expand All @@ -62,7 +63,6 @@ describe('setup-dotnet tests', () => {
});

test(`if 'dotnet-version' and 'global-json-file' inputs aren't present, should log into debug output, try to find global.json in the repo root, fail and log message into info output`, async () => {
inputs['global-json-file'] = '';
inputs['dotnet-version'] = [];

maxSatisfyingSpy.mockImplementation(() => null);
Expand All @@ -80,7 +80,6 @@ describe('setup-dotnet tests', () => {
});

it('should fail the action if quality is supplied but its value is not supported', async () => {
inputs['global-json-file'] = '';
inputs['dotnet-version'] = ['6.0'];
inputs['dotnet-quality'] = 'fictitiousQuality';

Expand All @@ -90,10 +89,19 @@ describe('setup-dotnet tests', () => {
expect(setFailedSpy).toHaveBeenCalledWith(expectedErrorMessage);
});

it('should fail the action if architecture is supplied but its value is not supported', async () => {
console.log(inputs);
inputs['dotnet-version'] = ['6.0'];
inputs['dotnet-architecture'] = 'fictitiousArchitecture';

const expectedErrorMessage = `Value '${inputs['dotnet-architecture']}' is not supported for the 'dotnet-architecture' option. Supported values are: amd64, x64, x86, arm64, arm, s390x, ppc64le, loongarch64.`;

await setup.run();
expect(setFailedSpy).toHaveBeenCalledWith(expectedErrorMessage);
});

it('should call installDotnet() multiple times if dotnet-version multiline input is provided', async () => {
inputs['global-json-file'] = '';
inputs['dotnet-version'] = ['6.0', '7.0'];
inputs['dotnet-quality'] = '';

installDotnetSpy.mockImplementation(() => Promise.resolve(''));

Expand All @@ -102,9 +110,7 @@ describe('setup-dotnet tests', () => {
});

it('should call addToPath() after installation complete', async () => {
inputs['global-json-file'] = '';
inputs['dotnet-version'] = ['6.0', '7.0'];
inputs['dotnet-quality'] = '';

installDotnetSpy.mockImplementation(() => Promise.resolve(''));

Expand All @@ -113,9 +119,7 @@ describe('setup-dotnet tests', () => {
});

it('should call auth.configAuthentication() if source-url input is provided', async () => {
inputs['global-json-file'] = '';
inputs['dotnet-version'] = [];
inputs['dotnet-quality'] = '';
inputs['source-url'] = 'fictitious.source.url';

configAuthenticationSpy.mockImplementation(() => {});
Expand All @@ -128,9 +132,7 @@ describe('setup-dotnet tests', () => {
});

it('should call auth.configAuthentication() with proper parameters if source-url and config-file inputs are provided', async () => {
inputs['global-json-file'] = '';
inputs['dotnet-version'] = [];
inputs['dotnet-quality'] = '';
inputs['source-url'] = 'fictitious.source.url';
inputs['config-file'] = 'fictitious.path';

Expand Down Expand Up @@ -178,7 +180,6 @@ describe('setup-dotnet tests', () => {

it(`should get 'cache-dependency-path' and call restoreCache() if input cache is set to true and cache feature is available`, async () => {
inputs['dotnet-version'] = ['6.0.300'];
inputs['dotnet-quality'] = '';
inputs['cache'] = true;
inputs['cache-dependency-path'] = 'fictitious.package.lock.json';

Expand All @@ -196,7 +197,6 @@ describe('setup-dotnet tests', () => {

it(`shouldn't call restoreCache() if input cache isn't set to true`, async () => {
inputs['dotnet-version'] = ['6.0.300'];
inputs['dotnet-quality'] = '';
inputs['cache'] = false;

installDotnetSpy.mockImplementation(() => Promise.resolve(''));
Expand All @@ -210,7 +210,6 @@ describe('setup-dotnet tests', () => {

it(`shouldn't call restoreCache() if cache feature isn't available`, async () => {
inputs['dotnet-version'] = ['6.0.300'];
inputs['dotnet-quality'] = '';
inputs['cache'] = true;

installDotnetSpy.mockImplementation(() => Promise.resolve(''));
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ inputs:
description: 'Optional SDK version(s) to use. If not provided, will install global.json version when available. Examples: 2.2.104, 3.1, 3.1.x, 3.x, 6.0.2xx'
dotnet-quality:
description: 'Optional quality of the build. The possible values are: daily, signed, validated, preview, ga.'
dotnet-architecture:
description: 'Optional architecture of the .NET binaries to install. Possible values: amd64, x64, x86, arm64, arm, s390x, ppc64le and loongarch64 if not provided, defaults to the OS architecture.'
global-json-file:
description: 'Optional global.json location, if your global.json isn''t located in the root of the repo.'
source-url:
Expand Down
Loading

0 comments on commit a5b55f4

Please sign in to comment.