Skip to content

Commit 8a21b4e

Browse files
Support global.json's rollForward latest* variants
Co-authored-by: js6pak <[email protected]>
1 parent 3f75cd0 commit 8a21b4e

File tree

3 files changed

+138
-6
lines changed

3 files changed

+138
-6
lines changed

.github/workflows/e2e-tests.yml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,106 @@ jobs:
201201
shell: pwsh
202202
run: __tests__/verify-dotnet.ps1 -Patterns "^2.2", "^3.1"
203203

204+
test-setup-global-json-rollforward-latestmajor:
205+
runs-on: ${{ matrix.operating-system }}
206+
strategy:
207+
fail-fast: false
208+
matrix:
209+
operating-system: [ubuntu-latest, windows-latest, macos-13]
210+
steps:
211+
- name: Checkout
212+
uses: actions/checkout@v3
213+
- name: Clear toolcache
214+
shell: pwsh
215+
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
216+
- name: Write global.json
217+
shell: bash
218+
run: |
219+
mkdir subdirectory
220+
echo '{"sdk":{"version": "3.1.0","rollForward": "latestMajor"}}' > ./subdirectory/global.json
221+
- name: Setup dotnet
222+
uses: ./
223+
with:
224+
global-json-file: ./subdirectory/global.json
225+
- name: Verify dotnet
226+
shell: pwsh
227+
run: __tests__/verify-dotnet.ps1 -Patterns "^(?!3)"
228+
229+
test-setup-global-json-rollforward-latestminor:
230+
runs-on: ${{ matrix.operating-system }}
231+
strategy:
232+
fail-fast: false
233+
matrix:
234+
operating-system: [ubuntu-latest, windows-latest, macos-13]
235+
steps:
236+
- name: Checkout
237+
uses: actions/checkout@v3
238+
- name: Clear toolcache
239+
shell: pwsh
240+
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
241+
- name: Write global.json
242+
shell: bash
243+
run: |
244+
mkdir subdirectory
245+
echo '{"sdk":{"version": "3.0.100","rollForward": "latestMinor"}}' > ./subdirectory/global.json
246+
- name: Setup dotnet
247+
uses: ./
248+
with:
249+
global-json-file: ./subdirectory/global.json
250+
- name: Verify dotnet
251+
shell: pwsh
252+
run: __tests__/verify-dotnet.ps1 -Patterns "^3.1"
253+
254+
test-setup-global-json-rollforward-latestfeature:
255+
runs-on: ${{ matrix.operating-system }}
256+
strategy:
257+
fail-fast: false
258+
matrix:
259+
operating-system: [ubuntu-latest, windows-latest, macos-13]
260+
steps:
261+
- name: Checkout
262+
uses: actions/checkout@v3
263+
- name: Clear toolcache
264+
shell: pwsh
265+
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
266+
- name: Write global.json
267+
shell: bash
268+
run: |
269+
mkdir subdirectory
270+
echo '{"sdk":{"version": "3.1.100","rollForward": "latestFeature"}}' > ./subdirectory/global.json
271+
- name: Setup dotnet
272+
uses: ./
273+
with:
274+
global-json-file: ./subdirectory/global.json
275+
- name: Verify dotnet
276+
shell: pwsh
277+
run: __tests__/verify-dotnet.ps1 -Patterns "^3.1.4"
278+
279+
test-setup-global-json-rollforward-latestpatch:
280+
runs-on: ${{ matrix.operating-system }}
281+
strategy:
282+
fail-fast: false
283+
matrix:
284+
operating-system: [ubuntu-latest, windows-latest, macos-13]
285+
steps:
286+
- name: Checkout
287+
uses: actions/checkout@v3
288+
- name: Clear toolcache
289+
shell: pwsh
290+
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
291+
- name: Write global.json
292+
shell: bash
293+
run: |
294+
mkdir subdirectory
295+
echo '{"sdk":{"version": "5.0.400","rollForward": "latestPatch"}}' > ./subdirectory/global.json
296+
- name: Setup dotnet
297+
uses: ./
298+
with:
299+
global-json-file: ./subdirectory/global.json
300+
- name: Verify dotnet
301+
shell: pwsh
302+
run: __tests__/verify-dotnet.ps1 -Patterns "^5.0.408$"
303+
204304
test-setup-global-json-only:
205305
runs-on: ${{ matrix.operating-system }}
206306
strategy:

dist/setup/index.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94096,9 +94096,23 @@ function getVersionFromGlobalJson(globalJsonPath) {
9409694096
if (globalJson.sdk && globalJson.sdk.version) {
9409794097
version = globalJson.sdk.version;
9409894098
const rollForward = globalJson.sdk.rollForward;
94099-
if (rollForward && rollForward === 'latestFeature') {
94100-
const [major, minor] = version.split('.');
94101-
version = `${major}.${minor}`;
94099+
if (rollForward) {
94100+
const [major, minor, featurePatch] = version.split('.');
94101+
const feature = featurePatch.substring(0, 1);
94102+
switch (rollForward) {
94103+
case 'latestMajor':
94104+
version = '';
94105+
break;
94106+
case 'latestMinor':
94107+
version = `${major}`;
94108+
break;
94109+
case 'latestFeature':
94110+
version = `${major}.${minor}`;
94111+
break;
94112+
case 'latestPatch':
94113+
version = `${major}.${minor}.${feature}xx`;
94114+
break;
94115+
}
9410294116
}
9410394117
}
9410494118
return version;

src/setup-dotnet.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,27 @@ function getVersionFromGlobalJson(globalJsonPath: string): string {
110110
if (globalJson.sdk && globalJson.sdk.version) {
111111
version = globalJson.sdk.version;
112112
const rollForward = globalJson.sdk.rollForward;
113-
if (rollForward && rollForward === 'latestFeature') {
114-
const [major, minor] = version.split('.');
115-
version = `${major}.${minor}`;
113+
if (rollForward) {
114+
const [major, minor, featurePatch] = version.split('.');
115+
const feature = featurePatch.substring(0, 1);
116+
117+
switch (rollForward) {
118+
case 'latestMajor':
119+
version = '';
120+
break;
121+
122+
case 'latestMinor':
123+
version = `${major}`;
124+
break;
125+
126+
case 'latestFeature':
127+
version = `${major}.${minor}`;
128+
break;
129+
130+
case 'latestPatch':
131+
version = `${major}.${minor}.${feature}xx`;
132+
break;
133+
}
116134
}
117135
}
118136
return version;

0 commit comments

Comments
 (0)