Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify net8 net9 testing #220

Merged
merged 6 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
{
"version": 1,
"isRoot": true,
"tools": {}
"version": 1,
"isRoot": true,
"tools": {
"fantomas": {
"version": "6.3.16",
"commands": [
"fantomas"
],
"rollForward": false
}
}
}
1 change: 1 addition & 0 deletions .fantomasignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
test/examples
obj/**/*.fs
test/testrun_ws/
48 changes: 8 additions & 40 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,65 +10,33 @@ jobs:
build:
strategy:
matrix:
# Builds for Ubuntu, Windows, and macOS
os: [ubuntu-latest, windows-latest, macOS-latest]
dotnet-version: ["", "8.0.x", "9.0.x"]
# these entries will mesh with the above combinations
include:
# just use what's in the repo
- global-json-file: "global.json"
dotnet-version: ""
label: "repo global.json"
build_net9: false
globaljson-command: "dotnet new globaljson --sdk-version 8.0.400"
# latest 8.0 stable
- global-json-file: "global.json"
dotnet-version: "8.0.x"
label: "8.0 stable"
build_net9: false
globaljson-command: "dotnet new globaljson --sdk-version 8.0.0 --roll-forward latestMinor"
# latest 9.0 stable
- global-json-file: "global.json"
dotnet-version: "9.0.x"
label: "9.0 stable"
build_net9: true
globaljson-command: "dotnet new globaljson --sdk-version 9.0.0 --roll-forward latestMinor"
fail-fast: false # we have timing issues on some OS, so we want them all to run
fail-fast: false
runs-on: ${{ matrix.os }}
timeout-minutes: 15

name: Build on ${{matrix.os}} for ${{ matrix.label }}

steps:
- uses: actions/checkout@v3

# setup .NET per the repo global.json
- name: Setup .NET
uses: actions/setup-dotnet@v4

# setup .NET per test session
# setup .NET SDK
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
global-json-file: ${{ matrix.global-json-file }}
dotnet-version: ${{ matrix.dotnet-version }}

# remove global.json, create new one to protect against CI machine installed defaults. Then the env configuration takes precedence
- name: Purge global.json
run: |
rm global.json
${{ matrix.globaljson-command }}
global-json-file: 'global.json'
dotnet-version: |
8.x
9.x

# let's make sure we're on the version we think we are.
- name: Announce .NET version
continue-on-error: true
run: dotnet --info

- name: Restore tools
run: dotnet tool restore

- name: Run build and test
run: dotnet run --project build
env:
BuildNet9: ${{ matrix.build_net9 }}

