forked from Lombiq/GitHub-Actions
-
Notifications
You must be signed in to change notification settings - Fork 0
193 lines (185 loc) · 8.17 KB
/
build-and-test-dotnet.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
name: Build and Test .NET solution
on:
workflow_call:
secrets:
CHECKOUT_TOKEN:
required: false
description: >
The GitHub token to authenticate checkout. Pass in a GitHub personal access token if authenticated submodules
are used.
inputs:
cancel-workflow-on-failure:
description: When set to "true", will cancel the current workflow run with all jobs if this workflow fails.
required: false
type: string
default: "true"
# This needs to be stringified JSON because inputs don't support arrays, see
# https://github.community/t/reusable-workflow-with-strategy-matrix/205676/2.
machine-types:
required: false
type: string
default: "['ubuntu-22.04']"
description: >
Stringified JSON array with the name of the type of machine(s) to run the workflow under, e.g.
"['ubuntu-22.04']" or "['ubuntu-22.04', 'windows-2022']".
dotnet-version:
required: false
type: string
default: 6.0.x
description: Version of the .NET SDK to set up.
build-directory:
required: false
type: string
default: .
description: Path to the directory where a solution file can be found.
build-configuration:
required: false
type: string
default: Release
description: Configuration parameter for dotnet build (e.g. Debug, Release).
build-solution-path:
required: false
type: string
default: "*.sln"
description: >
The path of the solution or project file to be built. If there's exactly one .sln file in the build directory
then this can be omitted. For further information, see the documentation of the build-dotnet action.
build-verbosity:
required: false
type: string
default: quiet
description: Verbosity parameter for dotnet build.
build-enable-code-analysis:
required: false
type: string
default: "true"
description: Indicates whether to enable static code analysis during dotnet build.
build-enable-nuget-caching:
required: false
type: string
default: "false"
description: >
If set to "true", the NuGet packages will be cached by GitHub. This is faster if you have a lot of NuGet
packages, but negligible or even slower if you only have a handful.
build-enable-npm-caching:
required: false
type: string
default: "false"
description: >
If set to "true", the NPM packages will be cached by GitHub. This is faster if you have a lot of NPM packages,
but negligible or even slower if you only have a handful.
build-cache-version:
required: false
type: string
default: "0"
description: >
Change this to any other value to alter the cache key, effectively invalidating the latest cache. This is the
only current way to force "clear" the cache
(https://github.community/t/how-to-clear-cache-in-github-actions/129038/5) until the associated issue
(https://github.com/actions/cache/issues/2) is resolved.
build-create-binary-log:
required: false
type: string
default: "false"
description: >
Configures MSBuild to create a binary log. This is useful to inspect and debug builds. See
https://github.com/dotnet/msbuild/blob/main/documentation/wiki/Binary-Log.md for details.
build-binary-log-artifact-retention-days:
required: false
type: string
default: "14"
description: >
Duration in days after which the artifact of the build's binary log (if any) will expire. See
https://github.com/actions/upload-artifact#retention-period for more details.
test-disable:
required: false
type: string
default: "false"
description: Disables test execution completely if set to "true".
test-filter:
required: false
type: string
description: >
Filter expression for dotnet test. See:
https://learn.microsoft.com/en-us/dotnet/core/testing/selective-unit-tests.
xunit-max-parallel-threads:
required: false
type: string
default: "0"
description: >
Sets the maxParallelThreads configuration in all available xUnit xunit.runner.json configuration files. See
https://xunit.net/docs/configuration-files#maxParallelThreads for details on available values.
timeout-minutes:
required: false
type: number
default: 360
description: Configuration for the timeout-minutes parameter of the workflow. The 360 is GitHub's default.
verify-dotnet-consolidation:
required: false
type: boolean
default: true
description: >
When set to true, it will be verified whether the NuGet packages of the .NET solution are consolidated, i.e.
the same version of a given package is used in all projects.
warnings-as-errors:
required: false
type: string
default: "true"
description: >
Whether compiler warnings should be treated as errors during the build process. The default value is "true",
the compiler flag "-warnaserror" will be used, causing the build to fail if any warnings are generated. If set
to "false", the flag "-warnaserror" will not be used, allowing warnings to be generated without causing the
build to fail.
jobs:
# While the below steps seem suitable to DRY with build-and-test-orchard-core, since reusable workflows can't call
# other workflows, they'd need to be encapsulated in a composite action. That, however, will result in a single step
# being shown under the build details with all below steps mushed together.
build-and-test:
runs-on: ${{ matrix.machine-type }}
name: Build and Test
strategy:
matrix:
machine-type: ${{ fromJson(inputs.machine-types) }}
timeout-minutes: ${{ inputs.timeout-minutes }}
steps:
- name: Checkout
uses: Lombiq/GitHub-Actions/.github/actions/checkout@dev
with:
token: ${{ secrets.CHECKOUT_TOKEN }}
- name: Set up .NET
uses: Lombiq/GitHub-Actions/.github/actions/setup-dotnet@dev
with:
dotnet-version: ${{ inputs.dotnet-version }}
- name: Verify that .NET packages are consolidated
if: ${{ inputs.verify-dotnet-consolidation }}
uses: Lombiq/GitHub-Actions/.github/actions/verify-dotnet-consolidation@dev
with:
directory: ${{ inputs.build-directory }}
- name: Build and Static Code Analysis
uses: Lombiq/GitHub-Actions/.github/actions/build-dotnet@dev
with:
directory: ${{ inputs.build-directory}}
configuration: ${{ inputs.build-configuration}}
verbosity: ${{ inputs.build-verbosity}}
enable-code-analysis: ${{ inputs.build-enable-code-analysis}}
enable-nuget-caching: ${{ inputs.build-enable-nuget-caching }}
enable-npm-caching: ${{ inputs.build-enable-npm-caching }}
cache-version: ${{ inputs.build-cache-version }}
solution-or-project-path: ${{ inputs.build-solution-path }}
create-binary-log: ${{ inputs.build-create-binary-log }}
binary-log-artifact-retention-days: ${{ inputs.build-binary-log-artifact-retention-days }}
warnings-as-errors: ${{ inputs.warnings-as-errors }}
- name: Tests
if: inputs.test-disable == 'false'
uses: Lombiq/GitHub-Actions/.github/actions/test-dotnet@dev
with:
build-directory: ${{ inputs.build-directory }}
solution-path: ${{ inputs.build-solution-path }}
test-verbosity: ${{ inputs.build-verbosity }}
test-filter: ${{ inputs.test-filter }}
xunit-max-parallel-threads: ${{ inputs.xunit-max-parallel-threads }}
- name: Cancel Workflow on Failure
if: failure() && inputs.cancel-workflow-on-failure == 'true'
uses: Lombiq/GitHub-Actions/.github/actions/cancel-workflow@dev
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}