Repository navigation
132 lines (105 loc) · 4.17 KB
/
Copy pathcontinuous-integration.yml
File metadata and controls
132 lines (105 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
name: Continuous Integration
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
DOTNET_CLI_TELEMETRY_OPTOUT: "true"
DOTNET_NOLOGO: "true"
NUGET_XMLDOC_MODE: skip
# Start at the project's current baseline and raise these gradually.
MINIMUM_LINE_COVERAGE: "10"
MINIMUM_BRANCH_COVERAGE: "10"
jobs:
quality_gate:
name: Quality Gate (.NET 10)
runs-on: ubuntu-24.04
timeout-minutes: 15
steps:
- name: Check out repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up .NET SDK
uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0
with:
global-json-file: ./global.json
- name: Display .NET environment
run: dotnet --info
- name: Run formatting, build, tests, and coverage
shell: pwsh
run: ./scripts/Invoke-ProjectQualityCheck.ps1 -VerifyNoChanges
- name: Publish coverage summary and enforce baseline
shell: pwsh
run: |
$coverageFile = Join-Path $env:GITHUB_WORKSPACE "CoverageReport/Cobertura.xml"
$summaryFile = Join-Path $env:GITHUB_WORKSPACE "CoverageReport/SummaryGithub.md"
if (-not (Test-Path $coverageFile)) {
throw "Merged coverage report was not found: $coverageFile"
}
[xml] $coverageReport = Get-Content -Path $coverageFile -Raw
$invariantCulture = [System.Globalization.CultureInfo]::InvariantCulture
$lineRate = [double]::Parse(
[string] $coverageReport.coverage.'line-rate',
$invariantCulture)
$branchRate = [double]::Parse(
[string] $coverageReport.coverage.'branch-rate',
$invariantCulture)
$lineCoverage = [Math]::Round($lineRate * 100, 2)
$branchCoverage = [Math]::Round($branchRate * 100, 2)
$minimumLineCoverage = [double]::Parse(
$env:MINIMUM_LINE_COVERAGE,
$invariantCulture)
$minimumBranchCoverage = [double]::Parse(
$env:MINIMUM_BRANCH_COVERAGE,
$invariantCulture)
if (Test-Path $summaryFile) {
Get-Content -Path $summaryFile -Raw |
Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
}
else {
$fallbackSummary = @(
"## Code coverage",
"",
"| Metric | Result | Required |",
"|---|---:|---:|",
"| Line coverage | $lineCoverage% | $minimumLineCoverage% |",
"| Branch coverage | $branchCoverage% | $minimumBranchCoverage% |"
) -join [Environment]::NewLine
$fallbackSummary |
Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
}
Write-Host "Line coverage: $lineCoverage% (minimum $minimumLineCoverage%)"
Write-Host "Branch coverage: $branchCoverage% (minimum $minimumBranchCoverage%)"
$coverageFailures = [System.Collections.Generic.List[string]]::new()
if ($lineCoverage -lt $minimumLineCoverage) {
$coverageFailures.Add(
"Line coverage $lineCoverage% is below $minimumLineCoverage%.")
}
if ($branchCoverage -lt $minimumBranchCoverage) {
$coverageFailures.Add(
"Branch coverage $branchCoverage% is below $minimumBranchCoverage%.")
}
if ($coverageFailures.Count -gt 0) {
throw ($coverageFailures -join " ")
}
- name: Upload test and coverage reports
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: quality-results
path: |
TestResults/**/*
CoverageReport/**/*
if-no-files-found: warn
retention-days: 14
compression-level: 6