Repository navigation
104 lines (87 loc) · 3.61 KB
/
Copy pathci.yml
File metadata and controls
104 lines (87 loc) · 3.61 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
name: CI
on:
push:
branches: [master]
pull_request:
branches: [master]
permissions:
contents: read
jobs:
test:
name: Build and test (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- uses: actions/setup-dotnet@0f4a354dd5547a28c70b7853dbd95d5b67886e73 # v6
with:
dotnet-version: |
8.0.x
10.0.x
11.0.x
- name: Restore
run: dotnet restore UnitConversion.slnx
- name: Build
run: dotnet build UnitConversion.slnx --no-restore -c Release
- name: Format check
if: matrix.os == 'ubuntu-latest'
run: dotnet format UnitConversion.slnx --verify-no-changes --severity warn --verbosity minimal
- name: Test (net8.0, net10.0 and net11.0) with coverage
run: dotnet test UnitConversion.slnx --no-build -c Release --collect:"XPlat Code Coverage" --results-directory ./TestResults
- name: Coverage summary
if: matrix.os == 'ubuntu-latest'
run: |
dotnet tool install --global dotnet-reportgenerator-globaltool --version 5.5.11
reportgenerator -reports:"TestResults/**/coverage.cobertura.xml" -targetdir:coverage \
-assemblyfilters:"+UnitConversion;-UnitConversionTests;-UnitConversionExample" \
-reporttypes:"MarkdownSummaryGithub;Cobertura"
cat coverage/SummaryGithub.md >> "$GITHUB_STEP_SUMMARY"
- name: Enforce line coverage
if: matrix.os == 'ubuntu-latest'
run: |
rate=$(grep -oP '<coverage[^>]*line-rate="\K[0-9.]+' coverage/Cobertura.xml | head -1)
pct=$(awk -v r="$rate" 'BEGIN { printf "%.1f", r * 100 }')
echo "Line coverage: ${pct}% (minimum 95%)"
awk -v r="$rate" 'BEGIN { exit (r >= 0.95) ? 0 : 1 }' || { echo "::error::Line coverage ${pct}% is below the 95% minimum"; exit 1; }
- name: Upload coverage report
if: matrix.os == 'ubuntu-latest'
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
with:
name: coverage
path: coverage/
package:
name: Pack and check the package
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- uses: actions/setup-dotnet@0f4a354dd5547a28c70b7853dbd95d5b67886e73 # v6
with:
dotnet-version: |
8.0.x
10.0.x
11.0.x
- name: Pack
run: dotnet pack UnitConversion/UnitConversion.csproj -c Release -o nupkgs
- name: No vulnerable dependencies reach consumers
run: |
dotnet restore UnitConversion/UnitConversion.csproj
report=$(dotnet list UnitConversion/UnitConversion.csproj package --vulnerable --include-transitive 2>&1)
echo "$report"
if echo "$report" | grep -q "has the following vulnerable packages"; then
echo "::error::The package depends on a vulnerable package"
exit 1
fi
- name: Package contents
run: |
unzip -l nupkgs/UnitConversion.*.nupkg | grep -E "lib/|README|icon"
for tfm in netstandard2.0 net8.0 net10.0 net11.0; do
unzip -l nupkgs/UnitConversion.*.nupkg | grep -q "lib/$tfm/UnitConversion.dll" || { echo "::error::lib/$tfm is missing"; exit 1; }
done
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
with:
name: nupkgs
path: nupkgs/