-
Notifications
You must be signed in to change notification settings - Fork 0
147 lines (118 loc) · 5.14 KB
/
Copy pathbuild.yml
File metadata and controls
147 lines (118 loc) · 5.14 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
name: Build
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: 10.0.x
- name: Restore
run: dotnet restore
- name: Build
run: dotnet build --no-restore -c Release
- name: Test with Coverage
run: |
dotnet tool install -g dotnet-coverage
dotnet-coverage collect -s coverage.runsettings -f cobertura -o ./coverage/coverage.cobertura.xml "dotnet test --no-build -c Release --verbosity normal"
- name: Generate Coverage Report
run: |
dotnet tool install -g dotnet-reportgenerator-globaltool
reportgenerator -reports:./coverage/coverage.cobertura.xml -targetdir:./coverage/report -reporttypes:"MarkdownSummaryGithub;Badges" -assemblyfilters:"+SimpleBranchVersioning"
- name: Check Coverage Thresholds
run: |
LINE_THRESHOLD=85
BRANCH_THRESHOLD=75
LINE_RATE=$(grep -oP 'line-rate="\K[^"]+' ./coverage/coverage.cobertura.xml | head -1)
BRANCH_RATE=$(grep -oP 'branch-rate="\K[^"]+' ./coverage/coverage.cobertura.xml | head -1)
LINE_PCT=$(echo "$LINE_RATE * 100" | bc -l | xargs printf "%.1f")
BRANCH_PCT=$(echo "$BRANCH_RATE * 100" | bc -l | xargs printf "%.1f")
echo "Line coverage: $LINE_PCT% (threshold: $LINE_THRESHOLD%)"
echo "Branch coverage: $BRANCH_PCT% (threshold: $BRANCH_THRESHOLD%)"
FAILED=0
if (( $(echo "$LINE_PCT < $LINE_THRESHOLD" | bc -l) )); then
echo "::error::Line coverage $LINE_PCT% is below threshold of $LINE_THRESHOLD%"
FAILED=1
fi
if (( $(echo "$BRANCH_PCT < $BRANCH_THRESHOLD" | bc -l) )); then
echo "::error::Branch coverage $BRANCH_PCT% is below threshold of $BRANCH_THRESHOLD%"
FAILED=1
fi
if [ $FAILED -eq 1 ]; then
exit 1
fi
echo "::notice::Coverage thresholds met!"
- name: Add Coverage to Job Summary
if: always()
run: cat ./coverage/report/SummaryGithub.md >> $GITHUB_STEP_SUMMARY
- name: Publish Coverage Badge
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
mkdir -p /tmp/badges
cp ./coverage/report/badge_linecoverage.svg /tmp/badges/
cp ./coverage/report/badge_branchcoverage.svg /tmp/badges/
if git ls-remote --exit-code --heads origin coverage; then
git fetch origin coverage:coverage
git switch coverage
else
git switch --orphan coverage
fi
cp /tmp/badges/*.svg .
git add badge_linecoverage.svg badge_branchcoverage.svg
if git diff --staged --quiet; then
echo "No changes to coverage badges"
else
git commit -m "Update coverage badges"
git push origin coverage
fi
verify-frameworks:
runs-on: ubuntu-latest
strategy:
matrix:
dotnet-version: ['8.0', '9.0', '10.0']
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Setup .NET SDKs
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
8.0.x
9.0.x
10.0.x
- name: Build Example Apps
run: |
dotnet build tests/SimpleBranchVersioning.ExampleApp -c Release
dotnet build tests/SimpleBranchVersioning.ConfiguredApp -c Release
- name: Run ExampleApp
run: dotnet run --project tests/SimpleBranchVersioning.ExampleApp -f net${{ matrix.dotnet-version }} -c Release --no-build
- name: Run ConfiguredApp
run: dotnet run --project tests/SimpleBranchVersioning.ConfiguredApp -f net${{ matrix.dotnet-version }} -c Release --no-build
- name: Verify version.json
run: |
# ConfiguredApp should have version.json (GenerateVersionFile=true)
if [ ! -f "tests/SimpleBranchVersioning.ConfiguredApp/bin/Release/net${{ matrix.dotnet-version }}/version.json" ]; then
echo "::error::ConfiguredApp is missing version.json for net${{ matrix.dotnet-version }}"
exit 1
fi
echo "ConfiguredApp version.json exists for net${{ matrix.dotnet-version }}"
cat tests/SimpleBranchVersioning.ConfiguredApp/bin/Release/net${{ matrix.dotnet-version }}/version.json
# ExampleApp should NOT have version.json (GenerateVersionFile=false by default)
if [ -f "tests/SimpleBranchVersioning.ExampleApp/bin/Release/net${{ matrix.dotnet-version }}/version.json" ]; then
echo "::error::ExampleApp should not have version.json for net${{ matrix.dotnet-version }}"
exit 1
fi
echo "ExampleApp correctly has no version.json for net${{ matrix.dotnet-version }}"