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

Coverage report tweaks #272

Merged
merged 3 commits into from
Jun 9, 2023
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
2 changes: 2 additions & 0 deletions Content/Library/.github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ jobs:
./build.sh
env:
CI: true
ENABLE_COVERAGE: true
- name: Build via Windows
if: runner.os == 'Windows'
run: ./build.cmd
env:
CI: true
ENABLE_COVERAGE: true
2 changes: 1 addition & 1 deletion Content/Library/.github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
NUGET_TOKEN: ${{ secrets.NUGET_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FAKE_DETAILED_ERRORS: true
DISABLE_COVERAGE: true # AltCover doesn't work with Release builds, reports lower coverage than actual
ENABLE_COVERAGE: false # AltCover doesn't work with Release builds, reports lower coverage than actual
run: |
chmod +x ./build.sh
./build.sh Publish
5 changes: 3 additions & 2 deletions Content/Library/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ or

- `CONFIGURATION` will set the [configuration](https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-build?tabs=netcore2x#options) of the dotnet commands. If not set, it will default to Release.
- `CONFIGURATION=Debug ./build.sh` will result in `-c` additions to commands such as in `dotnet build -c Debug`
- `DISABLE_COVERAGE` Will disable running code coverage metrics. AltCover can have [severe performance degradation](https://github.com/SteveGilham/altcover/issues/57) so it's worth disabling when looking to do a quicker feedback loop.
- `DISABLE_COVERAGE=1 ./build.sh`
- `ENABLE_COVERAGE` Will enable running code coverage metrics. AltCover can have [severe performance degradation](https://github.com/SteveGilham/altcover/issues/57) so code coverage evaluation are disabled by default to speed up the feedback loop.
- `ENABLE_COVERAGE=1 ./build.sh` will enable code coverage evaluation


---
Expand Down Expand Up @@ -74,6 +74,7 @@ src/MyLib.1/bin/
- `FSharpAnalyzers` - Runs [BinaryDefense.FSharp.Analyzers](https://github.com/BinaryDefense/BinaryDefense.FSharp.Analyzers).
- `DotnetTest` - Runs [dotnet test](https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test?tabs=netcore21) on the [solution file](https://docs.microsoft.com/en-us/visualstudio/extensibility/internals/solution-dot-sln-file?view=vs-2019).
- `GenerateCoverageReport` - Code coverage is run during `DotnetTest` and this generates a report via [ReportGenerator](https://github.com/danielpalme/ReportGenerator).
- `ShowCoverageReport` - Shows the report generated in `GenerateCoverageReport`.
- `WatchTests` - Runs [dotnet watch](https://docs.microsoft.com/en-us/aspnet/core/tutorials/dotnet-watch?view=aspnetcore-3.0) with the test projects. Useful for rapid feedback loops.
- `GenerateAssemblyInfo` - Generates [AssemblyInfo](https://docs.microsoft.com/en-us/dotnet/api/microsoft.visualbasic.applicationservices.assemblyinfo?view=netframework-4.8) for libraries.
- `DotnetPack` - Runs [dotnet pack](https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-pack). This includes running [Source Link](https://github.com/dotnet/sourcelink).
Expand Down
32 changes: 27 additions & 5 deletions Content/Library/build/build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ let mutable changelogBackupFilename = ""

let publishUrl = "https://www.nuget.org"

let disableCodeCoverage = environVarAsBoolOrDefault "DISABLE_COVERAGE" false
let enableCodeCoverage = environVarAsBoolOrDefault "ENABLE_COVERAGE" false

let githubToken = Environment.environVarOrNone "GITHUB_TOKEN"

Expand Down Expand Up @@ -289,6 +289,10 @@ let failOnLocalBuild () =
if not isCI.Value then
failwith "Not on CI. If you want to publish, please use CI."

let failOnCIBuild () =
if isCI.Value then
failwith "On CI. If you want to run this target, please use a local build."

let allPublishChecks () =
failOnLocalBuild ()
Changelog.failOnEmptyChangelog latestEntry
Expand Down Expand Up @@ -403,12 +407,16 @@ let dotnetTest ctx =
|> Seq.map IO.Path.GetFileNameWithoutExtension
|> String.concat "|"

let isGenerateCoverageReport = ctx.Context.TryFindTarget("GenerateCoverageReport").IsSome

let args = [
"--no-build"
sprintf "/p:AltCover=%b" (not disableCodeCoverage)
sprintf "/p:AltCoverThreshold=%d" coverageThresholdPercent
sprintf "/p:AltCoverAssemblyExcludeFilter=%s" excludeCoverage
"/p:AltCoverLocalSource=true"
if enableCodeCoverage || isGenerateCoverageReport then
sprintf "/p:AltCover=true"
if not isGenerateCoverageReport then
sprintf "/p:AltCoverThreshold=%d" coverageThresholdPercent
sprintf "/p:AltCoverAssemblyExcludeFilter=%s" excludeCoverage
"/p:AltCoverLocalSource=true"
]

DotNet.test
Expand Down Expand Up @@ -449,6 +457,15 @@ let generateCoverageReport _ =

dotnet.reportgenerator id args

let showCoverageReport _ =
failOnCIBuild ()
coverageReportDir </> "index.html"
|> Command.ShellCommand
|> CreateProcess.fromCommand
|> Proc.start
|> ignore
TheAngryByrd marked this conversation as resolved.
Show resolved Hide resolved


let watchTests _ =
!!testsGlob
|> Seq.map (fun proj ->
Expand Down Expand Up @@ -714,6 +731,7 @@ let initTargets () =
Target.create "FSharpAnalyzers" fsharpAnalyzers
Target.create "DotnetTest" dotnetTest
Target.create "GenerateCoverageReport" generateCoverageReport
Target.create "ShowCoverageReport" showCoverageReport
Target.create "WatchTests" watchTests
Target.create "GenerateAssemblyInfo" generateAssemblyInfo
Target.create "DotnetPack" dotnetPack
Expand Down Expand Up @@ -770,6 +788,10 @@ let initTargets () =
"DotnetBuild"
==>! "WatchDocs"

"DotnetTest"
==> "GenerateCoverageReport"
==>! "ShowCoverageReport"

"UpdateChangelog"
==> "GenerateAssemblyInfo"
==> "GitRelease"
Expand Down