Skip to content

Commit 98af08b

Browse files
authored
Support global.json's rollForward latest* variants (#538)
* Rename toolcache directory instead of moving to tmp This further enhances time savings seen in #213, down from a few minutes to seconds. * Remove branch constraint on workflows used for testing This means you are going to be notified of CI issues quicker, especially if you have to wait for a confirmation before running the workflows on your PR. * Support global.json's rollForward latest* variants * Remove e2e-test's dependency on Microsoft.NET.Test.Sdk The newer versions are net8.0/net462+ only, making older .NET sdks more annoying to test * Revert "Remove e2e-test's dependency on Microsoft.NET.Test.Sdk" This reverts commit 14839a662649cdea79ccecc3a7ce9a91386185b4. * Don't run unsupported versions in global.json tests * Revert "Remove branch constraint on workflows used for testing" This reverts commit d9dae35.
1 parent 8404272 commit 98af08b

4 files changed

Lines changed: 115 additions & 8 deletions

File tree

.github/workflows/e2e-tests.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,81 @@ jobs:
257257
shell: pwsh
258258
run: __tests__/verify-dotnet.ps1 -Patterns "^9.0", "^10.0"
259259

260+
test-setup-global-json-rollforward-latestmajor:
261+
runs-on: ${{ matrix.operating-system }}
262+
strategy:
263+
fail-fast: false
264+
matrix:
265+
operating-system: [ubuntu-latest, windows-latest, macos-latest]
266+
steps:
267+
- name: Checkout
268+
uses: actions/checkout@v6
269+
- name: Clear toolcache
270+
shell: pwsh
271+
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
272+
- name: Write global.json
273+
shell: bash
274+
run: |
275+
mkdir subdirectory
276+
echo '{"sdk":{"version": "3.1.0","rollForward": "latestMajor"}}' > ./subdirectory/global.json
277+
- name: Setup dotnet
278+
uses: ./
279+
with:
280+
global-json-file: ./subdirectory/global.json
281+
- name: Verify dotnet
282+
shell: pwsh
283+
run: __tests__/verify-dotnet.ps1 -Patterns "^(?!3)"
284+
285+
test-setup-global-json-rollforward-latestfeature:
286+
runs-on: ${{ matrix.operating-system }}
287+
strategy:
288+
fail-fast: false
289+
matrix:
290+
operating-system: [ubuntu-latest, windows-latest, macos-latest]
291+
steps:
292+
- name: Checkout
293+
uses: actions/checkout@v6
294+
- name: Clear toolcache
295+
shell: pwsh
296+
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
297+
- name: Write global.json
298+
shell: bash
299+
run: |
300+
mkdir subdirectory
301+
echo '{"sdk":{"version": "10.0.100","rollForward": "latestFeature"}}' > ./subdirectory/global.json
302+
- name: Setup dotnet
303+
uses: ./
304+
with:
305+
global-json-file: ./subdirectory/global.json
306+
- name: Verify dotnet
307+
shell: pwsh
308+
run: __tests__/verify-dotnet.ps1 -Patterns "^10.0.(?!1)"
309+
310+
test-setup-global-json-rollforward-latestpatch:
311+
runs-on: ${{ matrix.operating-system }}
312+
strategy:
313+
fail-fast: false
314+
matrix:
315+
operating-system: [ubuntu-latest, windows-latest, macos-latest]
316+
steps:
317+
- name: Checkout
318+
uses: actions/checkout@v6
319+
- name: Clear toolcache
320+
shell: pwsh
321+
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
322+
- name: Write global.json
323+
shell: bash
324+
run: |
325+
mkdir subdirectory
326+
echo '{"sdk":{"version": "10.0.100","rollForward": "latestPatch"}}' > ./subdirectory/global.json
327+
- name: Setup dotnet
328+
uses: ./
329+
with:
330+
global-json-file: ./subdirectory/global.json
331+
- name: Verify dotnet
332+
shell: pwsh
333+
run: __tests__/verify-dotnet.ps1 -Patterns "^10.0.1(?!00)"
334+
260335
test-setup-global-json-only:
261336
runs-on: ${{ matrix.operating-system }}
262337
strategy:

__tests__/clear-toolcache.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ $dotnetPaths = @{
66

77
foreach ($srcPath in $dotnetPaths[$args[0]]) {
88
if (Test-Path $srcPath) {
9-
Write-Host "Move $srcPath path"
10-
$dstPath = Join-Path ([IO.Path]::GetTempPath()) ([IO.Path]::GetRandomFileName())
9+
$dstPath = "$srcPath-" + [IO.Path]::GetRandomFileName()
10+
Write-Host "Moving $srcPath to $dstPath"
1111
Move-Item -Path $srcPath -Destination $dstPath
1212
}
1313
}

dist/setup/index.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79244,9 +79244,23 @@ function getVersionFromGlobalJson(globalJsonPath) {
7924479244
if (globalJson.sdk && globalJson.sdk.version) {
7924579245
version = globalJson.sdk.version;
7924679246
const rollForward = globalJson.sdk.rollForward;
79247-
if (rollForward && rollForward === 'latestFeature') {
79248-
const [major, minor] = version.split('.');
79249-
version = `${major}.${minor}`;
79247+
if (rollForward) {
79248+
const [major, minor, featurePatch] = version.split('.');
79249+
const feature = featurePatch.substring(0, 1);
79250+
switch (rollForward) {
79251+
case 'latestMajor':
79252+
version = '';
79253+
break;
79254+
case 'latestMinor':
79255+
version = `${major}`;
79256+
break;
79257+
case 'latestFeature':
79258+
version = `${major}.${minor}`;
79259+
break;
79260+
case 'latestPatch':
79261+
version = `${major}.${minor}.${feature}xx`;
79262+
break;
79263+
}
7925079264
}
7925179265
}
7925279266
return version;

src/setup-dotnet.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,27 @@ function getVersionFromGlobalJson(globalJsonPath: string): string {
207207
if (globalJson.sdk && globalJson.sdk.version) {
208208
version = globalJson.sdk.version;
209209
const rollForward = globalJson.sdk.rollForward;
210-
if (rollForward && rollForward === 'latestFeature') {
211-
const [major, minor] = version.split('.');
212-
version = `${major}.${minor}`;
210+
if (rollForward) {
211+
const [major, minor, featurePatch] = version.split('.');
212+
const feature = featurePatch.substring(0, 1);
213+
214+
switch (rollForward) {
215+
case 'latestMajor':
216+
version = '';
217+
break;
218+
219+
case 'latestMinor':
220+
version = `${major}`;
221+
break;
222+
223+
case 'latestFeature':
224+
version = `${major}.${minor}`;
225+
break;
226+
227+
case 'latestPatch':
228+
version = `${major}.${minor}.${feature}xx`;
229+
break;
230+
}
213231
}
214232
}
215233
return version;

0 commit comments

Comments
 (0)