-
Notifications
You must be signed in to change notification settings - Fork 0
98 lines (83 loc) · 3.18 KB
/
pipeline.yaml
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
name: Pipeline
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
Build:
name: Build
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full depth (not shallow) for better relevancy of Sonar analysis
- name: Use .NET
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
- name: Use pnpm
uses: pnpm/action-setup@v4
with:
version: 9
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: .node-version
cache: 'pnpm'
# Begin ci-build.ps1
- name: dotnet restore
run: dotnet restore -v normal
- name: dotnet build
run: dotnet build -v normal -c Release --no-restore
- name: dotnet test
run: dotnet test -v normal -c Release --no-build
- name: Fix JS package names
shell: pwsh
run: |
Get-ChildItem TestResults -Filter *.cobertura.xml -Name | Foreach-Object {
$projectName = $_ -replace ".{14}$"
(Get-Content TestResults/$_).replace("package name=`"main`"", "package name=`"${projectName}`"") | Set-Content TestResults/$_
}
- name: ReportGenerator
uses: danielpalme/[email protected]
with:
reports: TestResults/*.cobertura.xml
targetdir: TestResults/report
reporttypes: Cobertura;HtmlInline;JsonSummary;MarkdownSummaryGithub;SonarQube
- name: Check coverage thresholds
shell: pwsh
run: |
$coverage = Get-Content -Raw TestResults/report/Summary.json | ConvertFrom-Json
if ($coverage.summary.linecoverage -lt 80 -or $coverage.summary.branchcoverage -lt 80 -or $coverage.summary.methodcoverage -lt 80) {
Write-Error "Coverage does not meet threshold.`n`nCI build failed."; Exit 1
}
# End ci-build.ps1
- name: Add coverage comment to PR
if: github.event_name == 'pull_request' && always() # Still post coverage comment if tests failed
run: gh pr comment $PR_NUMBER --body-file TestResults/report/SummaryGithub.md
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.number }}
- name: Publish coverage in build summary
if: always() # Still publish coverage if tests failed
run: cat TestResults/report/SummaryGithub.md >> $GITHUB_STEP_SUMMARY
- name: Upload coverage report to Codecov
if: always() # Still upload to CodeCov if tests failed
uses: codecov/codecov-action@v4
with:
disable_search: true
fail_ci_if_error: true
files: TestResults/*.cobertura.xml
flags: unittests
plugins: noop
token: ${{ secrets.CODECOV_TOKEN }}
- name: SonarCloud Scan
if: always() # Still run Sonar if tests failed
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}