-
Notifications
You must be signed in to change notification settings - Fork 9
177 lines (166 loc) · 8.19 KB
/
msbuild-and-test.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
name: Build and Test .NET Solution with MSBuild
concurrency:
# If "cancel-in-progress-for-this-pr" is set to "true" and this run is for a pull request, then the concurrency
# key will be constructed from a handful of parameters to produce a value that would evaluate to the same value on
# a subsequent push (while still allowing different solutions to be built with the same configuration), causing
# the already running job (with the same strategy) for this pull request to be cancelled. Otherwise it will be the
# ID of the workflow run combined with the strategy parameters, making it more unique so that parallel runs of
# this job aren't kept waiting. This workflow's technical name is also included in both cases, so that it doesn't
# conflict with other jobs calling a different workflow that are started by the same caller workflow. The caller
# job's technical name is optionally included in the concurrency key, so that different jobs in the same parent
# workflow calling this one don't conflict with each other.
group: |
${{
inputs.cancel-in-progress-for-this-pr == 'true' && github.event_name == 'pull_request'
&& format('{0}_msbuild-and-test_{1}_{2}_{3}', github.workflow, inputs.parent-job-name, inputs.machine-type, github.ref)
|| format('{0}_msbuild-and-test_{1}_{2}', github.run_id, inputs.parent-job-name, inputs.machine-type)
}}
cancel-in-progress: ${{ inputs.cancel-in-progress-for-this-pr == 'true' }}
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.
ENVIRONMENT_VARIABLES_JSON:
required: false
description: >
A JSON string containing key-value pairs of environment variables to be set. You can use this to pass in
arbitrary environment variables that can be used to e.g. customize the build or test execution.
inputs:
cancel-in-progress-for-this-pr:
description: >
When set to "true", it will cancel the already running workflow for this pull request. See the concurrency
settings of the workflow above for more details.
type: string
default: 'true'
parent-job-name:
description: >
An optional technical identifier that is used to construct the concurrency key to be able to distinguish
different jobs in the same parent workflow calling this one. This is necessary if you build multiple solutions
(as separate jobs) in the same workflow for these jobs not to conflict with each other.
type: string
default: parent-job
required: false
cancel-workflow-on-failure:
description: When set to "true", it will cancel the current workflow run with all jobs if this workflow fails.
type: string
default: 'true'
machine-type:
type: string
default: windows-2022
description: >
The machine type to run the workflow under, e.g. "windows-2022". Needs to be Windows.
repository:
description: >
Repository name with owner to git checkout, if not the current repository. E.g. "Lombiq/GitHub-Actions".
Defaults to the current repository.
type: string
default: ${{ github.repository }}
repository-ref:
description: >
The branch, tag or SHA to checkout. When checking out the repository that triggered the workflow, this
defaults to the reference or SHA for that event. Otherwise, uses the default branch.
type: string
default: ''
build-directory:
type: string
default: .
description: Path to the directory where a solution file can be found.
solution-or-project-path:
type: string
default: '*.sln'
description: >
The path of the solution or project file to be built. If you have exactly one .sln file in the current
directory then this can be omitted. Otherwise make sure to specify it to avoid an "MSB1008: Only one project
can be specified." error that is thrown when the `*.sln` wildcard results in multiple files. To build a
project file you must specify a path that ends with `.csproj`. An example: "./src/*Web/*.Web.csproj". The
value is given to PowerShell's `Get-ChildItem` cmdlet as-is, so grepping is still possible but a name with
spaces must be escaped separately.
build-verbosity:
type: string
default: quiet
description: Verbosity parameter for msbuild.
build-treat-warnings-as-errors:
type: string
default: 'true'
description: Indicates whether warnings should be treated as errors during msbuild.
build-enable-code-analysis:
type: string
default: 'true'
description: Indicates whether to enable static code analysis during msbuild.
dotnet-test-process-timeout:
required: false
type: number
default: -1
description: Run the dotnet test process with the given timeout in milliseconds. -1 means no timeout.
test-disable:
type: string
default: 'false'
description: Disables test execution completely if set to "true".
test-filter:
type: string
description: >
Filter expression for dotnet test. See:
https://learn.microsoft.com/en-us/dotnet/core/testing/selective-unit-tests.
timeout-minutes:
type: number
default: 360
description: Configuration for the timeout-minutes parameter of the workflow. 360 is GitHub's default.
collect-workflow-telemetry:
type: string
default: 'true'
description: >
If "true" (the default), detailed telemetry about the workflow run will be collected with
https://github.com/catchpoint/workflow-telemetry-action.
jobs:
build-and-test:
runs-on: ${{ inputs.machine-type }}
name: Build and Test
timeout-minutes: ${{ inputs.timeout-minutes }}
steps:
# This has to be the first step so it can collect data about the whole workflow run.
- name: Collect Workflow Telemetry
if: inputs.collect-workflow-telemetry == 'true'
uses: Lombiq/GitHub-Actions/.github/actions/workflow-telemetry@dev
with:
github_token: ${{ secrets.CHECKOUT_TOKEN }}
- name: Set Environment Variables
uses: Lombiq/GitHub-Actions/.github/actions/set-environment-variables@dev
env:
ENVIRONMENT_VARIABLES_JSON: ${{ secrets.ENVIRONMENT_VARIABLES_JSON }}
- name: Checkout
uses: Lombiq/GitHub-Actions/.github/actions/checkout@dev
with:
repository: ${{ inputs.repository }}
ref: ${{ inputs.repository-ref }}
token: ${{ secrets.CHECKOUT_TOKEN }}
- name: Enable Node corepack
uses: Lombiq/GitHub-Actions/.github/actions/enable-corepack@dev
# This is necessary for building Gulp Extensions and test-dotnet.
- name: Set up .NET
uses: Lombiq/GitHub-Actions/.github/actions/setup-dotnet@dev
- name: Build and Static Code Analysis
uses: Lombiq/GitHub-Actions/.github/actions/msbuild@dev
with:
directory: ${{ inputs.build-directory }}
solution-or-project-path: ${{ inputs.solution-or-project-path }}
verbosity: ${{ inputs.build-verbosity }}
treat-warnings-as-errors: ${{ inputs.build-treat-warnings-as-errors }}
enable-code-analysis: ${{ inputs.build-enable-code-analysis }}
- name: Tests
if: inputs.test-disable == 'false'
uses: Lombiq/GitHub-Actions/.github/actions/test-dotnet@dev
with:
build-directory: ${{ inputs.build-directory }}
dotnet-test-process-timeout: ${{ inputs.dotnet-test-process-timeout }}
test-verbosity: ${{ inputs.build-verbosity }}
test-filter: ${{ inputs.test-filter }}
test-configuration: Release
- 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 }}