1+ name : Code Analysis on PR
2+
3+ on :
4+ pull_request :
5+ branches : [ main, master, develop ]
6+
7+ jobs :
8+ code-analysis :
9+ runs-on : windows-latest
10+
11+ steps :
12+ - uses : actions/checkout@v4
13+
14+ - name : Setup .NET
15+ uses : actions/setup-dotnet@v4
16+ with :
17+ dotnet-version : 8.0.x
18+
19+ - name : Detect project file
20+ id : proj
21+ shell : pwsh
22+ run : |
23+ $p = Get-ChildItem -Path $Env:GITHUB_WORKSPACE -Filter *.csproj -Recurse | Select-Object -First 1 -ExpandProperty FullName
24+ if (-not $p) { Write-Error "No .csproj found."; exit 1 }
25+ "path=$p" | Out-File -FilePath $Env:GITHUB_OUTPUT -Append -Encoding utf8
26+
27+ - name : Restore dependencies
28+ run : dotnet restore "${{ steps.proj.outputs.path }}"
29+
30+ - name : Build with analysis (fail on warnings not suppressed by csproj)
31+ id : build
32+ run : dotnet build "${{ steps.proj.outputs.path }}" --configuration Release --no-restore /warnaserror /p:ContinuousIntegrationBuild=true
33+
34+ - name : Close PR on failure
35+ if : failure() && steps.build.outcome == 'failure'
36+ uses : actions/github-script@v7
37+ with :
38+ github-token : ${{ secrets.GITHUB_TOKEN }}
39+ script : |
40+ const { owner, repo } = context.repo;
41+ const prNumber = context.payload.pull_request.number;
42+
43+ const message = `
44+ ❌ PR 已被自动关闭, 存在未被解决的编译警告.
45+
46+ 请修复后打开一个新的 PR.
47+ ` ;
48+
49+ await github.rest.issues.createComment({
50+ owner,
51+ repo,
52+ issue_number: prNumber,
53+ body: message
54+ });
55+
56+ await github.rest.pulls.update({
57+ owner,
58+ repo,
59+ pull_number: prNumber,
60+ state: "closed"
61+ });
0 commit comments