C# Linter for Unity Project #8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: C# Linter for Unity Project | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| workflow_dispatch: # Allows manual execution via GitHub CLI | |
| jobs: | |
| lint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v3 | |
| with: | |
| dotnet-version: 8.0.x # Adjust as needed | |
| - name: Get C# Files (Changed in PR or All for Manual Runs) | |
| id: get-files | |
| run: | | |
| if [ "${{ github.event_name }}" = "pull_request" ]; then | |
| echo "🔎 Detecting changed C# files in PR..." | |
| FILES=$(git diff --name-only origin/main...HEAD | grep '\.cs$' || true) | |
| else | |
| echo "🟢 Manual run detected! Running on ALL C# files..." | |
| FILES=$(find Assets com.playeveryware.eos -type f -name "*.cs" ! -path "*/EOS_SDK/*" | tr '\n' ' ') | |
| fi | |
| if [ -z "$FILES" ]; then | |
| echo "✅ No C# files to analyze!" | |
| exit 0 | |
| fi | |
| echo "Files to analyze:" | |
| echo "$FILES" | |
| echo "FILES=$FILES" >> $GITHUB_ENV | |
| - name: Run Roslyn Analyzers Using `dotnet format` | |
| continue-on-error: true # Allow warnings but don’t fail the workflow | |
| run: | | |
| for file in $FILES; do | |
| echo "🔍 Running analyzers on $file" | |
| dotnet format analyze "$file" --severity info 2>&1 | tee -a lint_warnings.log | |
| done | |
| - name: Print Lint Warnings | |
| run: | | |
| echo "⚠️ Lint warnings detected:" | |
| cat lint_warnings.log || echo "✅ No warnings found!" |