Skip to content

Commit edd8df8

Browse files
Simplify net8/net9 testing (#220)
Co-authored-by: Chet Husk <[email protected]>
1 parent 77a63fa commit edd8df8

File tree

6 files changed

+83
-68
lines changed

6 files changed

+83
-68
lines changed

.config/dotnet-tools.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
{
2-
"version": 1,
3-
"isRoot": true,
4-
"tools": {}
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"fantomas": {
6+
"version": "6.3.16",
7+
"commands": [
8+
"fantomas"
9+
],
10+
"rollForward": false
11+
}
12+
}
513
}

.fantomasignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
test/examples
22
obj/**/*.fs
3+
test/testrun_ws/

.github/workflows/build.yml

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,65 +10,33 @@ jobs:
1010
build:
1111
strategy:
1212
matrix:
13+
# Builds for Ubuntu, Windows, and macOS
1314
os: [ubuntu-latest, windows-latest, macOS-latest]
14-
dotnet-version: ["", "8.0.x", "9.0.x"]
15-
# these entries will mesh with the above combinations
16-
include:
17-
# just use what's in the repo
18-
- global-json-file: "global.json"
19-
dotnet-version: ""
20-
label: "repo global.json"
21-
build_net9: false
22-
globaljson-command: "dotnet new globaljson --sdk-version 8.0.400"
23-
# latest 8.0 stable
24-
- global-json-file: "global.json"
25-
dotnet-version: "8.0.x"
26-
label: "8.0 stable"
27-
build_net9: false
28-
globaljson-command: "dotnet new globaljson --sdk-version 8.0.0 --roll-forward latestMinor"
29-
# latest 9.0 stable
30-
- global-json-file: "global.json"
31-
dotnet-version: "9.0.x"
32-
label: "9.0 stable"
33-
build_net9: true
34-
globaljson-command: "dotnet new globaljson --sdk-version 9.0.0 --roll-forward latestMinor"
35-
fail-fast: false # we have timing issues on some OS, so we want them all to run
15+
fail-fast: false
3616
runs-on: ${{ matrix.os }}
37-
timeout-minutes: 15
38-
39-
name: Build on ${{matrix.os}} for ${{ matrix.label }}
4017

4118
steps:
4219
- uses: actions/checkout@v3
4320

44-
# setup .NET per the repo global.json
45-
- name: Setup .NET
46-
uses: actions/setup-dotnet@v4
47-
48-
# setup .NET per test session
21+
# setup .NET SDK
4922
- name: Setup .NET
5023
uses: actions/setup-dotnet@v4
5124
with:
52-
global-json-file: ${{ matrix.global-json-file }}
53-
dotnet-version: ${{ matrix.dotnet-version }}
54-
55-
# remove global.json, create new one to protect against CI machine installed defaults. Then the env configuration takes precedence
56-
- name: Purge global.json
57-
run: |
58-
rm global.json
59-
${{ matrix.globaljson-command }}
25+
global-json-file: 'global.json'
26+
dotnet-version: |
27+
8.x
28+
9.x
6029
6130
# let's make sure we're on the version we think we are.
6231
- name: Announce .NET version
32+
continue-on-error: true
6333
run: dotnet --info
6434

6535
- name: Restore tools
6636
run: dotnet tool restore
6737

6838
- name: Run build and test
6939
run: dotnet run --project build
70-
env:
71-
BuildNet9: ${{ matrix.build_net9 }}
7240

7341
- name: Archive test results
7442
uses: actions/upload-artifact@v3

