Skip to content

Commit aa983c5

Browse files
Merge pull request #428 from akv-platform/add-latest-patch-syntax
Add latest patch syntax
2 parents 5fdecd2 + b891376 commit aa983c5

File tree

8 files changed

+318
-138
lines changed

8 files changed

+318
-138
lines changed

.github/workflows/e2e-tests.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,27 @@ jobs:
133133
shell: pwsh
134134
run: __tests__/verify-dotnet.ps1 -Patterns "^2.2", "^3.1"
135135

136+
test-ABCxx-syntax:
137+
runs-on: ${{ matrix.operating-system }}
138+
strategy:
139+
fail-fast: false
140+
matrix:
141+
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
142+
steps:
143+
- name: Checkout
144+
uses: actions/checkout@v3
145+
- name: Clear toolcache
146+
shell: pwsh
147+
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
148+
149+
- name: Setup dotnet 6.0.4xx
150+
uses: ./
151+
with:
152+
dotnet-version: '6.0.4xx'
153+
- name: Verify dotnet
154+
shell: pwsh
155+
run: __tests__/verify-dotnet.ps1 -Patterns "^6\.0\.4\d{2}"
156+
136157
test-setup-with-wildcard:
137158
runs-on: ${{ matrix.operating-system }}
138159
strategy:
@@ -183,6 +204,31 @@ jobs:
183204
shell: pwsh
184205
run: __tests__/verify-dotnet.ps1 -Patterns "^2.2", "^3.1"
185206

207+
test-setup-global-json-only:
208+
runs-on: ${{ matrix.operating-system }}
209+
strategy:
210+
fail-fast: false
211+
matrix:
212+
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
213+
steps:
214+
- name: Checkout
215+
uses: actions/checkout@v3
216+
- name: Clear toolcache
217+
shell: pwsh
218+
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
219+
- name: Write global.json
220+
shell: bash
221+
run: |
222+
mkdir subdirectory
223+
echo '{"sdk":{"version": "2.2.207","rollForward": "latestFeature"}}' > ./subdirectory/global.json
224+
- name: Setup dotnet
225+
uses: ./
226+
with:
227+
global-json-file: ./subdirectory/global.json
228+
- name: Verify dotnet
229+
shell: pwsh
230+
run: __tests__/verify-dotnet.ps1 -Patterns "^2.2"
231+
186232
test-setup-with-dotnet-quality:
187233
runs-on: ${{ matrix.operating-system }}
188234
strategy:

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@ The `dotnet-version` input supports following syntax:
4949
- **A.B.C** (e.g 6.0.400, 7.0.100-preview.7.22377.5) - installs exact version of .NET SDK
5050
- **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)
5151
- **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).
5253

5354

5455
## Using the `dotnet-quality` input
5556
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**.
5657

57-
> **Note**: `dotnet-quality` input can be used only with .NET SDK version in 'A.B', 'A.B.x', 'A' and 'A.x' formats where the major version is higher than 5. In other cases, `dotnet-quality` input will be ignored.
58+
> **Note**: `dotnet-quality` input can be used only with .NET SDK version in 'A.B', 'A.B.x', 'A', 'A.x' and 'A.B.Cxx' formats where the major version is higher than 5. In other cases, `dotnet-quality` input will be ignored.
5859

