This repository was archived by the owner on Nov 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
247 lines (215 loc) · 8.67 KB
/
ci.yml
File metadata and controls
247 lines (215 loc) · 8.67 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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
name: CI
on:
push:
branches:
- master
- main
- develop
- beta/*
- release/*
- experimental/*
- feature/*
paths-ignore:
- 'README.md'
- 'docs/**'
- 'samples/**'
pull_request:
branches:
- master
- main
- develop
env:
DOTNET_VERSION: '10.0'
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
DOTNET_INSTALL_DIR: ${{ github.workspace }}/.dotnet
jobs:
validate:
name: Validate Build Context
runs-on: windows-latest
steps:
- name: Display build context
run: |
echo "Build branch: ${{ github.ref }}"
echo "Build configuration: ${{ env.BUILD_CONFIGURATION }}"
echo ".NET Version: ${{ env.DOTNET_VERSION }}"
build:
name: Build and Test
runs-on: windows-latest
needs: validate
env:
BUILD_CONFIGURATION: ${{ github.ref == 'refs/heads/master' && 'Release' || github.ref == 'refs/heads/develop' && 'Alpha' || startsWith(github.ref, 'refs/heads/beta/') && 'Beta' || startsWith(github.ref, 'refs/heads/release/') && 'Preview' || startsWith(github.ref, 'refs/heads/experimental/') && 'Experimental' || 'Debug' }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cache .NET SDK
uses: actions/cache@v4
with:
path: ${{ env.DOTNET_INSTALL_DIR }}
key: ${{ runner.os }}-dotnet-${{ env.DOTNET_VERSION }}
restore-keys: |
${{ runner.os }}-dotnet-
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
- name: Cache NuGet packages
uses: actions/cache@v4
with:
path: ${{ env.NUGET_PACKAGES }}
key: ${{ runner.os }}-nuget-${{ hashFiles('**/Directory.Packages.props') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Set version variables
uses: dotnet/nbgv@master
with:
setAllVars: true
- name: Cache .NET tools
uses: actions/cache@v4
with:
path: ~/.dotnet/tools
key: ${{ runner.os }}-dotnet-tools-reportgenerator
restore-keys: |
${{ runner.os }}-dotnet-tools-
- name: Install ReportGenerator
run: |
$tools = dotnet tool list -g
if ($tools -notmatch "dotnet-reportgenerator-globaltool") {
dotnet tool install -g dotnet-reportgenerator-globaltool
}
- name: Restore packages
run: dotnet restore
- name: Build
run: dotnet build --configuration ${{ env.BUILD_CONFIGURATION }} --no-restore -p:ContinuousIntegrationBuild=true
- name: Run unit tests with coverage
run: |
dotnet test --configuration ${{ env.BUILD_CONFIGURATION }} --no-build --collect:"XPlat Code Coverage" --settings coverlet.runsettings --filter "Category!=Integration" --logger trx --results-directory ${{ runner.temp }}
continue-on-error: ${{ contains(fromJSON('["Experimental", "Alpha"]'), env.BUILD_CONFIGURATION) }}
- name: Generate coverage report
if: always()
run: |
reportgenerator -reports:${{ runner.temp }}/**/coverage.cobertura.xml -targetdir:${{ runner.temp }}/CodeCoverage -reporttypes:"Cobertura;Html;Badges"
continue-on-error: true
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results
path: ${{ runner.temp }}/*.trx
- name: Upload coverage report
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: ${{ runner.temp }}/CodeCoverage
- name: Pack packages
run: |
dotnet pack --configuration ${{ env.BUILD_CONFIGURATION }} --no-build --output ${{ github.workspace }}/packages -p:RepositoryUrl=${{ github.server_url }}/${{ github.repository }} -p:RepositoryBranch=${{ github.ref_name }} -p:RepositoryCommit=${{ github.sha }}
- name: Upload packages
uses: actions/upload-artifact@v4
with:
name: packages
path: ${{ github.workspace }}/packages
security-scan:
name: Security Scanning
runs-on: windows-latest
needs: validate
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/heads/beta/') || startsWith(github.ref, 'refs/heads/release/')
permissions:
actions: read
contents: read
security-events: write
env:
BUILD_CONFIGURATION: ${{ github.ref == 'refs/heads/master' && 'Release' || github.ref == 'refs/heads/develop' && 'Alpha' || startsWith(github.ref, 'refs/heads/beta/') && 'Beta' || startsWith(github.ref, 'refs/heads/release/') && 'Preview' || 'Alpha' }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cache .NET SDK
uses: actions/cache@v4
with:
path: ${{ env.DOTNET_INSTALL_DIR }}
key: ${{ runner.os }}-dotnet-${{ env.DOTNET_VERSION }}
restore-keys: |
${{ runner.os }}-dotnet-
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
- name: Cache NuGet packages
uses: actions/cache@v4
with:
path: ${{ env.NUGET_PACKAGES }}
key: ${{ runner.os }}-nuget-${{ hashFiles('**/Directory.Packages.props') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: csharp
- name: Restore packages
run: dotnet restore
- name: Build for CodeQL
run: dotnet build --configuration ${{ env.BUILD_CONFIGURATION }} --no-restore
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
- name: Security audit
run: dotnet list package --vulnerable --include-transitive
publish-packages:
name: Publish Packages
runs-on: windows-latest
needs: [build, security-scan]
if: |
github.event_name == 'push' &&
(github.ref == 'refs/heads/master' ||
github.ref == 'refs/heads/main' ||
github.ref == 'refs/heads/develop' ||
startsWith(github.ref, 'refs/heads/beta/') ||
startsWith(github.ref, 'refs/heads/release/'))
steps:
- name: Download packages
uses: actions/download-artifact@v4
with:
name: packages
path: ${{ github.workspace }}/packages
- name: List package contents
run: |
Get-ChildItem -Path "${{ github.workspace }}/packages" -Recurse
# For GitHub Packages - only for nightly/experimental branches
- name: Push to GitHub Packages
if: |
github.event_name == 'push' &&
(github.ref == 'refs/heads/develop' ||
startsWith(github.ref, 'refs/heads/experimental/') ||
startsWith(github.ref, 'refs/heads/feature/'))
run: |
Get-ChildItem -Path "${{ github.workspace }}/packages" -Filter "*.nupkg" -Recurse | ForEach-Object {
dotnet nuget push $_.FullName --source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate
}
continue-on-error: true
# For NuGet.org - publish stable and prerelease versions
- name: Push to NuGet.org
if: |
github.event_name == 'push' &&
(github.ref == 'refs/heads/master' ||
github.ref == 'refs/heads/main' ||
github.ref == 'refs/heads/develop' ||
startsWith(github.ref, 'refs/heads/release/')) &&
env.NUGET_API_KEY != ''
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: |
Get-ChildItem -Path "${{ github.workspace }}/packages" -Filter "*.nupkg" -Recurse | ForEach-Object {
dotnet nuget push $_.FullName --source "https://api.nuget.org/v3/index.json" --api-key ${{ secrets.NUGET_API_KEY }} --skip-duplicate
}
continue-on-error: true
- name: Tag release
if: github.ref == 'refs/heads/master'
run: |
git config user.email "cmblair@domesticateddata.com"
git config user.name "jConner"
git tag -a "v${{ env.NBGV_SemVer2 }}" -m "Release v${{ env.NBGV_SemVer2 }}"
git push origin "v${{ env.NBGV_SemVer2 }}"
continue-on-error: true