Skip to content

Commit 66ae3de

Browse files
committed
Added option that can be used to specify the architecture.
1 parent 2216f56 commit 66ae3de

File tree

8 files changed

+395
-242
lines changed

8 files changed

+395
-242
lines changed

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ steps:
3030
```
3131
> **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.
3232

33+
**Specific architecture:**
34+
```yml
35+
steps:
36+
- uses: actions/checkout@v3
37+
- uses: actions/setup-dotnet@v2
38+
with:
39+
dotnet-version: '8.0.x'
40+
architecture: 'x86'
41+
- run: dotnet build <my project>
42+
```
43+
3344
**Multiple version installation**:
3445
```yml
3546
steps:
@@ -49,8 +60,7 @@ The `dotnet-version` input supports following syntax:
4960
- **A.B.C** (e.g 6.0.400, 7.0.100-preview.7.22377.5) - installs exact version of .NET SDK
5061
- **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)
5162
- **A** or **A.x** (e.g. 3, 3.x) - installs the latest minor version of the specified major tag, including prerelease versions (preview, rc)
52-
- **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).
53-
63+
- **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).
5464

5565
## Using the `dotnet-quality` input
5666
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**.

__tests__/installer.test.ts

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as io from '@actions/io';
88
import * as installer from '../src/installer';
99

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

1313
describe('installer tests', () => {
1414
const env = process.env;
@@ -119,6 +119,86 @@ describe('installer tests', () => {
119119
expect(scriptArguments).toContain(expectedArgument);
120120
});
121121

122+
it(`should not supply 'architecture' argument to the installation script when architecture is an empty string`, async () => {
123+
const inputVersion = '6.0.300';
124+
const inputQuality = '' as QualityOptions;
125+
const inputArchitecture = '' as ArchitectureOptions;
126+
const stdout = `Fictitious dotnet version ${inputVersion} is installed`;
127+
128+
getExecOutputSpy.mockImplementation(() => {
129+
return Promise.resolve({
130+
exitCode: 0,
131+
stdout: `${stdout}`,
132+
stderr: ''
133+
});
134+
});
135+
maxSatisfyingSpy.mockImplementation(() => inputVersion);
136+
137+
const dotnetInstaller = new installer.DotnetCoreInstaller(
138+
inputVersion,
139+
inputQuality,
140+
inputArchitecture
141+
);
142+
143+
await dotnetInstaller.installDotnet();
144+
145+
/**
146+
* First time script would be called to
147+
* install runtime, here we checking only the
148+
* second one that installs actual SDK. i.e. 1
149+
*/
150+
const callIndex = 1;
151+
152+
const scriptArguments = (
153+
getExecOutputSpy.mock.calls[callIndex][1] as string[]
154+
).join(' ');
155+
const unexpectedArgument = IS_WINDOWS
156+
? `-Architecture`
157+
: `--architecture`;
158+
159+
expect(scriptArguments).not.toContain(unexpectedArgument);
160+
});
161+
162+
it(`should supply 'architecture' argument to the installation script when arrchitecture is supplied`, async () => {
163+
const inputVersion = '6.0.300';
164+
const inputQuality = '' as QualityOptions;
165+
const inputArchitecture = 'x86';
166+
const stdout = `Fictitious dotnet version ${inputVersion} is installed`;
167+
168+
getExecOutputSpy.mockImplementation(() => {
169+
return Promise.resolve({
170+
exitCode: 0,
171+
stdout: `${stdout}`,
172+
stderr: ''
173+
});
174+
});
175+
maxSatisfyingSpy.mockImplementation(() => inputVersion);
176+
177+
const dotnetInstaller = new installer.DotnetCoreInstaller(
178+
inputVersion,
179+
inputQuality,
180+
inputArchitecture
181+
);
182+
183+
await dotnetInstaller.installDotnet();
184+
185+
/**
186+
* First time script would be called to
187+
* install runtime, here we checking only the
188+
* second one that installs actual SDK. i.e. 1
189+
*/
190+
const callIndex = 1;
191+
192+
const scriptArguments = (
193+
getExecOutputSpy.mock.calls[callIndex][1] as string[]
194+
).join(' ');
195+
const expectedArgument = IS_WINDOWS
196+
? `-Architecture ${inputArchitecture}`
197+
: `--architecture ${inputArchitecture}`;
198+
199+
expect(scriptArguments).toContain(expectedArgument);
200+
});
201+
122202
it(`should warn if the 'quality' input is set and the supplied version is in A.B.C syntax`, async () => {
123203
const inputVersion = '6.0.300';
124204
const inputQuality = 'ga' as QualityOptions;

__tests__/setup-dotnet.test.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as cacheUtils from '../src/cache-utils';
99
import * as cacheRestore from '../src/cache-restore';
1010

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

1414
const getInputSpy = jest.spyOn(core, 'getInput');
1515
const getMultilineInputSpy = jest.spyOn(core, 'getMultilineInput');
@@ -49,6 +49,7 @@ describe('setup-dotnet tests', () => {
4949
DotnetInstallDir.addToPath = addToPathOriginal;
5050
jest.clearAllMocks();
5151
jest.resetAllMocks();
52+
inputs = {};
5253
});
5354

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

6465
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 () => {
65-
inputs['global-json-file'] = '';
6666
inputs['dotnet-version'] = [];
6767

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

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

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

92+
it('should fail the action if architecture is supplied but its value is not supported', async () => {
93+
console.log(inputs);
94+
inputs['dotnet-version'] = ['6.0'];
95+
inputs['dotnet-architecture'] = 'fictitiousArchitecture';
96+
97+
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.`;
98+
99+
await setup.run();
100+
expect(setFailedSpy).toHaveBeenCalledWith(expectedErrorMessage);
101+
});
102+
93103
it('should call installDotnet() multiple times if dotnet-version multiline input is provided', async () => {
94-
inputs['global-json-file'] = '';
95104
inputs['dotnet-version'] = ['6.0', '7.0'];
96-
inputs['dotnet-quality'] = '';
97105

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

action.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ inputs:
99
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'
1010
dotnet-quality:
1111
description: 'Optional quality of the build. The possible values are: daily, signed, validated, preview, ga.'
12+
dotnet-architecture:
13+
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.'
1214
global-json-file:
1315
description: 'Optional global.json location, if your global.json isn''t located in the root of the repo.'
1416
source-url:

0 commit comments

Comments
 (0)