5960
```yml
6061
steps:

__tests__/installer.test.ts

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,13 @@ describe('installer tests', () => {
4848
it('should return version of .NET SDK after installation complete', async () => {
4949
const inputVersion = '3.1.100';
5050
const inputQuality = '' as QualityOptions;
51+
const stdout = `Fictitious dotnet version ${inputVersion} is installed`;
5152
getExecOutputSpy.mockImplementation(() => {
52-
return Promise.resolve({exitCode: 0, stdout: '', stderr: ''});
53+
return Promise.resolve({
54+
exitCode: 0,
55+
stdout: `${stdout}`,
56+
stderr: ''
57+
});
5358
});
5459
maxSatisfyingSpy.mockImplementation(() => inputVersion);
5560

@@ -65,9 +70,14 @@ describe('installer tests', () => {
6570
it(`should supply 'version' argument to the installation script if supplied version is in A.B.C syntax`, async () => {
6671
const inputVersion = '6.0.300';
6772
const inputQuality = '' as QualityOptions;
73+
const stdout = `Fictitious dotnet version ${inputVersion} is installed`;
6874

6975
getExecOutputSpy.mockImplementation(() => {
70-
return Promise.resolve({exitCode: 0, stdout: '', stderr: ''});
76+
return Promise.resolve({
77+
exitCode: 0,
78+
stdout: `${stdout}`,
79+
stderr: ''
80+
});
7181
});
7282
maxSatisfyingSpy.mockImplementation(() => inputVersion);
7383

@@ -91,9 +101,13 @@ describe('installer tests', () => {
91101
it(`should warn if the 'quality' input is set and the supplied version is in A.B.C syntax`, async () => {
92102
const inputVersion = '6.0.300';
93103
const inputQuality = 'ga' as QualityOptions;
94-
104+
const stdout = `Fictitious dotnet version ${inputVersion} is installed`;
95105
getExecOutputSpy.mockImplementation(() => {
96-
return Promise.resolve({exitCode: 0, stdout: '', stderr: ''});
106+
return Promise.resolve({
107+
exitCode: 0,
108+
stdout: `${stdout}`,
109+
stderr: ''
110+
});
97111
});
98112
maxSatisfyingSpy.mockImplementation(() => inputVersion);
99113

@@ -105,16 +119,21 @@ describe('installer tests', () => {
105119
await dotnetInstaller.installDotnet();
106120

107121
expect(warningSpy).toHaveBeenCalledWith(
108-
`'dotnet-quality' input can be used only with .NET SDK version in A.B, A.B.x, A and A.x formats where the major tag is higher than 5. You specified: ${inputVersion}. 'dotnet-quality' input is ignored.`
122+
`The 'dotnet-quality' input can be used only with .NET SDK version in A.B, A.B.x, A, A.x and A.B.Cxx formats where the major tag is higher than 5. You specified: ${inputVersion}. 'dotnet-quality' input is ignored.`
109123
);
110124
});
111125

112126
it(`should warn if the 'quality' input is set and version isn't in A.B.C syntax but major tag is lower then 6`, async () => {
113127
const inputVersion = '3.1';
114128
const inputQuality = 'ga' as QualityOptions;
129+
const stdout = `Fictitious dotnet version 3.1.100 is installed`;
115130

116131
getExecOutputSpy.mockImplementation(() => {
117-
return Promise.resolve({exitCode: 0, stdout: '', stderr: ''});
132+
return Promise.resolve({
133+
exitCode: 0,
134+
stdout: `${stdout}`,
135+
stderr: ''
136+
});
118137
});
119138
maxSatisfyingSpy.mockImplementation(() => inputVersion);
120139

@@ -126,7 +145,7 @@ describe('installer tests', () => {
126145
await dotnetInstaller.installDotnet();
127146

128147
expect(warningSpy).toHaveBeenCalledWith(
129-
`'dotnet-quality' input can be used only with .NET SDK version in A.B, A.B.x, A and A.x formats where the major tag is higher than 5. You specified: ${inputVersion}. 'dotnet-quality' input is ignored.`
148+
`The 'dotnet-quality' input can be used only with .NET SDK version in A.B, A.B.x, A, A.x and A.B.Cxx formats where the major tag is higher than 5. You specified: ${inputVersion}. 'dotnet-quality' input is ignored.`
130149
);
131150
});
132151