- name: Archive test results
uses: actions/upload-artifact@v3
Expand Down
12 changes: 6 additions & 6 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"version": "0.2.0",
"configurations": [
{
"name": "Launch Tool 6.0 graph resolver",
"name": "Launch Tool 8.0 graph resolver",
"type": "coreclr",
"request": "launch",
"program": "${workspaceFolder}/src/Ionide.ProjInfo.Tool/bin/Debug/net6.0/Ionide.ProjInfo.Tool.dll",
"program": "${workspaceFolder}/src/Ionide.ProjInfo.Tool/bin/Debug/net8.0/Ionide.ProjInfo.Tool.dll",
"args": [
"--project",
"<your project>",
Expand All @@ -17,10 +17,10 @@
"justMyCode": true,
},
{
"name": "Launch Tool 6.0 normal resolver",
"name": "Launch Tool 8.0 normal resolver",
"type": "coreclr",
"request": "launch",
"program": "${workspaceFolder}/src/Ionide.ProjInfo.Tool/bin/Debug/net6.0/Ionide.ProjInfo.Tool.dll",
"program": "${workspaceFolder}/src/Ionide.ProjInfo.Tool/bin/Debug/net8.0/Ionide.ProjInfo.Tool.dll",
"args": [
"--project",
"<your project>",
Expand Down Expand Up @@ -54,8 +54,8 @@
"id": "tfm",
"description": "The TFM of the test to run",
"options": [
"net6.0",
"net7.0"
"net8.0",
"net9.0"
],
"default": "net7.0",
"type": "pickString"
Expand Down
31 changes: 24 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,24 @@ Our current algorithm is

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.

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

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

### Against STS (net9.0)
1. `dotnet run --project .\build\ -- -t Test`
1. This should chose the `Test:net8.0` and `Test:net9.0` targets and run against that respective runtime.

### Manually invoking dotnet test

If you want to run `dotnet test` directly, you'll need to set the `global.json` file and environment variables yourself.

#### Against LTS (net8.0)
1. Move to the test project
1. `cd test/Ionide.ProjInfo.Tests`
2. Run tests with `dotnet test`


#### Against STS (net9.0)
1. Change global.json to use net9.0
```json
"sdk": {
Expand All @@ -28,11 +40,16 @@ So if you set global.json to a 9.0.xxx SDK, you'll _always_ use the 9.x MSBuild
"allowPrerelease": true
}
```
2. Set environment variable `BuildNet9` to `true`
1. Move to the test project
1. `cd test/Ionide.ProjInfo.Tests`
3. Set environment variable `BuildNet9` to `true`
1. Bash: `export BuildNet9=true`
2. PowerShell: `$env:BuildNet9 = "true"`
3. Run tests with `dotnet run --project .\build\ -- -t Test`
1. This should chose the `Test:net9.0` target and run against that runtime
4. Run tests with `dotnet test`





## Release

Expand Down
45 changes: 33 additions & 12 deletions build/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ System.Environment.CurrentDirectory <- (Path.combine __SOURCE_DIRECTORY__ "..")
// --------------------------------------------------------------------------------------
let isNullOrWhiteSpace = System.String.IsNullOrWhiteSpace

let exec cmd args dir =
let exec cmd args dir env =
let proc =
CreateProcess.fromRawCommandLine cmd args
|> CreateProcess.ensureExitCodeWithMessage (sprintf "Error while running '%s' with args: %s" cmd args)
|> CreateProcess.withEnvironment (Map.toList env)

(if isNullOrWhiteSpace dir then
proc
Expand All @@ -31,16 +32,14 @@ let initializeContext args =
let getBuildParam = Environment.environVar
let DoNothing = ignore


let init args =
initializeContext args

let buildNet9 =
match
System.Environment.GetEnvironmentVariable("BuildNet9")
|> bool.TryParse
with
| true, v -> v
| _ -> false
let configuration =
match getBuildParam "CONFIGURATION" with
| s when not (isNullOrWhiteSpace s) -> s
| _ -> "Release"

let ignoreTests =
match
Expand All @@ -66,26 +65,48 @@ let init args =
opts.MSBuildParams with
DisableInternalBinLog = true
}
Configuration = DotNet.BuildConfiguration.fromString configuration
}

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

let tfmToSdkMap =
Map.ofSeq [
"net8.0", "8.0.100"
"net9.0", "9.0.100"
]

let tfmToBuildNet9Map =
Map.ofSeq [
"net8.0", false
"net9.0", true
]

let testTFM tfm =
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" "."
|> ignore
try
exec "dotnet" $"new globaljson --force --sdk-version {tfmToSdkMap.[tfm]} --roll-forward LatestMinor" "test" Map.empty

exec
"dotnet"
$"test --blame --blame-hang-timeout 60s --framework {tfm} --logger trx --logger GitHubActions -c {configuration} .\\Ionide.ProjInfo.Tests\\Ionide.ProjInfo.Tests.fsproj"
"test"
(Map.ofSeq [ "BuildNet9", tfmToBuildNet9Map.[tfm].ToString() ])
|> ignore
finally
System.IO.File.Delete "test\\global.json"

Target.create "Test" DoNothing

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

"Build"
=?> ("Test:net8.0", not buildNet9)
==> ("Test:net8.0")
=?> ("Test", not ignoreTests)
|> ignore

"Build"
=?> ("Test:net9.0", buildNet9)
==> ("Test:net9.0")
=?> ("Test", not ignoreTests)
|> ignore

Expand Down
Loading