Repository navigation
225 lines (191 loc) · 7.53 KB
/
Copy pathdotnet.yml
File metadata and controls
225 lines (191 loc) · 7.53 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
name: CI
on:
push:
branches: [master]
pull_request:
workflow_dispatch:
permissions:
contents: read
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
jobs:
build-test:
name: Build and test (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up .NET
uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0
with:
dotnet-version: '10.0.x'
- name: Restore
run: dotnet restore --locked-mode
- name: Build
run: dotnet build --no-restore --configuration Release -warnaserror
- name: Test
shell: bash
run: |
dotnet test --project Tests/Tests.fsproj \
--configuration Release \
--no-build \
--report-trx \
--report-trx-filename "tests-${{ matrix.os }}.trx" \
--results-directory TestResults
- name: Report test counts
if: always()
shell: bash
run: |
tTrx="TestResults/tests-${{ matrix.os }}.trx"
tCounters=$(grep -oE '<Counters [^>]*' "$tTrx" 2>/dev/null | head -1)
if [ -z "$tCounters" ]; then
echo "::error::Could not find test counters in $tTrx."
exit 1
fi
counter() { echo "$tCounters" | grep -oE " $1=\"[0-9]+\"" | grep -oE '[0-9]+'; }
tTotal=$(counter total)
tPassed=$(counter passed)
tFailed=$(counter failed)
tSkipped=$(counter notExecuted)
{
echo "### Tests (${{ matrix.os }})"
echo
echo "| Total | Passed | Failed | Skipped |"
echo "| ---: | ---: | ---: | ---: |"
echo "| $tTotal | $tPassed | $tFailed | $tSkipped |"
} >> "$GITHUB_STEP_SUMMARY"
if [ "$tSkipped" -ne 0 ]; then
echo "::error::$tSkipped test(s) skipped. The bar is 0 failed and 0 skipped."
exit 1
fi
- name: Upload test results
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: test-results-${{ matrix.os }}
path: TestResults/*.trx
retention-days: 14
coverage:
name: Code coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up .NET
uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0
with:
dotnet-version: '10.0.x'
- name: Restore
run: dotnet restore --locked-mode
- name: Build
run: dotnet build --no-restore --configuration Release -warnaserror
- name: Test with coverage
run: >
dotnet test --project Tests/Tests.fsproj
--configuration Release
--no-build
--coverlet
--coverlet-output-format cobertura
--coverlet-include "[FSharp.Interop.Dynamic]*"
--coverlet-exclude "[Tests]*"
--results-directory TestResults
- name: Install ReportGenerator
run: dotnet tool install --tool-path ./tools --version 5.5.11 dotnet-reportgenerator-globaltool
- name: Generate report
run: >
./tools/reportgenerator
-reports:TestResults/**/coverage.cobertura*.xml
-targetdir:CoverageReport
-reporttypes:"MarkdownSummaryGithub;HtmlInline;Cobertura"
- name: Publish coverage to the job summary
shell: bash
run: cat CoverageReport/SummaryGithub.md >> "$GITHUB_STEP_SUMMARY"
- name: Enforce coverage floors
shell: bash
env:
MIN_LINE: '77'
MIN_BRANCH: '100'
run: |
tReport=$(find TestResults -name 'coverage.cobertura*.xml' | head -1)
if [ -z "$tReport" ]; then
echo "::error::No cobertura report was produced."
exit 1
fi
tHeader=$(grep -oE '^<coverage[^>]*' "$tReport")
tLineRate=$(echo "$tHeader" | grep -oE 'line-rate="[0-9.]+"' | grep -oE '[0-9.]+')
tBranchRate=$(echo "$tHeader" | grep -oE 'branch-rate="[0-9.]+"' | grep -oE '[0-9.]+')
tLinePct=$(awk -v r="$tLineRate" 'BEGIN { printf "%.1f", r * 100 }')
tBranchPct=$(awk -v r="$tBranchRate" 'BEGIN { printf "%.1f", r * 100 }')
tLinesCovered=$(echo "$tHeader" | grep -oE 'lines-covered="[0-9]+"' | grep -oE '[0-9]+')
tLinesValid=$(echo "$tHeader" | grep -oE 'lines-valid="[0-9]+"' | grep -oE '[0-9]+')
tBranchesCovered=$(echo "$tHeader" | grep -oE 'branches-covered="[0-9]+"' | grep -oE '[0-9]+')
tBranchesValid=$(echo "$tHeader" | grep -oE 'branches-valid="[0-9]+"' | grep -oE '[0-9]+')
{
echo "### Coverage floors"
echo
echo "| Metric | Covered | Total | Percent | Floor |"
echo "| --- | ---: | ---: | ---: | ---: |"
echo "| Lines | $tLinesCovered | $tLinesValid | ${tLinePct}% | ${MIN_LINE}% |"
echo "| Branches | $tBranchesCovered | $tBranchesValid | ${tBranchPct}% | ${MIN_BRANCH}% |"
} >> "$GITHUB_STEP_SUMMARY"
tFailed=0
if awk -v p="$tLinePct" -v m="$MIN_LINE" 'BEGIN { exit !(p < m) }'; then
echo "::error::Line coverage ${tLinePct}% is below the ${MIN_LINE}% floor."
tFailed=1
fi
if awk -v p="$tBranchPct" -v m="$MIN_BRANCH" 'BEGIN { exit !(p < m) }'; then
echo "::error::Branch coverage ${tBranchPct}% is below the ${MIN_BRANCH}% floor."
tFailed=1
fi
exit $tFailed
- name: Upload coverage report
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: coverage-report
path: CoverageReport
retention-days: 14
analyzers:
name: F# analyzers
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up .NET
uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0
with:
dotnet-version: '10.0.x'
- name: Restore
run: |
dotnet restore --locked-mode
dotnet tool restore
- name: Run Ionide analyzers
run: |
analyzer_version=$(sed -n 's/.*Include="Ionide.Analyzers" Version="\([^"]*\)".*/\1/p' Directory.Packages.props)
analyzer_path="${NUGET_PACKAGES:-$HOME/.nuget/packages}/ionide.analyzers/${analyzer_version}/analyzers/dotnet/fs"
if [ ! -d "$analyzer_path" ]; then
echo "::error::Ionide analyzer binaries not found at $analyzer_path"
exit 1
fi
dotnet fsharp-analyzers \
--project FSharp.Interop.Dynamic/FSharp.Interop.Dynamic.fsproj \
--analyzers-path "$analyzer_path" \
--configuration Release \
--verbosity n \
--output-format github \
--report ionide.sarif
- name: Upload analyzer SARIF
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: ionide-sarif
path: ionide.sarif
retention-days: 14