-
Notifications
You must be signed in to change notification settings - Fork 6
122 lines (120 loc) · 3.76 KB
/
regular-checks-project.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
111
112
113
114
115
116
117
118
119
120
121
122
name: Regular Checks - Project
on:
pull_request:
branches:
- main
- 'epic/**'
paths:
- 'src/**/*'
- 'test/**/*'
- '.editorconfig'
- 'Directory.Build.props'
- 'Directory.Packages.props'
- 'Baked.sln'
env:
MIN_COVERAGE: 85
jobs:
# outputs matrix json so that windows is only added when head branch is a release branch
prepare:
name: Prepare
runs-on: ubuntu-latest
outputs:
matrix: ${{ env.MATRIX }}
env:
MATRIX: '{ "os": [ "ubuntu-latest" ] }'
COLON: ':'
steps:
- name: Windows
id: windows
if: startsWith(github.head_ref, 'release/') == true
run: echo "MATRIX={ \"os\"$COLON [ \"ubuntu-latest\", \"windows-latest\" ] }" >> $GITHUB_ENV
build:
name: Build
needs: Prepare
outputs:
matrix: ${{ needs.prepare.outputs.matrix }}
strategy:
max-parallel: 2
matrix: ${{ fromJson(needs.prepare.outputs.matrix) }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9
- name: Restore Dependencies
run: dotnet restore
- name: Format Solution
run: dotnet format --no-restore --verify-no-changes --verbosity diagnostic
- name: Build Solution
run: dotnet build --no-restore -c Release
test:
name: Test
needs: build
strategy:
max-parallel: 2
matrix: ${{ fromJson(needs.build.outputs.matrix) }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9
- name: Test
if: ${{ matrix.os != 'ubuntu-latest' }}
run: dotnet test -c Release
- name: Test w/ Coverage
if: ${{ matrix.os == 'ubuntu-latest' }}
# If a project is not listed in coverage report,
# use '-verbosity:diagnostic --diag:log.log' options
# to log collector warnings.
run: |
dotnet test -c Release \
--collect:"XPlat Code Coverage" \
--logger trx \
--results-directory .coverage \
--settings test/runsettings.xml
- name: Merge Multiple Test Coverage Report
if: ${{ matrix.os == 'ubuntu-latest' }}
uses: danielpalme/[email protected]
with:
reports: '.coverage/*/coverage.cobertura.xml'
targetdir: 'coveragereport'
reporttypes: 'Cobertura'
- name: Code Coverage Summary Report
if: ${{ matrix.os == 'ubuntu-latest' }}
uses: irongut/[email protected]
with:
filename: coveragereport/Cobertura.xml
badge: true
format: 'markdown'
output: 'both'
- name: Upload Reports
if: ${{ matrix.os == 'ubuntu-latest' }}
uses: actions/upload-artifact@v4
with:
name: coverage-reports
path: code-coverage-results.md
coverage:
name: Coverage
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download Reports
uses: actions/download-artifact@v4
with:
name: coverage-reports
- name: Write to Job Summary
run: |
cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY
- name: Checking Test Coverage Under Minimum Coverage
run: |
coverage=$(cat code-coverage-results.md | sed -n '/Code%20Coverage-/p' | sed '/[ a-zA-Z\/()=\.\?%\!]/ s///g' | sed 's/.\{3\}$//' | sed 's/^......//')
if test $(($coverage < ${{ env.MIN_COVERAGE }})) = 1
then
echo ! Coverage is below ${{ env.MIN_COVERAGE }}% ! >> $GITHUB_STEP_SUMMARY
exit 1
fi