Skip to content

feat: improve linting workflow with violation detection #182

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

Merged
merged 3 commits into from
Feb 25, 2025
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
20 changes: 13 additions & 7 deletions .github/workflows/reusable-unity-cs-linter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ jobs:
dotnet add package StyleCop.Analyzers

- name: Collect Style Violations Log
id: violations-log
if: ${{ steps.detect-cs-files.outputs.files != '' }}
run: |
echo "Collecting style violations into output.log..."
Expand All @@ -198,33 +199,38 @@ jobs:
modified_line=$(echo "$line" | sed -E 's/(\\s){6}/6 spaces/g' | sed -E 's/(\\s){4}/4 spaces/g' | sed -E 's/(\\s){2}/2 spaces/g' | sed -E 's/\\s/1 space/g')
echo "$modified_line" >> output_temp.log
done < output.log
mv output_temp.log output.log
if [ -f output_temp.log ]; then
mv output_temp.log output.log
echo "available=1" >> "$GITHUB_OUTPUT"
else
echo "::notice::No issues were found in the code"
fi

- name: Debug Raw Output Log
if: ${{ steps.detect-cs-files.outputs.files != '' }}
if: ${{ steps.violations-log.outputs.available == '1' }}
run: |
echo "=== DEBUG RAW OUTPUT.LOG ==="
cat output.log
echo "=== END RAW OUTPUT.LOG ==="

- name: Download `convert_to_sarif.py`
if: ${{ steps.detect-cs-files.outputs.files != '' }}
if: ${{ steps.violations-log.outputs.available == '1' }}
run: |
curl --fail --silent --show-error --max-time 10 -o convert_to_sarif.py ${{ env.CONVERT_TO_SARIF_URI }} || { echo "Failed to download script"; exit 1; }

- name: Convert to SARIF
if: ${{ steps.detect-cs-files.outputs.files != '' }}
if: ${{ steps.violations-log.outputs.available == '1' }}
run: |
python3 convert_to_sarif.py output.log output.sarif

- name: Setup reviewdog
if: ${{ steps.detect-cs-files.outputs.files != '' }}
if: ${{ steps.violations-log.outputs.available == '1' }}
uses: reviewdog/action-setup@v1
with:
reviewdog_version: latest

- name: Apply Style Suggestions with reviewdog
if: ${{ steps.detect-cs-files.outputs.files != '' }}
if: ${{ steps.violations-log.outputs.available == '1' }}
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
Expand All @@ -237,6 +243,6 @@ jobs:
< output.sarif

- name: Cleanup temporary files
if: ${{ steps.detect-cs-files.outputs.files != '' && always() }}
if: ${{ steps.violations-log.outputs.available == '1' && always() }}
run: |
rm -f TempProject.csproj convert_to_sarif.py output.log output.sarif || true
3 changes: 3 additions & 0 deletions Assets/Tests/StyleTest.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions Assets/Tests/StyleTest/StyleTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

namespace Tests.StyleTest
{
public sealed class StyleTest
{
static string s_staticField = string.Empty;
string _test;
string _test2;

void Test()
{

}
}
}
3 changes: 3 additions & 0 deletions Assets/Tests/StyleTest/StyleTest.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading