fix workflow: remove github dependency + duplicate scan
Some checks failed
SonarQube Code Quality Scan / scan (push) Failing after 12s
Some checks failed
SonarQube Code Quality Scan / scan (push) Failing after 12s
This commit is contained in:
@@ -6,51 +6,44 @@ on:
|
||||
branches: [ main ]
|
||||
jobs:
|
||||
scan:
|
||||
runs-on: windowsx64 # 与Runner标签一致(或写x64)
|
||||
runs-on: windowsx64 # 与你的Runner标签完全一致(已确认匹配)
|
||||
steps:
|
||||
# 步骤1:拉取仓库代码(完整历史)
|
||||
- name: Checkout Code (Manual)
|
||||
# 步骤1:手动拉取Gitea仓库代码(无GitHub依赖)
|
||||
- name: Checkout Code (Gitea Direct)
|
||||
run: |
|
||||
git clone https://git.we965.cn/learning/VectorDBDemo.git .
|
||||
git fetch --depth=0
|
||||
git checkout ${{ github.ref_name }}
|
||||
git fetch --depth=0 # 拉取完整历史,SonarQube必需
|
||||
git checkout ${{ github.ref_name }} # 切换到触发事件的分支
|
||||
|
||||
# 步骤2:配置 Sonar Scanner 路径(必做,替换为你的实际路径)
|
||||
# 步骤2:配置Sonar Scanner路径(已替换为你的实际路径)
|
||||
- name: Add Sonar Scanner to PATH
|
||||
run: |
|
||||
$scannerPath = "D:\Paths\sonar-scanner-cli\bin" # 替换为你的 Scanner bin 目录
|
||||
$scannerPath = "D:\Paths\sonar-scanner-cli\bin" # 你的Scanner bin目录(无需修改)
|
||||
echo "$scannerPath" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8
|
||||
|
||||
# 步骤3:安装 .NET SDK(C# 项目编译依赖,根据你的项目版本调整)
|
||||
- name: Setup .NET SDK
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: 6.0.x # 替换为你的项目对应的 .NET 版本(如 3.1.x、5.0.x、7.0.x)
|
||||
# 步骤3:验证本地.NET SDK(替代GitHub的setup-dotnet,无网络依赖)
|
||||
- name: Verify .NET SDK (Local)
|
||||
run: |
|
||||
# 查看本地已安装的.NET SDK版本(确保包含6.0.x)
|
||||
dotnet --list-sdks
|
||||
# 验证dotnet命令可用
|
||||
dotnet --version
|
||||
|
||||
# 步骤4:编译 C# 项目(生成 SonarQube 所需的二进制文件和覆盖率报告)
|
||||
# 步骤4:编译C#项目(Release模式)
|
||||
- name: Build .NET Project
|
||||
run: |
|
||||
dotnet restore # 还原依赖包
|
||||
dotnet build --configuration Release # 编译项目(Release 模式,确保生成完整二进制文件)
|
||||
dotnet restore # 还原依赖包(本地SDK直接执行,无需下载)
|
||||
dotnet build --configuration Release # 生成SonarQube所需的二进制文件
|
||||
|
||||
# 步骤5:执行 SonarQube 扫描(C# 专属配置)
|
||||
# 步骤5:执行SonarQube扫描(修复重复执行问题,仅运行一次)
|
||||
- name: Run SonarQube Scan
|
||||
run: |
|
||||
sonar-scanner `
|
||||
-Dsonar.projectKey=sqp_4bae541a7a6ccfd4ebae43150ce5b8b5c1c34c50 ` # 你的SonarQube项目密钥
|
||||
-Dsonar.sources=./ ` # 代码根目录(C# 项目通常无需修改)
|
||||
-Dsonar.host.url=http://127.0.0.1:9000 ` # SonarQube 地址(非本地需改局域网 IP)
|
||||
-Dsonar.sources=./ ` # 代码根目录
|
||||
-Dsonar.host.url=http://127.0.0.1:9000 ` # SonarQube本地地址
|
||||
-Dsonar.login=${{ secrets.SONAR_TOKEN }} ` # 引用Gitea Secrets令牌
|
||||
-Dsonar.language=csharp ` # 强制指定语言为 C#(避免自动识别错误)
|
||||
-Dsonar.dotnet.build.directory=./**/bin/Release ` # 指定 .NET 编译输出目录(匹配步骤4的 Release 模式)
|
||||
-Dsonar.exclusions=**/obj/**,**/bin/Debug/** ` # 排除无需扫描的目录(编译临时文件、Debug 目录)
|
||||
-Dsonar.coverage.exclusions=**/Test/**,**/*.Tests.cs # 排除测试代码目录(按需调整)
|
||||
sonar-scanner `
|
||||
-Dsonar.projectKey=sqp_4bae541a7a6ccfd4ebae43150ce5b8b5c1c34c50 ` # 你的 SonarQube 项目密钥
|
||||
-Dsonar.sources=./ ` # 代码根目录(C# 项目通常无需修改)
|
||||
-Dsonar.host.url=http://127.0.0.1:9000 ` # SonarQube 地址(非本地需改局域网 IP)
|
||||
-Dsonar.login=${{ secrets.SONAR_TOKEN }} ` # 引用 Gitea Secrets 令牌
|
||||
-Dsonar.language=csharp ` # 强制指定语言为 C#(避免自动识别错误)
|
||||
-Dsonar.dotnet.build.directory=./**/bin/Release ` # 指定 .NET 编译输出目录(匹配步骤4的 Release 模式)
|
||||
-Dsonar.exclusions=**/obj/**,**/bin/Debug/** ` # 排除无需扫描的目录(编译临时文件、Debug 目录)
|
||||
-Dsonar.coverage.exclusions=**/Test/**,**/*.Tests.cs # 排除测试代码目录(按需调整)
|
||||
-Dsonar.language=csharp ` # 强制指定C#语言
|
||||
-Dsonar.dotnet.build.directory=./**/bin/Release ` # 编译输出目录
|
||||
-Dsonar.exclusions=**/obj/**,**/bin/Debug/** ` # 排除冗余目录
|
||||
-Dsonar.coverage.exclusions=**/Test/**,**/*.Tests.cs # 排除测试代码
|
||||
Reference in New Issue
Block a user