diff --git a/.github/workflows/inspect-code.yml b/.github/workflows/inspect-code.yml new file mode 100644 index 00000000..3eb3fb21 --- /dev/null +++ b/.github/workflows/inspect-code.yml @@ -0,0 +1,77 @@ +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json +name: Inspect Code + +on: + push: + branches: ["**"] + tags: ["!**"] + paths: + - .github/workflows/inspect-code.yml + - '**.cs' + pull_request: + paths: + - .github/workflows/inspect-code.yml + - '**.cs' + +jobs: + inspect: + name: Resharper Inspect Code + runs-on: ubuntu-latest + steps: + - name: Checkout Source Code + uses: actions/checkout@v3 + with: + fetch-depth: 0 # avoid shallow clone for GitVersion + + - name: Setup .NET + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 6.0.x + + - name: Restore + run: dotnet restore src + + - name: Inspect Code + uses: rcdailey/resharper_inspectcode@include + with: + workingDirectory: src + solutionPath: Recyclarr.sln + minimumSeverity: warning + include: '**.cs' + + cleanup: + name: Resharper Code Cleanup + runs-on: ubuntu-latest + steps: + - name: Checkout Source Code + uses: actions/checkout@v3 + with: + fetch-depth: 0 # avoid shallow clone for GitVersion + + - name: Setup .NET + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 6.0.x + + - name: Install Resharper Tools + run: dotnet tool install -g JetBrains.ReSharper.GlobalTools + + - name: Build + run: dotnet build src + + - name: Run Code Cleanup + run: ../ci/code_cleanup.sh + working-directory: src + + - name: Check Diff + run: | + ci/diff_to_errors.sh + set -o pipefail + git diff --exit-code | tee code-cleanup.patch + + - name: Publish Patch File + uses: actions/upload-artifact@v3 + if: failure() + with: + name: code-cleanup-patch-files + path: '*.patch' diff --git a/ci/code_cleanup.sh b/ci/code_cleanup.sh new file mode 100755 index 00000000..021b2508 --- /dev/null +++ b/ci/code_cleanup.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +changed_files="$(git diff --relative --name-only origin/master... | egrep '\.cs$')" + +echo '--------------------------------------------------' +echo 'Files to be checked for code cleanup:' +echo +echo "$changed_files" +echo '--------------------------------------------------' + +jb cleanupcode Recyclarr.sln \ + --profile="Recyclarr Cleanup" \ + --include="$(echo "$changed_files" | tr '\n' ';')" diff --git a/ci/diff_to_errors.sh b/ci/diff_to_errors.sh new file mode 100755 index 00000000..dec78c04 --- /dev/null +++ b/ci/diff_to_errors.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +files="$(git diff --name-only)" + +for file in $files; do + echo "File: $file" + diffoutput="$(git diff $file | sed -z 's/\n/%0A/g')" + echo "::error file=$file,title=Code Cleanup Needed In File::$diffoutput" +done