.vscode/launch.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"version": "0.2.0",
33
"configurations": [
44
{
5-
"name": "Launch Tool 6.0 graph resolver",
5+
"name": "Launch Tool 8.0 graph resolver",
66
"type": "coreclr",
77
"request": "launch",
8-
"program": "${workspaceFolder}/src/Ionide.ProjInfo.Tool/bin/Debug/net6.0/Ionide.ProjInfo.Tool.dll",
8+
"program": "${workspaceFolder}/src/Ionide.ProjInfo.Tool/bin/Debug/net8.0/Ionide.ProjInfo.Tool.dll",
99
"args": [
1010
"--project",
1111
"<your project>",
@@ -17,10 +17,10 @@
1717
"justMyCode": true,
1818
},
1919
{
20-
"name": "Launch Tool 6.0 normal resolver",
20+
"name": "Launch Tool 8.0 normal resolver",
2121
"type": "coreclr",
2222
"request": "launch",
23-
"program": "${workspaceFolder}/src/Ionide.ProjInfo.Tool/bin/Debug/net6.0/Ionide.ProjInfo.Tool.dll",
23+
"program": "${workspaceFolder}/src/Ionide.ProjInfo.Tool/bin/Debug/net8.0/Ionide.ProjInfo.Tool.dll",
2424
"args": [
2525
"--project",
2626
"<your project>",
@@ -54,8 +54,8 @@
5454
"id": "tfm",
5555
"description": "The TFM of the test to run",
5656
"options": [
57-
"net6.0",
58-
"net7.0"
57+
"net8.0",
58+
"net9.0"
5959
],
6060
"default": "net7.0",
6161
"type": "pickString"

CONTRIBUTING.md

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,24 @@ Our current algorithm is
1414

1515
So if you set global.json to a 9.0.xxx SDK, you'll _always_ use the 9.x MSBuild libraries, which will require the 9.0 runtime to load. If you want to test while loading older MSBuilds, you'll need to somehow constraint the tests to 8.0.xxx SDKs, and the easiest way to do this is to make a global.json with a 8.0.xxx version and a `rollForward: latestPatch` constraint on it.
1616

17-
### Against LTS (net8.0)
18-
1. Run tests with `dotnet run --project .\build\ -- -t Test`
19-
1. This should chose the `Test:net8.0` target and run against that runtime
17+
### Running tests from FAKE
2018

19+
Our FAKE build project will handle creating/deleting a temporary `global.json` file in the `test` directory for you.
2120

22-
### Against STS (net9.0)
21+
1. `dotnet run --project .\build\ -- -t Test`
22+
1. This should chose the `Test:net8.0` and `Test:net9.0` targets and run against that respective runtime.
23+
24+
### Manually invoking dotnet test
25+
26+
If you want to run `dotnet test` directly, you'll need to set the `global.json` file and environment variables yourself.
27+
28+
#### Against LTS (net8.0)
29+
1. Move to the test project
30+
1. `cd test/Ionide.ProjInfo.Tests`
31+
2. Run tests with `dotnet test`
32+
33+
34+
#### Against STS (net9.0)
2335
1. Change global.json to use net9.0
2436
```json
2537
"sdk": {
@@ -28,11 +40,16 @@ So if you set global.json to a 9.0.xxx SDK, you'll _always_ use the 9.x MSBuild
2840
"allowPrerelease": true
2941
}
3042
```
31-
2. Set environment variable `BuildNet9` to `true`
43+
1. Move to the test project
44+
1. `cd test/Ionide.ProjInfo.Tests`
45+
3. Set environment variable `BuildNet9` to `true`
3246
1. Bash: `export BuildNet9=true`
3347
2. PowerShell: `$env:BuildNet9 = "true"`
34-
3. Run tests with `dotnet run --project .\build\ -- -t Test`
35-
1. This should chose the `Test:net9.0` target and run against that runtime
48+
4. Run tests with `dotnet test`
49+
50+
51+
52+
3653

3754
## Release
3855

build/Program.fs

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ System.Environment.CurrentDirectory <- (Path.combine __SOURCE_DIRECTORY__ "..")
1111
// --------------------------------------------------------------------------------------
1212
let isNullOrWhiteSpace = System.String.IsNullOrWhiteSpace
1313

14-
let exec cmd args dir =
14+
let exec cmd args dir env =
1515
let proc =
1616
CreateProcess.fromRawCommandLine cmd args
1717
|> CreateProcess.ensureExitCodeWithMessage (sprintf "Error while running '%s' with args: %s" cmd args)
18+
|> CreateProcess.withEnvironment (Map.toList env)
1819

1920
(if isNullOrWhiteSpace dir then
2021
proc
@@ -31,16 +32,14 @@ let initializeContext args =
3132
let getBuildParam = Environment.environVar
3233
let DoNothing = ignore
3334

35+
3436
let init args =
3537
initializeContext args
3638

37-
let buildNet9 =
38-
match
39-
System.Environment.GetEnvironmentVariable("BuildNet9")
40-
|> bool.TryParse
41-
with
42-
| true, v -> v
43-
| _ -> false
39+
let configuration =
40+
match getBuildParam "CONFIGURATION" with
41+
| s when not (isNullOrWhiteSpace s) -> s
42+
| _ -> "Release"
4443

4544
let ignoreTests =
4645
match
@@ -66,26 +65,48 @@ let init args =
6665
opts.MSBuildParams with
6766
DisableInternalBinLog = true
6867
}
68+
Configuration = DotNet.BuildConfiguration.fromString configuration
6969
}
7070

7171
Target.create "Build" (fun _ -> DotNet.build buildOpts "")
7272

73+
let tfmToSdkMap =
74+
Map.ofSeq [
75+
"net8.0", "8.0.100"
76+
"net9.0", "9.0.100"
77+
]
78+
79+
let tfmToBuildNet9Map =
80+
Map.ofSeq [
81+
"net8.0", false
82+
"net9.0", true
83+
]
84+
7385
let testTFM tfm =
74-
exec "dotnet" $"test --blame --blame-hang-timeout 60s --no-build --framework {tfm} --logger trx --logger GitHubActions -c Release .\\test\\Ionide.ProjInfo.Tests\\Ionide.ProjInfo.Tests.fsproj" "."
75-
|> ignore
86+
try
87+
exec "dotnet" $"new globaljson --force --sdk-version {tfmToSdkMap.[tfm]} --roll-forward LatestMinor" "test" Map.empty
88+
89+
exec
90+
"dotnet"
91+
$"test --blame --blame-hang-timeout 60s --framework {tfm} --logger trx --logger GitHubActions -c {configuration} .\\Ionide.ProjInfo.Tests\\Ionide.ProjInfo.Tests.fsproj"
92+
"test"
93+
(Map.ofSeq [ "BuildNet9", tfmToBuildNet9Map.[tfm].ToString() ])
94+
|> ignore
95+
finally
96+
System.IO.File.Delete "test\\global.json"
7697

7798
Target.create "Test" DoNothing
7899

79100
Target.create "Test:net8.0" (fun _ -> testTFM "net8.0")
80101
Target.create "Test:net9.0" (fun _ -> testTFM "net9.0")
81102

82103
"Build"
83-
=?> ("Test:net8.0", not buildNet9)
104+
==> ("Test:net8.0")
84105
=?> ("Test", not ignoreTests)
85106
|> ignore
86107

87108
"Build"
88-
=?> ("Test:net9.0", buildNet9)
109+
==> ("Test:net9.0")
89110
=?> ("Test", not ignoreTests)
90111
|> ignore
91112

0 commit comments

Comments
 (0)