From ee06697aa347ce076b73052abe5ec1a22035e646 Mon Sep 17 00:00:00 2001 From: dawe Date: Thu, 26 Oct 2023 22:24:38 +0200 Subject: [PATCH] Integrate analyzers via msbuild (#2968) * integrate analyzers via msbuild magic * try wildcard for sarif upload, might need to change to directory * try another wildcard for sarif files * collect sarif files in dedicated directory to be able to upload them with github/codeql-action/upload-sarif * add back env vars * remove stale open statement * update analyzers tool and gr analyzers package * move setting of env vars * delete "Directory.Solution.props" * remove message * needs some UsingTask magic I don't know currently * fix build for now * cool kids project cracking * restore all fail-on-warnings * use analysisreports dir * use $(SolutionFileName) instead of hard coding name * Set environment variables in target. --------- Co-authored-by: nojaf --- .config/dotnet-tools.json | 2 +- .github/workflows/main.yml | 2 +- .gitignore | 2 +- Directory.Build.props | 6 ++++ Directory.Build.targets | 22 ++++++++++++ Directory.Solution.targets | 15 ++++++++ analyzers/analyzers.fsproj | 17 --------- analyzers/packages.lock.json | 6 ---- build.fsx | 38 +++----------------- src/Fantomas.Benchmarks/packages.lock.json | 6 ++++ src/Fantomas.Client.Tests/packages.lock.json | 6 ++++ src/Fantomas.Client/packages.lock.json | 6 ++++ src/Fantomas.Core.Tests/packages.lock.json | 6 ++++ src/Fantomas.Core/packages.lock.json | 6 ++++ src/Fantomas.FCS/packages.lock.json | 6 ++++ src/Fantomas.Tests/packages.lock.json | 6 ++++ src/Fantomas/packages.lock.json | 6 ++++ 17 files changed, 99 insertions(+), 59 deletions(-) create mode 100644 Directory.Build.targets create mode 100644 Directory.Solution.targets delete mode 100644 analyzers/analyzers.fsproj delete mode 100644 analyzers/packages.lock.json diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index c0b42f787d..68c79739d9 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -21,7 +21,7 @@ ] }, "fsharp-analyzers": { - "version": "0.16.0", + "version": "0.17.0", "commands": [ "fsharp-analyzers" ] diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 02e011c0d8..ebe3f63893 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -31,7 +31,7 @@ jobs: uses: github/codeql-action/upload-sarif@v2 if: matrix.os == 'ubuntu-latest' with: - sarif_file: analysis.sarif + sarif_file: analysisreports - name: "Documentation" if: matrix.os == 'windows-latest' && github.ref == 'refs/heads/main' uses: peaceiris/actions-gh-pages@v3 diff --git a/.gitignore b/.gitignore index c5ba351d1f..99f0656079 100644 --- a/.gitignore +++ b/.gitignore @@ -201,4 +201,4 @@ tests/.repositories/** # Analyzer files .analyzerpackages -analysis.sarif \ No newline at end of file +*.sarif \ No newline at end of file diff --git a/Directory.Build.props b/Directory.Build.props index c293b13475..b065a3b36c 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -58,4 +58,10 @@ Some common use cases include: + + + all + build + + diff --git a/Directory.Build.targets b/Directory.Build.targets new file mode 100644 index 0000000000..7303c8418d --- /dev/null +++ b/Directory.Build.targets @@ -0,0 +1,22 @@ + + + + + + + + 1 + LatestMajor + + + + + + + + + \ No newline at end of file diff --git a/Directory.Solution.targets b/Directory.Solution.targets new file mode 100644 index 0000000000..7fea63eaad --- /dev/null +++ b/Directory.Solution.targets @@ -0,0 +1,15 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/analyzers/analyzers.fsproj b/analyzers/analyzers.fsproj deleted file mode 100644 index 0df7286cec..0000000000 --- a/analyzers/analyzers.fsproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - false - ../.analyzerpackages/ - - net6.0 - true - false - - - - - - - - diff --git a/analyzers/packages.lock.json b/analyzers/packages.lock.json deleted file mode 100644 index 2fca7fd98a..0000000000 --- a/analyzers/packages.lock.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "version": 1, - "dependencies": { - "net6.0": {} - } -} \ No newline at end of file diff --git a/build.fsx b/build.fsx index 31a4440ede..61a4a892f6 100644 --- a/build.fsx +++ b/build.fsx @@ -6,7 +6,6 @@ open System open System.IO -open System.Text.RegularExpressions open Fun.Build open CliWrap open CliWrap.Buffered @@ -58,23 +57,7 @@ let pushPackage nupkg = return result.ExitCode } -let analyzersProjectPath = __SOURCE_DIRECTORY__ "analyzers/analyzers.fsproj" - -let analyzersVersion = - let s = File.ReadAllText(analyzersProjectPath) - let regex = Regex(@"\[\s*(\d+\.\d+\.\d+)\s*\]") - let matches = regex.Match(s) - matches.Groups[1].Value - -let analyzeProjects (projectPaths: string seq) = - let projects = String.concat " " projectPaths - let analyzerPath = - $"./.analyzerpackages/g-research.fsharp.analyzers/{analyzersVersion}" - let failOnWarnings = - "GRA-STRING-001 GRA-STRING-002 GRA-STRING-003 GRA-UNIONCASE-001" - let excludeAnalyzers = "PartialAppAnalyzer" - let report = "./analysis.sarif" - $"dotnet fsharp-analyzers --project %s{projects} --analyzers-path \"%s{analyzerPath}\" --verbose --fail-on-warnings %s{failOnWarnings} --report %s{report} --exclude-analyzer %s{excludeAnalyzers}" +let analysisReportsDir = "analysisreports" pipeline "Build" { workingDir __SOURCE_DIRECTORY__ @@ -82,7 +65,8 @@ pipeline "Build" { stage "Clean" { run ( cleanFolders - [| "bin" + [| analysisReportsDir + "bin" "src/Fantomas.FCS/bin/Release" "src/Fantomas.FCS/obj/Release" "src/Fantomas.Core/bin/Release" @@ -94,22 +78,10 @@ pipeline "Build" { ) } stage "CheckFormat" { run "dotnet fantomas src docs build.fsx --check" } - stage "RestoreAnalyzers" { run $"dotnet restore %s{analyzersProjectPath}" } stage "Build" { run "dotnet build -c Release" } stage "Analyze" { - envVars - [| "DOTNET_ROLL_FORWARD_TO_PRERELEASE", "1" - "DOTNET_ROLL_FORWARD", "LatestMajor" |] - run ( - analyzeProjects - [ "./src/Fantomas/Fantomas.fsproj" - "./src/Fantomas.Benchmarks/Fantomas.Benchmarks.fsproj" - "./src/Fantomas.Client/Fantomas.Client.fsproj" - "./src/Fantomas.Client.Tests/Fantomas.Client.Tests.fsproj" - "./src/Fantomas.Core/Fantomas.Core.fsproj" - "./src/Fantomas.Core.Tests/Fantomas.Core.Tests.fsproj" - "./src/Fantomas.Tests/Fantomas.Tests.fsproj" ] - ) + run (fun _ -> async { System.IO.Directory.CreateDirectory(analysisReportsDir) |> ignore }) + run "dotnet msbuild /t:AnalyzeSolution" } stage "UnitTests" { run "dotnet test -c Release" } stage "Pack" { run "dotnet pack --no-restore -c Release -o ./bin" } diff --git a/src/Fantomas.Benchmarks/packages.lock.json b/src/Fantomas.Benchmarks/packages.lock.json index 8a9dd2b851..5feae21816 100644 --- a/src/Fantomas.Benchmarks/packages.lock.json +++ b/src/Fantomas.Benchmarks/packages.lock.json @@ -28,6 +28,12 @@ "resolved": "6.0.4", "contentHash": "CYqAfmO7JvN38M+ACkstS8taVfl8C0mCkvSiBAshfKuu2Nut6+8MuFU7Wahu09wGIyFPlRz5ArFWxSOM5mhMSA==" }, + "G-Research.FSharp.Analyzers": { + "type": "Direct", + "requested": "[0.1.6, )", + "resolved": "0.1.6", + "contentHash": "1WyLN4LsQVQUprNr5adpLcYA7Dbn1ohGQ3Pch4qoVflKWZRuFb81pDziFZN/KOqPHdlQUx2BLAE5LIKGD46o5g==" + }, "BenchmarkDotNet.Annotations": { "type": "Transitive", "resolved": "0.13.2", diff --git a/src/Fantomas.Client.Tests/packages.lock.json b/src/Fantomas.Client.Tests/packages.lock.json index d66bc6b874..a3f5bc17f3 100644 --- a/src/Fantomas.Client.Tests/packages.lock.json +++ b/src/Fantomas.Client.Tests/packages.lock.json @@ -14,6 +14,12 @@ "resolved": "6.0.1", "contentHash": "VrFAiW8dEEekk+0aqlbvMNZzDvYXmgWZwAt68AUBqaWK8RnoEVUNglj66bZzhs4/U63q0EfXlhcEKnH1sTYLjw==" }, + "G-Research.FSharp.Analyzers": { + "type": "Direct", + "requested": "[0.1.6, )", + "resolved": "0.1.6", + "contentHash": "1WyLN4LsQVQUprNr5adpLcYA7Dbn1ohGQ3Pch4qoVflKWZRuFb81pDziFZN/KOqPHdlQUx2BLAE5LIKGD46o5g==" + }, "Microsoft.NET.Test.Sdk": { "type": "Direct", "requested": "[17.5.0, )", diff --git a/src/Fantomas.Client/packages.lock.json b/src/Fantomas.Client/packages.lock.json index 979844a514..334da8b828 100644 --- a/src/Fantomas.Client/packages.lock.json +++ b/src/Fantomas.Client/packages.lock.json @@ -20,6 +20,12 @@ "resolved": "5.0.1", "contentHash": "96YN8cgEVSpFhENBs+oXmxskFOQIjdW/pGCtyR+X8URYGbbQk0Fpu56uKHTOl7BEj6bSiZCuE8sjr9FdlXjoUQ==" }, + "G-Research.FSharp.Analyzers": { + "type": "Direct", + "requested": "[0.1.6, )", + "resolved": "0.1.6", + "contentHash": "1WyLN4LsQVQUprNr5adpLcYA7Dbn1ohGQ3Pch4qoVflKWZRuFb81pDziFZN/KOqPHdlQUx2BLAE5LIKGD46o5g==" + }, "Ionide.KeepAChangelog.Tasks": { "type": "Direct", "requested": "[0.1.8, )", diff --git a/src/Fantomas.Core.Tests/packages.lock.json b/src/Fantomas.Core.Tests/packages.lock.json index 84b87d60df..1bdd036bc9 100644 --- a/src/Fantomas.Core.Tests/packages.lock.json +++ b/src/Fantomas.Core.Tests/packages.lock.json @@ -28,6 +28,12 @@ "NUnit": "[3.13.2, 3.14.0)" } }, + "G-Research.FSharp.Analyzers": { + "type": "Direct", + "requested": "[0.1.6, )", + "resolved": "0.1.6", + "contentHash": "1WyLN4LsQVQUprNr5adpLcYA7Dbn1ohGQ3Pch4qoVflKWZRuFb81pDziFZN/KOqPHdlQUx2BLAE5LIKGD46o5g==" + }, "Microsoft.NET.Test.Sdk": { "type": "Direct", "requested": "[17.5.0, )", diff --git a/src/Fantomas.Core/packages.lock.json b/src/Fantomas.Core/packages.lock.json index 6364efa65b..72294aaead 100644 --- a/src/Fantomas.Core/packages.lock.json +++ b/src/Fantomas.Core/packages.lock.json @@ -20,6 +20,12 @@ "resolved": "6.0.1", "contentHash": "VrFAiW8dEEekk+0aqlbvMNZzDvYXmgWZwAt68AUBqaWK8RnoEVUNglj66bZzhs4/U63q0EfXlhcEKnH1sTYLjw==" }, + "G-Research.FSharp.Analyzers": { + "type": "Direct", + "requested": "[0.1.6, )", + "resolved": "0.1.6", + "contentHash": "1WyLN4LsQVQUprNr5adpLcYA7Dbn1ohGQ3Pch4qoVflKWZRuFb81pDziFZN/KOqPHdlQUx2BLAE5LIKGD46o5g==" + }, "Ionide.KeepAChangelog.Tasks": { "type": "Direct", "requested": "[0.1.8, )", diff --git a/src/Fantomas.FCS/packages.lock.json b/src/Fantomas.FCS/packages.lock.json index 26e990f7a2..bf0b616c7b 100644 --- a/src/Fantomas.FCS/packages.lock.json +++ b/src/Fantomas.FCS/packages.lock.json @@ -30,6 +30,12 @@ "FsLexYacc.Runtime": "11.2.0" } }, + "G-Research.FSharp.Analyzers": { + "type": "Direct", + "requested": "[0.1.6, )", + "resolved": "0.1.6", + "contentHash": "1WyLN4LsQVQUprNr5adpLcYA7Dbn1ohGQ3Pch4qoVflKWZRuFb81pDziFZN/KOqPHdlQUx2BLAE5LIKGD46o5g==" + }, "Ionide.KeepAChangelog.Tasks": { "type": "Direct", "requested": "[0.1.8, )", diff --git a/src/Fantomas.Tests/packages.lock.json b/src/Fantomas.Tests/packages.lock.json index 755eb6d456..35bc37b517 100644 --- a/src/Fantomas.Tests/packages.lock.json +++ b/src/Fantomas.Tests/packages.lock.json @@ -28,6 +28,12 @@ "NUnit": "[3.13.2, 3.14.0)" } }, + "G-Research.FSharp.Analyzers": { + "type": "Direct", + "requested": "[0.1.6, )", + "resolved": "0.1.6", + "contentHash": "1WyLN4LsQVQUprNr5adpLcYA7Dbn1ohGQ3Pch4qoVflKWZRuFb81pDziFZN/KOqPHdlQUx2BLAE5LIKGD46o5g==" + }, "Microsoft.NET.Test.Sdk": { "type": "Direct", "requested": "[17.5.0, )", diff --git a/src/Fantomas/packages.lock.json b/src/Fantomas/packages.lock.json index 2bb8c55aea..63f5435635 100644 --- a/src/Fantomas/packages.lock.json +++ b/src/Fantomas/packages.lock.json @@ -36,6 +36,12 @@ "resolved": "6.0.1", "contentHash": "VrFAiW8dEEekk+0aqlbvMNZzDvYXmgWZwAt68AUBqaWK8RnoEVUNglj66bZzhs4/U63q0EfXlhcEKnH1sTYLjw==" }, + "G-Research.FSharp.Analyzers": { + "type": "Direct", + "requested": "[0.1.6, )", + "resolved": "0.1.6", + "contentHash": "1WyLN4LsQVQUprNr5adpLcYA7Dbn1ohGQ3Pch4qoVflKWZRuFb81pDziFZN/KOqPHdlQUx2BLAE5LIKGD46o5g==" + }, "Ignore": { "type": "Direct", "requested": "[0.1.46, )",