From 7d619358e02a63f60eaf9996db09a9843943fec1 Mon Sep 17 00:00:00 2001 From: nikoyak <99891966+nikoyak@users.noreply.github.com> Date: Thu, 8 Jun 2023 10:47:41 +0300 Subject: [PATCH 1/3] Tuned the GenerateCoverageReport target in the library template - Added dependency on Dotnetest - Closed TheAngryByrd#251 --- Content/Library/build/build.fs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Content/Library/build/build.fs b/Content/Library/build/build.fs index c46fdec6..9ce1c102 100644 --- a/Content/Library/build/build.fs +++ b/Content/Library/build/build.fs @@ -403,12 +403,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 not disableCodeCoverage || 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 @@ -770,6 +774,9 @@ let initTargets () = "DotnetBuild" ==>! "WatchDocs" + "DotnetTest" + ==>! "GenerateCoverageReport" + "UpdateChangelog" ==> "GenerateAssemblyInfo" ==> "GitRelease" From 2c5a7fc3cdf87acb8237e06cc74977c2a92709cb Mon Sep 17 00:00:00 2001 From: nikoyak <99891966+nikoyak@users.noreply.github.com> Date: Thu, 8 Jun 2023 13:41:02 +0300 Subject: [PATCH 2/3] Added ShowCoverageReport target into library template --- Content/Library/README.md | 1 + Content/Library/build/build.fs | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Content/Library/README.md b/Content/Library/README.md index 04ff2feb..cb3cd45e 100644 --- a/Content/Library/README.md +++ b/Content/Library/README.md @@ -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). diff --git a/Content/Library/build/build.fs b/Content/Library/build/build.fs index 9ce1c102..c107f9f1 100644 --- a/Content/Library/build/build.fs +++ b/Content/Library/build/build.fs @@ -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 @@ -453,6 +457,15 @@ let generateCoverageReport _ = dotnet.reportgenerator id args +let showCoverageReport _ = + failOnCIBuild () + coverageReportDir "index.html" + |> Command.ShellCommand + |> CreateProcess.fromCommand + |> Proc.start + |> ignore + + let watchTests _ = !!testsGlob |> Seq.map (fun proj -> @@ -718,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 @@ -775,7 +789,8 @@ let initTargets () = ==>! "WatchDocs" "DotnetTest" - ==>! "GenerateCoverageReport" + ==> "GenerateCoverageReport" + ==>! "ShowCoverageReport" "UpdateChangelog" ==> "GenerateAssemblyInfo" From ea4a01b33fa1cf603cbc749c9d281290ff8e3925 Mon Sep 17 00:00:00 2001 From: nikoyak <99891966+nikoyak@users.noreply.github.com> Date: Thu, 8 Jun 2023 18:33:14 +0300 Subject: [PATCH 3/3] Code coverage evaluation in the library template is disabled by default --- Content/Library/.github/workflows/build.yml | 2 ++ Content/Library/.github/workflows/publish.yml | 2 +- Content/Library/README.md | 4 ++-- Content/Library/build/build.fs | 4 ++-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Content/Library/.github/workflows/build.yml b/Content/Library/.github/workflows/build.yml index 510da2d7..4e82db7c 100644 --- a/Content/Library/.github/workflows/build.yml +++ b/Content/Library/.github/workflows/build.yml @@ -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 diff --git a/Content/Library/.github/workflows/publish.yml b/Content/Library/.github/workflows/publish.yml index 84f0980e..4e46a4d3 100644 --- a/Content/Library/.github/workflows/publish.yml +++ b/Content/Library/.github/workflows/publish.yml @@ -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 diff --git a/Content/Library/README.md b/Content/Library/README.md index cb3cd45e..94a66533 100644 --- a/Content/Library/README.md +++ b/Content/Library/README.md @@ -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 --- diff --git a/Content/Library/build/build.fs b/Content/Library/build/build.fs index c107f9f1..347db41a 100644 --- a/Content/Library/build/build.fs +++ b/Content/Library/build/build.fs @@ -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" @@ -411,7 +411,7 @@ let dotnetTest ctx = let args = [ "--no-build" - if not disableCodeCoverage || isGenerateCoverageReport then + if enableCodeCoverage || isGenerateCoverageReport then sprintf "/p:AltCover=true" if not isGenerateCoverageReport then sprintf "/p:AltCoverThreshold=%d" coverageThresholdPercent