-
Notifications
You must be signed in to change notification settings - Fork 4
110 lines (107 loc) · 4.3 KB
/
build.yml
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
name: Build
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
pull_request:
branches: [ main ]
# Allows to run this workflow manually from the Actions tab
workflow_dispatch:
# Workflow jobs
jobs:
Build:
runs-on: ubuntu-latest
env:
LOW_THRESHOLD: 7
HIGH_THRESHOLD: 70
steps:
# Checkout
- name: Git checkout
uses: actions/checkout@v2
# Needs .NET
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 8.0.x
# Run dotnet restore
- name: Run dotnet restore
run: dotnet restore Cmf.CustomerPortal.Sdk.sln
# Run dotnet build
- name: Run dotnet build
run: dotnet build Cmf.CustomerPortal.Sdk.sln --no-restore --configuration Release
# Run tests with coverage
- name: Run Unit Tests with Coverage
run: |
dotnet test Cmf.CustomerPortal.Sdk.sln --no-build --no-restore --configuration Release --collect:"XPlat Code Coverage" --logger trx --results-directory TestResults
- name: Merge Coverage Reports
run: |
dotnet tool install --global dotnet-reportgenerator-globaltool
reportgenerator -reports:TestResults/**/coverage.cobertura.xml -targetdir:TestResults/MergedCoverage -reporttypes:Cobertura
- name: Code Coverage Report
uses: irongut/[email protected]
with:
filename: TestResults/MergedCoverage/Cobertura.xml
badge: true
fail_below_min: false
format: markdown
hide_branch_rate: false
hide_complexity: true
indicators: true
output: both
thresholds: '${{ env.LOW_THRESHOLD }} ${{ env.HIGH_THRESHOLD }}'
- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request'
with:
recreate: true
path: code-coverage-results.md
- name: Write to Job Summary
run: cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY
- name: Validate if line coverage is above ${{ env.LOW_THRESHOLD }}%
run: |
# Get only the first occurrence of line-rate attribute
LINE_RATE=$(grep -m 1 -oP 'line-rate="\K[^"]+' TestResults/MergedCoverage/Cobertura.xml)
echo "Top-level line coverage rate: $(echo "$LINE_RATE * 100" | bc)%"
if (( $(echo "$LINE_RATE * 100 < ${{ env.LOW_THRESHOLD }}" | bc -l) )); then
echo "Coverage threshold not met. Top-level line coverage is $(echo "$LINE_RATE * 100" | bc)% which is below the required ${{ env.LOW_THRESHOLD }}%"
exit 1
fi
# Run build
- name: Build Windows
if: github.ref_name == 'main'
env:
DOTNET_CLI_TELEMETRY_OPTOUT: true
run: dotnet publish --configuration Release --self-contained --runtime win-x64 Cmf.CustomerPortal.Sdk.sln
- name: Build Linux
if: github.ref_name == 'main'
env:
DOTNET_CLI_TELEMETRY_OPTOUT: true
run: dotnet publish --configuration Release --self-contained --runtime linux-x64 Cmf.CustomerPortal.Sdk.sln
# Read version
- name: Read tool version
if: github.ref_name == 'main'
uses: QwerMike/xpath-action@v1
id: getver
with:
filename: src/Version.props
expression: '/Project/PropertyGroup/Version/text()'
# Archive
- name: Archive Console Win64
if: github.ref_name == 'main'
uses: actions/upload-artifact@v4
with:
name: Cmf.CustomerPortal.Sdk.Console-${{ steps.getver.outputs.result }}.win-x64
path: src/Console/bin/Release/net8.0/win-x64/publish/
- name: Archive Console Linux64
if: github.ref_name == 'main'
uses: actions/upload-artifact@v4
with:
name: Cmf.CustomerPortal.Sdk.Console-${{ steps.getver.outputs.result }}.linux-x64
path: src/Console/bin/Release/net8.0/linux-x64/publish/
- name: Archive PowerShell
if: github.ref_name == 'main'
uses: actions/upload-artifact@v4
with:
name: Cmf.CustomerPortal.Sdk.PowerShell-${{ steps.getver.outputs.result }}
path: src/Powershell/bin/Release/net8.0/linux-x64/publish/