@@ -135,10 +154,11 @@ describe('installer tests', () => {
135154
async inputVersion => {
136155
const inputQuality = 'ga' as QualityOptions;
137156
const exitCode = 0;
157+
const stdout = `Fictitious dotnet version 6.0.0 is installed`;
138158
getExecOutputSpy.mockImplementation(() => {
139159
return Promise.resolve({
140160
exitCode: exitCode,
141-
stdout: '',
161+
stdout: `${stdout}`,
142162
stderr: ''
143163
});
144164
});
@@ -167,10 +187,11 @@ describe('installer tests', () => {
167187
async inputVersion => {
168188
const inputQuality = '' as QualityOptions;
169189
const exitCode = 0;
190+
const stdout = `Fictitious dotnet version 6.0.0 is installed`;
170191
getExecOutputSpy.mockImplementation(() => {
171192
return Promise.resolve({
172193
exitCode: exitCode,
173-
stdout: '',
194+
stdout: `${stdout}`,
174195
stderr: ''
175196
});
176197
});
@@ -199,9 +220,14 @@ describe('installer tests', () => {
199220
process.env['https_proxy'] = 'https://proxy.com';
200221
const inputVersion = '6.0.100';
201222
const inputQuality = '' as QualityOptions;
223+
const stdout = `Fictitious dotnet version ${inputVersion} is installed`;
202224

203225
getExecOutputSpy.mockImplementation(() => {
204-
return Promise.resolve({exitCode: 0, stdout: '', stderr: ''});
226+
return Promise.resolve({
227+
exitCode: 0,
228+
stdout: `${stdout}`,
229+
stderr: ''
230+
});
205231
});
206232
maxSatisfyingSpy.mockImplementation(() => inputVersion);
207233

@@ -225,9 +251,14 @@ describe('installer tests', () => {
225251
process.env['no_proxy'] = 'first.url,second.url';
226252
const inputVersion = '6.0.100';
227253
const inputQuality = '' as QualityOptions;
254+
const stdout = `Fictitious dotnet version 6.0.0 is installed`;
228255

229256
getExecOutputSpy.mockImplementation(() => {
230-
return Promise.resolve({exitCode: 0, stdout: '', stderr: ''});
257+
return Promise.resolve({
258+
exitCode: 0,
259+
stdout: `${stdout}`,
260+
stderr: ''
261+
});
231262
});
232263
maxSatisfyingSpy.mockImplementation(() => inputVersion);
233264

@@ -275,7 +306,8 @@ describe('installer tests', () => {
275306
'3.1.*',
276307
'3.1.X',
277308
'3.1.2',
278-
'3.1.0-preview1'
309+
'3.1.0-preview1',
310+
'6.0.2xx'
279311
]).test(
280312
'if valid version is supplied (%s), it should return version object with some value',
281313
async version => {
@@ -327,7 +359,7 @@ describe('installer tests', () => {
327359
}
328360
);
329361

330-
each(['3', '3.1', '3.1.x', '3.1.*', '3.1.X']).test(
362+
each(['3', '3.1', '3.1.x', '3.1.*', '3.1.X', '6.0.2xx']).test(
331363
"if version that can be resolved to 'channel' option is supplied (%s), it should set type to 'channel' in version object",
332364
async version => {
333365
const dotnetVersionResolver = new installer.DotnetVersionResolver(
@@ -342,7 +374,7 @@ describe('installer tests', () => {
342374
}
343375
);
344376

345-
each(['6.0', '6.0.x', '6.0.*', '6.0.X']).test(
377+
each(['6.0', '6.0.x', '6.0.*', '6.0.X', '6.0.2xx']).test(
346378
"if version that can be resolved to 'channel' option is supplied and its major tag is >= 6 (%s), it should set type to 'channel' and qualityFlag to 'true' in version object",
347379
async version => {
348380
const dotnetVersionResolver = new installer.DotnetVersionResolver(
@@ -394,6 +426,18 @@ describe('installer tests', () => {
394426
}
395427
}
396428
);
429+
430+
it(`should throw if dotnet-version is supplied in A.B.Cxx syntax with major tag lower that 5`, async () => {
431+
const version = '3.0.1xx';
432+
const dotnetVersionResolver = new installer.DotnetVersionResolver(
433+
version
434+
);
435+
await expect(
436+
async () => await dotnetVersionResolver.createDotNetVersion()
437+
).rejects.toThrow(
438+
`'dotnet-version' was supplied in invalid format: ${version}! The A.B.Cxx syntax is available since the .NET 5.0 release.`
439+
);
440+
});
397441
});
398442
});
399443
});

__tests__/setup-dotnet.test.ts

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ describe('setup-dotnet tests', () => {
1212
const getInputSpy = jest.spyOn(core, 'getInput');
1313
const getMultilineInputSpy = jest.spyOn(core, 'getMultilineInput');
1414
const setFailedSpy = jest.spyOn(core, 'setFailed');
15+
const warningSpy = jest.spyOn(core, 'warning');
1516
const debugSpy = jest.spyOn(core, 'debug');
1617
const infoSpy = jest.spyOn(core, 'info');
1718
const setOutputSpy = jest.spyOn(core, 'setOutput');
@@ -58,7 +59,7 @@ describe('setup-dotnet tests', () => {
5859

5960
const expectedDebugMessage =
6061
'No version found, trying to find version from global.json';
61-
const expectedInfoMessage = `global.json wasn't found in the root directory. No .NET version will be installed.`;
62+
const expectedInfoMessage = `The global.json wasn't found in the root directory. No .NET version will be installed.`;
6263

6364
await setup.run();
6465

@@ -72,7 +73,7 @@ describe('setup-dotnet tests', () => {
7273
inputs['dotnet-version'] = ['6.0'];
7374
inputs['dotnet-quality'] = 'fictitiousQuality';
7475

75-
const expectedErrorMessage = `${inputs['dotnet-quality']} is not a supported value for 'dotnet-quality' option. Supported values are: daily, signed, validated, preview, ga.`;
76+
const expectedErrorMessage = `Value '${inputs['dotnet-quality']}' is not supported for the 'dotnet-quality' option. Supported values are: daily, signed, validated, preview, ga.`;
7677

7778
await setup.run();
7879
expect(setFailedSpy).toHaveBeenCalledWith(expectedErrorMessage);
@@ -133,14 +134,40 @@ describe('setup-dotnet tests', () => {
133134
);
134135
});
135136

136-
it('should call setOutput() after installation complete', async () => {
137+
it('should call setOutput() after installation complete successfully', async () => {
137138
inputs['dotnet-version'] = ['6.0.300'];
138139

139-
installDotnetSpy.mockImplementation(() => Promise.resolve(''));
140+
installDotnetSpy.mockImplementation(() =>
141+
Promise.resolve(`${inputs['dotnet-version']}`)
142+
);
140143
addToPathSpy.mockImplementation(() => {});
141144

142145
await setup.run();
143146
expect(setOutputSpy).toHaveBeenCalledTimes(1);
144147
});
148+
149+
it(`shouldn't call setOutput() if parsing dotnet-installer logs failed`, async () => {
150+
inputs['dotnet-version'] = ['6.0.300'];
151+
const warningMessage = `Failed to output the installed version of .NET. The 'dotnet-version' output will not be set.`;
152+
153+
installDotnetSpy.mockImplementation(() => Promise.resolve(null));
154+
addToPathSpy.mockImplementation(() => {});
155+
156+
await setup.run();
157+
expect(warningSpy).toHaveBeenCalledWith(warningMessage);
158+
expect(setOutputSpy).not.toHaveBeenCalled();
159+
});
160+
161+
it(`shouldn't call setOutput() if actions didn't install .NET`, async () => {
162+
inputs['dotnet-version'] = [];
163+
const warningMessage = `The 'dotnet-version' output will not be set.`;
164+
165+
addToPathSpy.mockImplementation(() => {});
166+
167+
await setup.run();
168+
169+
expect(infoSpy).toHaveBeenCalledWith(warningMessage);
170+
expect(setOutputSpy).not.toHaveBeenCalled();
171+
});
145172
});
146173
});

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ branding:
66
color: green
77
inputs:
88
dotnet-version:
9-
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'
9+
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.'
1212
global-json-file:

0 commit comments

Comments
 (0)