From 5385767c9df655354d72bb02823518f283b56087 Mon Sep 17 00:00:00 2001 From: Bronson Bata Date: Wed, 24 Jul 2024 20:13:39 -0500 Subject: [PATCH] Add F# Analyzers (#603) * Added fsharp analyzers in response to seeing Follow-up from "Minor code optimisation #567" #577 * Moved packages to proj file instead of props file * add analyzers CI workflow and define the report name at Directory.Build.Targets --------- Co-authored-by: 64J0 --- .config/dotnet-tools.json | 6 ++++++ .github/workflows/build-and-test.yml | 28 +++++++++++++++++++++++++++- Directory.Build.targets | 9 +++++++++ Directory.Solution.targets | 9 +++++++++ src/Giraffe/Giraffe.fsproj | 14 ++++++++++++++ 5 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 Directory.Build.targets create mode 100644 Directory.Solution.targets diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index f20af560..716799c8 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -7,6 +7,12 @@ "commands": [ "fantomas" ] + }, + "fsharp-analyzers": { + "version": "0.26.0", + "commands": [ + "fsharp-analyzers" + ] } } } \ No newline at end of file diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 9a991a75..5f489563 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -38,4 +38,30 @@ jobs: - name: Build run: dotnet build -c Release --no-restore - name: Test - run: dotnet test -c Release \ No newline at end of file + run: dotnet test -c Release + + analyzers: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup .NET Core + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.x + - name: Restore tools + run: dotnet tool restore + - name: Build solution + run: dotnet build -c Release Giraffe.sln + + - name: Run Analyzers + run: dotnet msbuild /t:AnalyzeFSharpProject src/Giraffe/Giraffe.fsproj + # This is important, you want to continue your Action even if you found problems. + # As you always want the report to upload + continue-on-error: true + # checkout code, build, run analyzers, ... + - name: Upload SARIF file + uses: github/codeql-action/upload-sarif@v2 + with: + # You can also specify the path to a folder for `sarif_file` + sarif_file: ./src/Giraffe/analysis.sarif \ No newline at end of file diff --git a/Directory.Build.targets b/Directory.Build.targets new file mode 100644 index 00000000..e2e6bdfa --- /dev/null +++ b/Directory.Build.targets @@ -0,0 +1,9 @@ + + + --analyzers-path "$(PkgG-Research_FSharp_Analyzers)" + $(FSharpAnalyzersOtherFlags) --analyzers-path "$(PkgIonide_Analyzers)" + $(FSharpAnalyzersOtherFlags) --configuration $(Configuration) + $(FSharpAnalyzersOtherFlags) --exclude-analyzers PartialAppAnalyzer + $(FSharpAnalyzersOtherFlags) --report "analysis.sarif" + + \ No newline at end of file diff --git a/Directory.Solution.targets b/Directory.Solution.targets new file mode 100644 index 00000000..33bbc1dd --- /dev/null +++ b/Directory.Solution.targets @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/Giraffe/Giraffe.fsproj b/src/Giraffe/Giraffe.fsproj index 85be607d..0e4c00f2 100644 --- a/src/Giraffe/Giraffe.fsproj +++ b/src/Giraffe/Giraffe.fsproj @@ -49,6 +49,20 @@ + + + build + all + + + analyzers + all + + + analyzers + all + +