From 8a21b4ed1527c384b6d4b7919db11dcb8389065c Mon Sep 17 00:00:00 2001 From: Chris Philips Date: Wed, 15 Nov 2023 11:58:12 -0800 Subject: [PATCH] Support global.json's rollForward latest* variants Co-authored-by: js6pak --- .github/workflows/e2e-tests.yml | 100 ++++++++++++++++++++++++++++++++ dist/setup/index.js | 20 ++++++- src/setup-dotnet.ts | 24 +++++++- 3 files changed, 138 insertions(+), 6 deletions(-) diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index 9b26d7b..d9c51f8 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -201,6 +201,106 @@ jobs: shell: pwsh run: __tests__/verify-dotnet.ps1 -Patterns "^2.2", "^3.1" + test-setup-global-json-rollforward-latestmajor: + runs-on: ${{ matrix.operating-system }} + strategy: + fail-fast: false + matrix: + operating-system: [ubuntu-latest, windows-latest, macos-13] + 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.0","rollForward": "latestMajor"}}' > ./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)" + + test-setup-global-json-rollforward-latestminor: + runs-on: ${{ matrix.operating-system }} + strategy: + fail-fast: false + matrix: + operating-system: [ubuntu-latest, windows-latest, macos-13] + 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-13] + 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-13] + 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": "5.0.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 "^5.0.408$" + test-setup-global-json-only: runs-on: ${{ matrix.operating-system }} strategy: diff --git a/dist/setup/index.js b/dist/setup/index.js index 405862d..6d3a0e4 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -94096,9 +94096,23 @@ 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) { + 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}xx`; + break; + } } } return version; diff --git a/src/setup-dotnet.ts b/src/setup-dotnet.ts index 2a628a5..6043456 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) { + 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}xx`; + break; + } } } return version;