f517b85571
A repointed third-party tag could swap the installer during the release job,
which held a write token for every job. Actions are now pinned to commit SHAs
(Dependabot keeps them current), only the job that publishes the release can
write, workflow inputs reach pwsh through env instead of ${{ }} interpolation,
Inno Setup and the SBOM tool are version-pinned, and the gitleaks download is
checked against its published SHA256.
138 lines
5.1 KiB
YAML
138 lines
5.1 KiB
YAML
name: CI DevSecOps
|
|
|
|
on:
|
|
push:
|
|
branches: ["main", "master"]
|
|
pull_request:
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: read
|
|
actions: read
|
|
|
|
jobs:
|
|
build-test-scan:
|
|
# Native EcoQoS read-back needs the Windows 11-era kernel (build 22000+).
|
|
runs-on: windows-2025
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
|
|
|
|
- name: Setup .NET
|
|
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4.3.1
|
|
with:
|
|
dotnet-version: "8.0.x"
|
|
|
|
- name: Restore
|
|
run: dotnet restore "ThreadPilot_1.sln"
|
|
|
|
- name: Verify formatting
|
|
continue-on-error: true
|
|
run: dotnet format "ThreadPilot_1.sln" --verify-no-changes --verbosity diagnostic --report dotnet-format-report.json
|
|
|
|
- name: Build Debug
|
|
run: dotnet build "ThreadPilot_1.sln" --configuration Debug --no-restore
|
|
|
|
- name: Build Release
|
|
run: dotnet build "ThreadPilot_1.sln" --configuration Release --no-restore
|
|
|
|
- name: Run tests
|
|
run: dotnet test "Tests/ThreadPilot.Core.Tests/ThreadPilot.Core.Tests.csproj" --configuration Release --no-restore --verbosity normal --collect:"XPlat Code Coverage" --settings "Tests/ThreadPilot.Core.Tests/coverlet.runsettings" --results-directory TestResults
|
|
|
|
- name: Enforce coverage gate
|
|
shell: pwsh
|
|
run: |
|
|
$ErrorActionPreference = "Stop"
|
|
$coveragePath = Get-ChildItem -Path "TestResults" -Recurse -Filter "coverage.cobertura.xml" |
|
|
Sort-Object LastWriteTimeUtc -Descending |
|
|
Select-Object -First 1 -ExpandProperty FullName
|
|
|
|
if ([string]::IsNullOrWhiteSpace($coveragePath))
|
|
{
|
|
throw "Coverage file not found under TestResults."
|
|
}
|
|
|
|
[xml]$coverage = Get-Content $coveragePath
|
|
$lineRate = [double]$coverage.coverage.'line-rate' * 100
|
|
$branchRate = [double]$coverage.coverage.'branch-rate' * 100
|
|
# Keep the gate slightly below measured main coverage so meaningful tests can raise it deliberately.
|
|
$minimumLineRate = 35.0
|
|
|
|
$summary = @(
|
|
"## Coverage Gate",
|
|
"- file: $coveragePath",
|
|
"- line coverage: $([math]::Round($lineRate, 2))%",
|
|
"- branch coverage: $([math]::Round($branchRate, 2))%",
|
|
"- minimum line coverage: $minimumLineRate%"
|
|
)
|
|
|
|
$summary | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
|
|
$summary | ForEach-Object { Write-Host $_ }
|
|
|
|
if ($lineRate -lt $minimumLineRate)
|
|
{
|
|
throw "Coverage gate failed. Expected >= $minimumLineRate, actual: $([math]::Round($lineRate, 2))"
|
|
}
|
|
|
|
- name: Upload coverage
|
|
uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4.6.0
|
|
with:
|
|
files: '**/coverage.cobertura.xml'
|
|
fail_ci_if_error: false
|
|
|
|
- name: Dependency vulnerability audit
|
|
shell: pwsh
|
|
run: |
|
|
$ErrorActionPreference = "Stop"
|
|
$audit = dotnet list "ThreadPilot.csproj" package --vulnerable --include-transitive
|
|
$audit | Out-String | Write-Host
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "dotnet list package --vulnerable failed."
|
|
}
|
|
|
|
if ($audit -match "has the following vulnerable packages") {
|
|
throw "Vulnerable packages detected."
|
|
}
|
|
|
|
- name: Secret scan (Gitleaks)
|
|
shell: pwsh
|
|
run: |
|
|
$ErrorActionPreference = "Stop"
|
|
$version = "8.24.3"
|
|
$baseUrl = "https://github.com/gitleaks/gitleaks/releases/download/v$version"
|
|
$zipAsset = "gitleaks_${version}_windows_x64.zip"
|
|
$toolDir = Join-Path $env:RUNNER_TEMP "gitleaks-bin"
|
|
|
|
if (Test-Path $toolDir) {
|
|
Remove-Item -Path $toolDir -Recurse -Force
|
|
}
|
|
|
|
# Pinned hash from gitleaks_8.24.3_checksums.txt: refuse a swapped binary.
|
|
$expectedZipSha256 = "3f1a35578631dbfe633cc5b49e6c906e55ff14a4bfd7336a10fb27fe33b6dcd2"
|
|
Invoke-WebRequest -Uri "$baseUrl/$zipAsset" -OutFile "gitleaks.zip"
|
|
$actualZipSha256 = (Get-FileHash -Path "gitleaks.zip" -Algorithm SHA256).Hash
|
|
if ($actualZipSha256 -ne $expectedZipSha256) {
|
|
throw "Gitleaks archive checksum mismatch: $actualZipSha256"
|
|
}
|
|
|
|
Expand-Archive -Path "gitleaks.zip" -DestinationPath $toolDir -Force
|
|
|
|
# Remove vendored tool docs from scan scope to avoid known upstream sample false positives.
|
|
if (Test-Path ".\\gitleaks-bin") {
|
|
Remove-Item -Path ".\\gitleaks-bin" -Recurse -Force
|
|
}
|
|
|
|
$gitleaksExe = Resolve-Path (Join-Path $toolDir "gitleaks.exe")
|
|
& $gitleaksExe detect --source "." --no-git --exit-code 1 --redact --verbose --report-format json --report-path gitleaks-report.json
|
|
|
|
- name: Upload security artifacts
|
|
if: always()
|
|
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
|
with:
|
|
name: security-reports
|
|
path: |
|
|
gitleaks-report.json
|
|
dotnet-format-report.json
|