-
Notifications
You must be signed in to change notification settings - Fork 0
398 lines (318 loc) · 11 KB
/
ci-build.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
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
name: CI Build
run-name: CIBuild_${{ github.event_name }}_${{ github.ref_name }}_${{ github.run_number }}.${{ github.run_attempt }}
env:
PKG_MAJOR_VERSION: 1.3
PROJECT_NAME: DNX.Extensions
DOTNET_VERSION: 8.0.x
NUGET_VERSION: 5.x
BUILD_CONFIG: Release
BUILD_PLATFORM: Any CPU
PACK_PARAMETERS: ''
COVERAGE_WARNING_THRESHOLD: 95
COVERAGE_ERROR_THRESHOLD: 85
NUGET_OUTPUT_FOLDER: nupkgs
BRANCH_PREFIX_RELEASE_CANDIDATE: rc/
BRANCH_PREFIX_PUBLISH_CANDIDATE: beta/
BRANCH_NAME_BENCHMARK_CANDIDATE: benchmark
on:
push:
branches:
- main
- rc/**
- feature/**
- task/**
- spike/**
pull_request:
branches:
- main
workflow_dispatch:
jobs:
##########################################################
## Pipeline Configuration and Setup
setup:
name: Setup Pipeline
runs-on: ubuntu-latest
steps:
- name: Get Current Build Date
run: echo "build_date=$(date +'%y%j')" >> $GITHUB_ENV
- name: Evaluate pipeline conditions
run: |
is_primary_branch=false
is_pull_request_build=false
is_release_candidate_branch=false
is_publish_candidate_branch=false
is_benchmark_candidate_branch=false
# Primary Branch ?
if [ "${{ github.ref }}" == 'refs/heads/main' ]
then
is_primary_branch=true
fi
# Pull Request ?
if [ "${{ github.event_name }}" == "pull_request" ]
then
is_pull_request_build=true
fi
# If Release Candidate branch ?
if [[ "${{ github.ref }}" == refs/heads/${{ env.BRANCH_PREFIX_RELEASE_CANDIDATE }}* ]]
then
is_release_candidate_branch=true
fi
# Is Publish Candidate branch ?
if [[ "${{ github.ref }}" == refs/heads/${{ env.BRANCH_PREFIX_PUBLISH_CANDIDATE }}* ]]
then
is_publish_candidate_branch=true
fi
# Is Benchmark Candidate branch ?
if [[ "${{ github.ref }}" == *${{ env.BRANCH_NAME_BENCHMARK_CANDIDATE }}* ]]
then
is_benchmark_candidate_branch=true
fi
# Set for later steps
echo "is_primary_branch=${is_primary_branch}" >> $GITHUB_ENV
echo "is_pull_request_build=${is_pull_request_build}" >> $GITHUB_ENV
echo "is_release_candidate_branch=${is_release_candidate_branch}" >> $GITHUB_ENV
echo "is_publish_candidate_branch=${is_publish_candidate_branch}" >> $GITHUB_ENV
echo "is_benchmark_candidate_branch=${is_benchmark_candidate_branch}" >> $GITHUB_ENV
- name: Determine Tagging
run: |
should_tag=false
if $is_primary_branch
then
should_tag=true
fi
echo "should_tag=${should_tag}" >> $GITHUB_ENV
- name: Determine GitHub Releasing
run: |
should_release=false
release_is_draft=false
release_is_prerelease=false
if $is_primary_branch
then
should_release=true
elif $is_release_candidate_branch
then
should_release=true
release_is_draft=true
if $is_pull_request_build; then
release_is_draft=false
release_is_prerelease=true
fi
fi
echo "should_release=${should_release}" >> $GITHUB_ENV
echo "release_is_draft=${release_is_draft}" >> $GITHUB_ENV
echo "release_is_prerelease=${release_is_prerelease}" >> $GITHUB_ENV
- name: Determine Benchmarking
run: |
should_benchmark=false
if $should_release
then
should_benchmark=true
elif $is_pull_request_build
then
should_benchmark=true
elif $is_benchmark_candidate_branch
then
should_benchmark=true
fi
echo "should_benchmark=${should_benchmark}" >> $GITHUB_ENV
- name: Determine package publishing
run: |
should_publish=false
if $is_primary_branch
then
should_publish=true
elif $is_pull_request_build
then
should_publish=true
elif $is_publish_candidate_branch
then
should_publish=true
fi
echo "should_publish=${should_publish}" >> $GITHUB_ENV
- name: Set Package Suffix
run: |
package_suffix=''
if !($is_primary_branch)
then
package_suffix='-beta'
if $should_release
then
package_suffix='-rc'
fi
fi
echo "package_suffix=${package_suffix}" >> $GITHUB_ENV
- name: Set Product Version
run: echo "product_version=${{ env.PKG_MAJOR_VERSION }}" >> $GITHUB_ENV
- name: Set Assembly Version
run: echo "assembly_version=${{ env.PKG_MAJOR_VERSION }}.${{ env.build_date }}.${{ github.run_number }}${{ github.run_attempt }}" >> $GITHUB_ENV
- name: Set Package Version
run: echo "package_version=${{ env.assembly_version }}${{ env.package_suffix }}" >> $GITHUB_ENV
- name: Show Configuration
run: env | sort
outputs:
assembly_version: ${{ env.assembly_version }}
product_version: ${{ env.product_version }}
package_version: ${{ env.package_version }}
should_tag: ${{ env.should_tag }}
should_publish: ${{ env.should_publish }}
should_release: ${{ env.should_release }}
should_benchmark: ${{ env.should_benchmark }}
release_is_draft: ${{ env.release_is_draft }}
release_is_prerelease: ${{ env.release_is_prerelease }}
##########################################################
## Build DotNet projects
build:
name: Build .NET
needs: setup
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Restore NuGet packages
run: dotnet restore
- name: Build
run: dotnet build --no-restore --configuration ${{ env.BUILD_CONFIG }} /p:"Platform=${{ env.BUILD_PLATFORM }}" /p:"Version=${{ needs.setup.outputs.product_version }}" /p:"AssemblyVersion=${{ needs.setup.outputs.assembly_version }}"
- name: Test
run: dotnet test --no-restore --no-build --configuration ${{ env.BUILD_CONFIG }} --verbosity normal --collect:"XPlat Code Coverage" --logger:trx;LogFileName=TestOutput.trx
- name: Test Results Summary
uses: bibipkins/[email protected]
if: success() || failure()
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
comment-title: 'Unit Test Results'
results-path: "**/*.trx"
coverage-type: cobertura
- name: Code Coverage Report
uses: irongut/[email protected]
if: success() || failure()
with:
filename: "**/coverage.cobertura.xml"
badge: true
fail_below_min: true
format: markdown
hide_branch_rate: false
hide_complexity: false
indicators: true
output: both
thresholds: '${{ env.COVERAGE_ERROR_THRESHOLD }} ${{ env.COVERAGE_WARNING_THRESHOLD }}'
- name: Output Code Coverage
run: cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY
- name: Pull Request - Add Coverage Comment
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request'
with:
recreate: true
path: code-coverage-results.md
- name: Pack
run: dotnet pack --configuration ${{ env.BUILD_CONFIG }} /p:"Platform=${{ env.BUILD_PLATFORM }}" /p:"PackageVersion=${{ needs.setup.outputs.package_version }}" --no-restore --output "${{ env.NUGET_OUTPUT_FOLDER }}"
- name: Upload Build Artifact
uses: actions/upload-artifact@v4
with:
name: build_output
path: "**/${{ env.PROJECT_NAME }}/bin/${{ env.BUILD_CONFIG }}/**"
if-no-files-found: error
- name: Upload NuGet Artifact
uses: actions/upload-artifact@v4
with:
name: nuget_output
path: "${{ env.NUGET_OUTPUT_FOLDER }}/**"
if-no-files-found: error
##########################################################
## Tag in git
tag:
name: Tag in GitHub
if: needs.setup.outputs.should_tag == 'true'
needs:
- setup
- build
runs-on: ubuntu-latest
steps:
- name: Tag git
uses: pkgdeps/git-tag-action@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
github_repo: ${{ github.repository }}
git_commit_sha: ${{ github.sha }}
git_tag_prefix: "v"
version: ${{ needs.setup.outputs.assembly_version }}
##########################################################
## Generate a GitHub Release
release:
name: Create GitHub Release
if: needs.setup.outputs.should_release == 'true'
needs:
- setup
- build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: nuget_output
path: nuget
- name: Build Changelog
uses: mikepenz/release-changelog-builder-action@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Release
uses: ncipollo/release-action@v1
with:
tag: v${{ needs.setup.outputs.assembly_version }}
name: Release ${{ needs.setup.outputs.assembly_version }}
body: ${{ steps.build_changelog.outputs.changelog }}
draft: ${{ needs.setup.outputs.release_is_draft }}
prerelease: ${{ needs.setup.outputs.release_is_prerelease }}
removeArtifacts: true
artifacts: '**/*.nupkg'
##########################################################
## Benchmark Performance
benchmark:
name: Benchmark Performance
if: needs.setup.outputs.should_benchmark == 'true'
needs:
- setup
- build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Run Benchmarks
run: dotnet run --configuration ${{ env.BUILD_CONFIG }} --project tests/DNX.Extensions.Benchmarks
- name: Publish Benchmark output
run: |
ls -la -R
cat BenchmarkDotNet.Artifacts/results/*Benchmarks-report-github.md >> $GITHUB_STEP_SUMMARY
##########################################################
## Publish to NuGet
publish:
name: Publish to NuGet
if: needs.setup.outputs.should_publish == 'true'
needs:
- setup
- build
runs-on: ubuntu-latest
steps:
- name: Install NuGet
uses: NuGet/setup-nuget@v2
with:
nuget-api-key: ${{ secrets.NUGET_API_KEY }}
nuget-version: ${{ env.NUGET_VERSION }}
- name: Download NuGet Output
uses: actions/download-artifact@v4
with:
name: nuget_output
path: ${{ env.NUGET_OUTPUT_FOLDER }}
- name: Publish
run: dotnet nuget push "**/*.nupkg" -k ${{ secrets.NUGET_API_KEY }} -s https://nuget.org
#
# - name: Publish
# run: nuget push "**/*.nupkg" -Source 'https://api.nuget.org/v3/index.json' -ApiKey