From bc45ec257e49369a81034efde8f332131029f548 Mon Sep 17 00:00:00 2001 From: Chris Philips Date: Wed, 15 Nov 2023 11:58:12 -0800 Subject: [PATCH 1/4] feat: support rollForward latest variants --- .github/workflows/e2e-tests.yml | 77 ++++++++++++++++++++++++++++++++- dist/setup/index.js | 24 ++++++++-- src/setup-dotnet.ts | 24 ++++++++-- 3 files changed, 118 insertions(+), 7 deletions(-) diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index 332eebccb..f266bc091 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -203,7 +203,82 @@ jobs: - name: Verify dotnet shell: pwsh run: __tests__/verify-dotnet.ps1 -Patterns "^2.2", "^3.1" - + + test-setup-global-json-rollforward-latestminor: + runs-on: ${{ matrix.operating-system }} + strategy: + fail-fast: false + matrix: + operating-system: [ ubuntu-latest, windows-latest, macOS-latest ] + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Clear toolcache + shell: pwsh + run: __tests__/clear-toolcache.ps1 ${{ runner.os }} + - name: Write global.json + shell: bash + run: | + mkdir subdirectory + echo '{"sdk":{"version": "3.0.100","rollForward": "latestMinor"}}' > ./subdirectory/global.json + - name: Setup dotnet + uses: ./ + with: + global-json-file: ./subdirectory/global.json + - name: Verify dotnet + shell: pwsh + run: __tests__/verify-dotnet.ps1 -Patterns "^3.1" + + test-setup-global-json-rollforward-latestfeature: + runs-on: ${{ matrix.operating-system }} + strategy: + fail-fast: false + matrix: + operating-system: [ ubuntu-latest, windows-latest, macOS-latest ] + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Clear toolcache + shell: pwsh + run: __tests__/clear-toolcache.ps1 ${{ runner.os }} + - name: Write global.json + shell: bash + run: | + mkdir subdirectory + echo '{"sdk":{"version": "3.1.100","rollForward": "latestFeature"}}' > ./subdirectory/global.json + - name: Setup dotnet + uses: ./ + with: + global-json-file: ./subdirectory/global.json + - name: Verify dotnet + shell: pwsh + run: __tests__/verify-dotnet.ps1 -Patterns "^3.1.4" + + test-setup-global-json-rollforward-latestpatch: + runs-on: ${{ matrix.operating-system }} + strategy: + fail-fast: false + matrix: + operating-system: [ ubuntu-latest, windows-latest, macOS-latest ] + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Clear toolcache + shell: pwsh + run: __tests__/clear-toolcache.ps1 ${{ runner.os }} + - name: Write global.json + shell: bash + run: | + mkdir subdirectory + echo '{"sdk":{"version": "3.1.400","rollForward": "latestPatch"}}' > ./subdirectory/global.json + - name: Setup dotnet + uses: ./ + with: + global-json-file: ./subdirectory/global.json + - name: Verify dotnet + shell: pwsh + run: __tests__/verify-dotnet.ps1 -Patterns "^3.1.426$" + test-setup-global-json-only: runs-on: ${{ matrix.operating-system }} strategy: diff --git a/dist/setup/index.js b/dist/setup/index.js index 7567a1bdf..466724aeb 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -73235,9 +73235,27 @@ function getVersionFromGlobalJson(globalJsonPath) { if (globalJson.sdk && globalJson.sdk.version) { version = globalJson.sdk.version; const rollForward = globalJson.sdk.rollForward; - if (rollForward && rollForward === 'latestFeature') { - const [major, minor] = version.split('.'); - version = `${major}.${minor}`; + if (rollForward && rollForward.startsWith('latest')) { + const [major, minor, featurePatch] = version.split('.'); + const feature = featurePatch.substring(0, 1); + + switch (rollForward) { + case 'latestMajor': + version = ''; + break; + + case 'latestMinor': + version = `${major}`; + break; + + case 'latestFeature': + version = `${major}.${minor}`; + break; + + case 'latestPatch': + version = `${major}.${minor}.${feature}` + break; + } } } return version; diff --git a/src/setup-dotnet.ts b/src/setup-dotnet.ts index 2a628a5ab..092bf59df 100644 --- a/src/setup-dotnet.ts +++ b/src/setup-dotnet.ts @@ -110,9 +110,27 @@ function getVersionFromGlobalJson(globalJsonPath: string): string { if (globalJson.sdk && globalJson.sdk.version) { version = globalJson.sdk.version; const rollForward = globalJson.sdk.rollForward; - if (rollForward && rollForward === 'latestFeature') { - const [major, minor] = version.split('.'); - version = `${major}.${minor}`; + if (rollForward && rollForward.startsWith('latest')) { + const [major, minor, featurePatch] = version.split('.'); + const feature = featurePatch.substring(0, 1); + + switch (rollForward) { + case 'latestMajor': + version = ''; + break; + + case 'latestMinor': + version = `${major}`; + break; + + case 'latestFeature': + version = `${major}.${minor}`; + break; + + case 'latestPatch': + version = `${major}.${minor}.${feature}` + break; + } } } return version; From 3089bb1ebdea5c87c2358d4aab8cc7da657e74ad Mon Sep 17 00:00:00 2001 From: Chris Philips Date: Wed, 15 Nov 2023 13:35:07 -0800 Subject: [PATCH 2/4] fix: allow null version the only way this is valid is if rollForward is `latestMajor`, which is the only value that the global.json spec says doesn't require a version to be specified --- src/setup-dotnet.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/setup-dotnet.ts b/src/setup-dotnet.ts index 092bf59df..0e8edb6e0 100644 --- a/src/setup-dotnet.ts +++ b/src/setup-dotnet.ts @@ -111,7 +111,7 @@ function getVersionFromGlobalJson(globalJsonPath: string): string { version = globalJson.sdk.version; const rollForward = globalJson.sdk.rollForward; if (rollForward && rollForward.startsWith('latest')) { - const [major, minor, featurePatch] = version.split('.'); + const [major, minor, featurePatch] = (version || '').split('.'); const feature = featurePatch.substring(0, 1); switch (rollForward) { From 9e7964056528446ce5ed406078129b69549a290b Mon Sep 17 00:00:00 2001 From: Chris Philips Date: Fri, 22 Mar 2024 11:34:19 -0700 Subject: [PATCH 3/4] Update src/setup-dotnet.ts Co-authored-by: js6pak --- src/setup-dotnet.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/setup-dotnet.ts b/src/setup-dotnet.ts index 0e8edb6e0..d6bdbddbe 100644 --- a/src/setup-dotnet.ts +++ b/src/setup-dotnet.ts @@ -128,7 +128,7 @@ function getVersionFromGlobalJson(globalJsonPath: string): string { break; case 'latestPatch': - version = `${major}.${minor}.${feature}` + version = `${major}.${minor}.${feature}xx` break; } } From 43ef2eefe75604781e356406631a2985cc6c8550 Mon Sep 17 00:00:00 2001 From: Chris Philips Date: Fri, 22 Mar 2024 11:39:06 -0700 Subject: [PATCH 4/4] Apply suggestions from code review --- src/setup-dotnet.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/setup-dotnet.ts b/src/setup-dotnet.ts index d6bdbddbe..6147f1260 100644 --- a/src/setup-dotnet.ts +++ b/src/setup-dotnet.ts @@ -120,11 +120,11 @@ function getVersionFromGlobalJson(globalJsonPath: string): string { break; case 'latestMinor': - version = `${major}`; + version = `${major}.x`; break; case 'latestFeature': - version = `${major}.${minor}`; + version = `${major}.${minor}.x`; break; case 'latestPatch':