Skip to content

Commit d3880ca

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

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
@@ -373,6 +373,106 @@ jobs:
373373
shell: pwsh
374374
run: __tests__/verify-dotnet.ps1 -Patterns "^6.0", "^8.0"
375375

376+
test-setup-global-json-rollforward-latestmajor:
377+
runs-on: ${{ matrix.operating-system }}
378+
strategy:
379+
fail-fast: false
380+
matrix:
381+
operating-system: [ubuntu-latest, windows-latest, macos-13]
382+
steps:
383+
- name: Checkout
384+
uses: actions/checkout@v3
385+
- name: Clear toolcache
386+
shell: pwsh
387+
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
388+
- name: Write global.json
389+
shell: bash
390+
run: |
391+
mkdir subdirectory
392+
echo '{"sdk":{"version": "3.1.0","rollForward": "latestMajor"}}' > ./subdirectory/global.json
393+
- name: Setup dotnet
394+
uses: ./
395+
with:
396+
global-json-file: ./subdirectory/global.json
397+
- name: Verify dotnet
398+
shell: pwsh
399+
run: __tests__/verify-dotnet.ps1 -Patterns "^(?!3)"
400+
401+
test-setup-global-json-rollforward-latestminor:
402+
runs-on: ${{ matrix.operating-system }}
403+
strategy:
404+
fail-fast: false
405+
matrix:
406+
operating-system: [ubuntu-latest, windows-latest, macos-13]
407+
steps:
408+
- name: Checkout
409+
uses: actions/checkout@v3
410+
- name: Clear toolcache
411+
shell: pwsh
412+
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
413+
- name: Write global.json
414+
shell: bash
415+
run: |
416+
mkdir subdirectory
417+
echo '{"sdk":{"version": "3.0.100","rollForward": "latestMinor"}}' > ./subdirectory/global.json
418+
- name: Setup dotnet
419+
uses: ./
420+
with:
421+
global-json-file: ./subdirectory/global.json
422+
- name: Verify dotnet
423+
shell: pwsh
424+
run: __tests__/verify-dotnet.ps1 -Patterns "^3.1"
425+
426+
test-setup-global-json-rollforward-latestfeature:
427+
runs-on: ${{ matrix.operating-system }}
428+
strategy:
429+
fail-fast: false
430+
matrix:
431+
operating-system: [ubuntu-latest, windows-latest, macos-13]
432+
steps:
433+
- name: Checkout
434+
uses: actions/checkout@v3
435+
- name: Clear toolcache
436+
shell: pwsh
437+
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
438+
- name: Write global.json
439+
shell: bash
440+
run: |
441+
mkdir subdirectory
442+
echo '{"sdk":{"version": "3.1.100","rollForward": "latestFeature"}}' > ./subdirectory/global.json
443+
- name: Setup dotnet
444+
uses: ./
445+
with:
446+
global-json-file: ./subdirectory/global.json
447+
- name: Verify dotnet
448+
shell: pwsh
449+
run: __tests__/verify-dotnet.ps1 -Patterns "^3.1.4"
450+
451+
test-setup-global-json-rollforward-latestpatch:
452+
runs-on: ${{ matrix.operating-system }}
453+
strategy:
454+
fail-fast: false
455+
matrix:
456+
operating-system: [ubuntu-latest, windows-latest, macos-13]
457+
steps:
458+
- name: Checkout
459+
uses: actions/checkout@v3
460+
- name: Clear toolcache
461+
shell: pwsh
462+
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
463+
- name: Write global.json
464+
shell: bash
465+
run: |
466+
mkdir subdirectory
467+
echo '{"sdk":{"version": "5.0.400","rollForward": "latestPatch"}}' > ./subdirectory/global.json
468+
- name: Setup dotnet
469+
uses: ./
470+
with:
471+
global-json-file: ./subdirectory/global.json
472+
- name: Verify dotnet
473+
shell: pwsh
474+
run: __tests__/verify-dotnet.ps1 -Patterns "^5.0.408$"
475+
376476
test-setup-global-json-only:
377477
runs-on: ${{ matrix.operating-system }}
378478
strategy:

dist/setup/index.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99758,9 +99758,23 @@ function getVersionFromGlobalJson(globalJsonPath) {
9975899758
if (globalJson.sdk && globalJson.sdk.version) {
9975999759
version = globalJson.sdk.version;
9976099760
const rollForward = globalJson.sdk.rollForward;
99761-
if (rollForward && rollForward === 'latestFeature') {
99762-
const [major, minor] = version.split('.');
99763-
version = `${major}.${minor}`;
99761+
if (rollForward) {
99762+
const [major, minor, featurePatch] = version.split('.');
99763+
const feature = featurePatch.substring(0, 1);
99764+
switch (rollForward) {
99765+
case 'latestMajor':
99766+
version = '';
99767+
break;
99768+
case 'latestMinor':
99769+
version = `${major}`;
99770+
break;
99771+
case 'latestFeature':
99772+
version = `${major}.${minor}`;
99773+
break;
99774+
case 'latestPatch':
99775+
version = `${major}.${minor}.${feature}xx`;
99776+
break;
99777+
}
9976499778
}
9976599779
}
9976699780
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)