-
Notifications
You must be signed in to change notification settings - Fork 1
251 lines (213 loc) · 10.4 KB
/
ci.yaml
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
#
# GitHub Actions workflow: Builds and tests the code in this repository.
#
# For more details on workflows, see README.md.
#
# NOTES:
#
# * We don't use CodeQL because it takes, at the time of writing, 3 minutes to run which is
# 3x the time of the "build-and-test" job. Since we already have the Microsoft Code Analysis
# enabled, I don't expect CodeQL to offer much advantages (especially compared to the time it
# takes to execute).
#
name: Continuous Integration
# When to run this workflow
#
# See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows
# See: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on
#
# TIP: Don't use "schedule" triggers as this will cause the workflow to be disabled after 60 days of inactivity
# (and afterward the workflow must be manually reenabled).
on:
# Trigger the workflow on push to the main branch.
push:
branches:
- main
# Trigger the workflow for any pull requests.
pull_request:
# Allow manual run of this workflow (https://docs.github.com/en/actions/using-workflows/manually-running-a-workflow)
workflow_dispatch:
# Permissions for GITHUB_TOKEN for this workflow.
#
# See: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
#
# NOTE: Because we run with minimal permissions, we use "@vX" (instead of "@hash") for non-GitHub steps below.
# Usually you would use "@hash" as a security measure to pin a specific version. However, since we run with
# minimal permissions here, malicious code can't do much harm (most likely). For more details, see:
# https://blog.gitguardian.com/github-actions-security-cheat-sheet/#use-specific-action-version-tags
permissions:
contents: read
env:
DOTNET_VERSION: '8.0'
# NOTE: Jobs run in parallel by default.
# https://docs.github.com/en/actions/using-jobs/using-jobs-in-a-workflow
jobs:
#
# Build & Test job
#
build-and-test:
# Name of the job
name: Build & Test
# Set the type of machine to run on
# See: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on
runs-on: ubuntu-latest
steps:
###########################################################################
#
# Setup Steps
#
###########################################################################
# See: https://github.com/marketplace/actions/checkout
- name: Clone Git repository
uses: actions/checkout@v4
with:
lfs: true
submodules: true
# This creates ${{ steps.short-sha.outputs.sha }} to be used below.
# See: https://github.com/marketplace/actions/short-sha
- name: Determine Git short commit hash
id: short-sha
uses: benjlevesque/[email protected]
# See: https://github.com/marketplace/actions/setup-net-core-sdk
- name: Setup .NET build environment
uses: actions/setup-dotnet@v4
with:
# NOTE: Apparently only the 3rd component can be "x"; i.e. "5.x" is not supported.
dotnet-version: '${{ env.DOTNET_VERSION }}.x'
###########################################################################
#
# Build Steps
#
###########################################################################
# See: https://docs.microsoft.com/de-de/dotnet/core/tools/dotnet-build
# NOTE: Without specifying a solution file, "dotnet build" searches for a .sln file in the current directory.
- name: Build code
run: dotnet build --configuration Release
# See: https://docs.microsoft.com/de-de/dotnet/core/tools/dotnet-test
# NOTES:
# * Without specifying a solution file, "dotnet test" searches for a .sln file in the current directory.
# * There seems to be no way to name the .trx file as '<project>.trx'. If no 'LogFileName' is specified,
# the .trx files will be named something like "_fv-az278-737_2021-08-15_03_50_33.trx".
# * The Option 'TreatNoTestsAsError' is documented here: https://learn.microsoft.com/en-us/visualstudio/test/configure-unit-tests-by-using-a-dot-runsettings-file?view=vs-2022#runconfiguration-element
- name: Run tests
id: run_tests
run: dotnet test --configuration Release --no-restore --no-build --logger "trx;LogFileName=${{ runner.os }}.trx" --nologo -- RunConfiguration.TreatNoTestsAsError=true
env:
# Tells tests that they're running in a (potentially slow) CI environment.
RUNS_IN_CI: true
###########################################################################
#
# Archive Steps
#
###########################################################################
# See: https://github.com/marketplace/actions/upload-a-build-artifact
- name: Upload test results
uses: actions/upload-artifact@v4
# Run this step even if "run_tests" has failed (but not if any other previous step has failed - which would
# be "failure()" - because in this case the tests have not run and thus no .trx files have been generated).
# See: https://docs.github.com/en/actions/learn-github-actions/expressions#failure
if: success() || steps.run_tests.conclusion == 'failure'
with:
# NOTE: To make the downloads of the test results easier to use (i.e. when downloading test results
# from different runs), we'll add an id to the name.
#
# We don't just use the sha because this workflow also runs on a schedule - which means that different
# runs would again create files with the same name (e.g. two consecutive scheduled runs while the
# repo hasn't changed in the meantime).
#
# Instead we use 'github.run_number' because this gives us the same number that's also shown in the
# ui - like 27 for run #27 ('github.run_id' on the other hand gives us some "random" big number like
# 1152888876 - which is less useful). For more details, see:
# https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#github-context
#
# NOTE: We put the "run_number" first so that the result zip file can be sorted by name.
name: 'test-results-#${{ github.run_number }}-${{ steps.short-sha.outputs.sha }}-${{ runner.os }}'
path: '**/*.trx'
if-no-files-found: error
#
# Create action test report
#
test-report:
# Name of the job
name: Test Report
needs: build-and-test
# Set the type of machine to run on
# See: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on
runs-on: ubuntu-latest
permissions:
actions: read
checks: write
steps:
# See: https://github.com/marketplace/actions/download-a-build-artifact
#
# The dorny/[email protected] action doesn't support actions/upload-artifact@v4 yet.
# We therefore download the artifact manually and feed it to test-reporter as local files.
# See: https://github.com/dorny/test-reporter/issues/363
- name: Download test results
uses: actions/download-artifact@v4
with:
pattern: test-results-*
path: test-results
# See: https://github.com/marketplace/actions/test-reporter
- name: Create test report
# For pinned versions, see: https://blog.gitguardian.com/github-actions-security-cheat-sheet/#use-specific-action-version-tags
uses: dorny/test-reporter@eaa763f6ffc21c7a37837f56cd5f9737f27fc6c8 # version 1.8.0
with:
# NOTE: We add the 'github.run_number' to the name so that we can easier identify the
# test report if they pile up due to bug https://github.com/dorny/test-reporter/issues/67.
# See top of this file for more details.
name: 'Test Report #${{ github.run_number }}'
# Path to test results (downloaded in previous step)
path: 'test-results/**/*.trx'
# Format of test results
reporter: dotnet-trx
# Don't mark the test report generated as failed if there's a failed test.
# Only mark it as failed if something with the workflow has actually gone wrong.
fail-on-error: false
# Workaround for error 'fatal: not a git repository' caused by a call to 'git ls-files'
# See: https://github.com/dorny/test-reporter/issues/169#issuecomment-1583560458
max-annotations: 0
#
# Publish Online Documentation
#
documentation:
# Name of the job
name: Publish Documentation
# Only run this on the 'main' branch.
if: github.ref == 'refs/heads/main'
# Set the type of machine to run on
# See: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on
runs-on: ubuntu-latest
permissions:
# This job needs permissions to push changes to the "retype" branch. Thus, it needs "write" permission.
contents: write
steps:
###########################################################################
#
# Setup Steps
#
###########################################################################
# See: https://github.com/marketplace/actions/checkout
- name: Clone Git repository
uses: actions/checkout@v4
with:
lfs: true
submodules: false # not needed
###########################################################################
#
# Build Steps
#
###########################################################################
# See: https://github.com/retypeapp/action-build
- name: Build HTML files
# For pinned versions, see: https://blog.gitguardian.com/github-actions-security-cheat-sheet/#use-specific-action-version-tags
uses: retypeapp/action-build@a95ca1f9508dec8465a93f2e50a1228d22e90f4e # version 3.5.0
# See: https://github.com/retypeapp/action-github-pages
- name: Publish HTML files to GitHub Pages
# For pinned versions, see: https://blog.gitguardian.com/github-actions-security-cheat-sheet/#use-specific-action-version-tags
uses: retypeapp/action-github-pages@5a952a4f53fc7366288db464ec120f755e9f1303 # version 3.5.0
with:
# The branch where the results are stored
branch: retype
# Update the "retype" branch (instead of creating a new branch)
update-branch: true