|
| 1 | +name: lint |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + paths-ignore: ['**.md', 'docs/**', 'LICENSE*'] |
| 6 | + pull_request: |
| 7 | + branches: [main, develop] |
| 8 | + paths-ignore: ['**.md', 'docs/**', 'LICENSE*'] |
| 9 | + |
| 10 | +concurrency: |
| 11 | + group: lint-${{ github.ref }} |
| 12 | + cancel-in-progress: true |
| 13 | + |
| 14 | +jobs: |
| 15 | + lint: |
| 16 | + runs-on: windows-2025 |
| 17 | + timeout-minutes: 5 |
| 18 | + permissions: |
| 19 | + contents: read |
| 20 | + pull-requests: write |
| 21 | + issues: write |
| 22 | + env: |
| 23 | + NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v5 |
| 26 | + |
| 27 | + - name: Cache NuGet packages |
| 28 | + uses: actions/cache@v4 |
| 29 | + with: |
| 30 | + path: ${{ github.workspace }}/.nuget/packages |
| 31 | + key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', '**/*.vcxproj') }} |
| 32 | + restore-keys: | |
| 33 | + ${{ runner.os }}-nuget- |
| 34 | +
|
| 35 | + - name: Restore |
| 36 | + run: dotnet restore Confuser2.sln |
| 37 | + |
| 38 | + - name: Check whitespace |
| 39 | + id: whitespace |
| 40 | + run: dotnet format whitespace Confuser2.sln --verify-no-changes --verbosity minimal 2>&1 | Tee-Object -Variable wsOutput |
| 41 | + shell: pwsh |
| 42 | + continue-on-error: true |
| 43 | + |
| 44 | + - name: Check style |
| 45 | + id: style |
| 46 | + run: dotnet format style Confuser2.sln --verify-no-changes --severity warn 2>&1 | Tee-Object -Variable styleOutput |
| 47 | + shell: pwsh |
| 48 | + continue-on-error: true |
| 49 | + |
| 50 | + - name: Check analyzers |
| 51 | + id: analyzers |
| 52 | + run: dotnet format analyzers Confuser2.sln --verify-no-changes --severity warn 2>&1 | Tee-Object -Variable analyzerOutput |
| 53 | + shell: pwsh |
| 54 | + continue-on-error: true |
| 55 | + |
| 56 | + - name: Build lint report |
| 57 | + if: always() |
| 58 | + id: report |
| 59 | + shell: pwsh |
| 60 | + run: | |
| 61 | + $ws = '${{ steps.whitespace.outcome }}' |
| 62 | + $st = '${{ steps.style.outcome }}' |
| 63 | + $an = '${{ steps.analyzers.outcome }}' |
| 64 | + $anyFailed = ($ws -eq 'failure') -or ($st -eq 'failure') -or ($an -eq 'failure') |
| 65 | +
|
| 66 | + $md = @() |
| 67 | + $md += '## Lint Results' |
| 68 | + $md += '' |
| 69 | +
|
| 70 | + if (-not $anyFailed) { |
| 71 | + $md += '> :white_check_mark: **All checks passed**' |
| 72 | + } else { |
| 73 | + $md += '> :warning: **Issues found** — run `dotnet format Confuser2.sln` locally to fix' |
| 74 | + } |
| 75 | +
|
| 76 | + $md += '' |
| 77 | + $md += '| Check | Result |' |
| 78 | + $md += '|-------|--------|' |
| 79 | +
|
| 80 | + $icon = if ($ws -eq 'success') { ':white_check_mark:' } else { ':x:' } |
| 81 | + $md += "| Whitespace (indentation, line endings) | $icon |" |
| 82 | +
|
| 83 | + $icon = if ($st -eq 'success') { ':white_check_mark:' } else { ':x:' } |
| 84 | + $md += "| Style (IDE rules, naming, var usage) | $icon |" |
| 85 | +
|
| 86 | + $icon = if ($an -eq 'success') { ':white_check_mark:' } else { ':x:' } |
| 87 | + $md += "| Analyzers (CA*, RCS* rules) | $icon |" |
| 88 | +
|
| 89 | + # Get specific violations if any failed |
| 90 | + if ($anyFailed) { |
| 91 | + $md += '' |
| 92 | + $md += '<details><summary><strong>Details (click to expand)</strong></summary>' |
| 93 | + $md += '' |
| 94 | + $md += '```' |
| 95 | + # Re-run to capture output |
| 96 | + $violations = dotnet format Confuser2.sln --verify-no-changes --verbosity diagnostic 2>&1 | Select-String 'error|warning' | Select-Object -First 30 |
| 97 | + foreach ($v in $violations) { $md += $v.ToString().Trim() } |
| 98 | + if ($violations.Count -ge 30) { $md += '... (truncated, run dotnet format locally for full list)' } |
| 99 | + $md += '```' |
| 100 | + $md += '' |
| 101 | + $md += '</details>' |
| 102 | + } |
| 103 | +
|
| 104 | + $md -join "`n" | Set-Content -Path 'lint-report.md' -Encoding utf8 |
| 105 | + $md -join "`n" >> $env:GITHUB_STEP_SUMMARY |
| 106 | +
|
| 107 | + echo "any_failed=$anyFailed" >> $env:GITHUB_OUTPUT |
| 108 | +
|
| 109 | + - name: Post PR comment |
| 110 | + if: always() && github.event_name == 'pull_request' |
| 111 | + uses: marocchino/sticky-pull-request-comment@v2 |
| 112 | + with: |
| 113 | + header: lint-report |
| 114 | + path: lint-report.md |
| 115 | + |
| 116 | + - name: Post issue comment |
| 117 | + if: always() && github.event_name == 'push' && github.event.pull_request == null |
| 118 | + shell: pwsh |
| 119 | + run: | |
| 120 | + # Extract issue number from branch name (e.g. 54-nuget-packages → 54) |
| 121 | + $branch = "${{ github.ref_name }}" |
| 122 | + if ($branch -match '^(\d+)-') { |
| 123 | + $issueNumber = $Matches[1] |
| 124 | + $marker = '<!-- lint-bot -->' |
| 125 | + $body = $marker + "`n" + (Get-Content 'lint-report.md' -Raw) |
| 126 | +
|
| 127 | + # Find existing lint comment |
| 128 | + $comments = gh api "repos/${{ github.repository }}/issues/$issueNumber/comments" --jq '.[] | select(.body | startswith("<!-- lint-bot -->")) | .id' 2>$null |
| 129 | + if ($comments) { |
| 130 | + # Update existing |
| 131 | + gh api "repos/${{ github.repository }}/issues/comments/$comments" -X PATCH -f body="$body" 2>$null |
| 132 | + } else { |
| 133 | + # Create new |
| 134 | + gh issue comment $issueNumber --repo ${{ github.repository }} --body "$body" 2>$null |
| 135 | + } |
| 136 | + } |
| 137 | + env: |
| 138 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 139 | + |
| 140 | + - name: Fail if issues found |
| 141 | + if: always() && steps.report.outputs.any_failed == 'True' |
| 142 | + shell: pwsh |
| 143 | + run: | |
| 144 | + Write-Host "::warning::Lint issues found. Run 'dotnet format Confuser2.sln' locally to fix." |
| 145 | + exit 1 |
0 commit comments