forked from open-telemetry/opentelemetry-dotnet-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
243 lines (216 loc) · 9.02 KB
/
Copy pathComponent.BuildTest.yml
File metadata and controls
243 lines (216 loc) · 9.02 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
name: Build Component
on:
workflow_call:
inputs:
project-name:
required: true
type: string
run-tests:
required: false
default: true
type: boolean
code-cov-name:
required: true
type: string
code-cov-prefix:
default: 'unittests'
required: false
type: string
os-list:
default: '[ "windows-2025", "ubuntu-24.04" ]'
required: false
type: string
tfm-list:
default: '[ "net462", "net8.0", "net9.0", "net10.0" ]'
required: false
type: string
test-case-filter:
required: false
type: string
test-require-elevated:
default: false
required: false
type: boolean
pack:
default: true
required: false
type: boolean
trigger:
required: true
type: string
permissions:
contents: read
jobs:
build-test:
name: build-test
strategy:
fail-fast: ${{ inputs.trigger == 'merge_group' }}
matrix:
os: ${{ fromJSON(inputs.os-list) }}
version: ${{ fromJSON(inputs.tfm-list) }}
exclude:
# renovate: datasource=github-runners depType=github-runner
- os: ubuntu-24.04
version: net462
# renovate: datasource=github-runners depType=github-runner
- os: macos-26
version: net462
runs-on: ${{ matrix.os }}
timeout-minutes: 45
steps:
- name: Checkout code
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
# Note: By default GitHub only fetches 1 commit. MinVer needs to find
# the version tag which is typically NOT on the first commit so we
# retrieve them all.
fetch-depth: 0
persist-credentials: false
show-progress: false
- name: Get Git commit timestamp
id: get-commit-timestamp
shell: pwsh
run: |
"epoch=$(git log -1 --pretty=%ct)" >> ${env:GITHUB_OUTPUT}
- name: Resolve project
id: resolve-project
shell: pwsh
env:
PROJECT_NAME: ${{ inputs.project-name }}
run: |
Import-Module .\build\scripts\build.psm1
# Note: inputs.project-name is either a .proj file or
# Component[component_name]. The ResolveProject call here parses
# inputs.project-name into variables we need for build.
$title = '' # Used for friendly names in action UI
$project = '' # Actual project passed to dotnet
$component = '' # Used to tell Component.proj what to build
ResolveProject `
-projectNameOrComponentData ${env:PROJECT_NAME} `
-title ([ref]$title) `
-project ([ref]$project) `
-component ([ref]$component)
Write-Output "title=$title" >> $env:GITHUB_OUTPUT
Write-Output "project=$project" >> $env:GITHUB_OUTPUT
$artifactName = $component
if ([string]::IsNullOrEmpty($artifactName)) {
$artifactName = $title
if ($artifactName.EndsWith(".proj")) {
$artifactName = $artifactName.Substring(0, $artifactName.Length - 5)
}
}
Write-Output "name=$artifactName" >> $env:GITHUB_OUTPUT
# Note: BUILD_COMPONENT envvar tells Component.proj what to build. Only
# used if $project ends up Component.proj.
Write-Output "BUILD_COMPONENT=$component" >> $env:GITHUB_ENV
- name: Setup previous .NET runtimes
uses: actions/setup-dotnet@26b0ec14cb23fa6904739307f278c14f94c95bf1 # v5.4.0
with:
dotnet-version: |
8.0.x
- name: Setup .NET
uses: actions/setup-dotnet@26b0ec14cb23fa6904739307f278c14f94c95bf1 # v5.4.0
- name: dotnet restore ${{ steps.resolve-project.outputs.title }}
run: dotnet restore ${env:PROJECT_PATH} -p:EnablePackageValidation=true
shell: pwsh
env:
PROJECT_PATH: ${{ steps.resolve-project.outputs.project }}
- name: dotnet build ${{ steps.resolve-project.outputs.title }}
run: dotnet build ${env:PROJECT_PATH} --configuration Release --no-restore
shell: pwsh
env:
PROJECT_PATH: ${{ steps.resolve-project.outputs.project }}
- name: dotnet test ${{ steps.resolve-project.outputs.title }}
if: inputs.run-tests && (!inputs.test-require-elevated || matrix.os == 'windows-2025')
shell: pwsh
env:
DISABLE_APP_DOMAIN: ${{ matrix.version == 'net462' && 'false' || 'true' }}
PROJECT_PATH: ${{ steps.resolve-project.outputs.project }}
TARGET_FRAMEWORK: ${{ matrix.version }}
TEST_FILTER: ${{ inputs.test-case-filter }}
run: |
dotnet test ${env:PROJECT_PATH} `
--collect:"Code Coverage" `
--results-directory:TestResults `
--framework ${env:TARGET_FRAMEWORK} `
--configuration Release `
--no-restore `
--no-build `
--logger:"GitHubActions;report-warnings=false" `
--logger:"junit;LogFilePath=${env:GITHUB_WORKSPACE}/TestResults/junit.xml" `
--filter "${env:TEST_FILTER}" `
-- RunConfiguration.DisableAppDomain=${env:DISABLE_APP_DOMAIN}
- name: dotnet test ${{ steps.resolve-project.outputs.title }} (elevated)
if: inputs.run-tests && inputs.test-require-elevated && matrix.os != 'windows-2025'
shell: pwsh
env:
DISABLE_APP_DOMAIN: ${{ matrix.version == 'net462' && 'false' || 'true' }}
PROJECT_PATH: ${{ steps.resolve-project.outputs.project }}
TARGET_FRAMEWORK: ${{ matrix.version }}
TEST_FILTER: ${{ inputs.test-case-filter }}
run: |
sudo -E dotnet test ${env:PROJECT_PATH} `
--collect:"Code Coverage" `
--results-directory:TestResults `
--framework ${env:TARGET_FRAMEWORK} `
--configuration Release `
--no-restore `
--no-build `
--logger:"GitHubActions;report-warnings=false" `
--logger:"junit;LogFilePath=${env:GITHUB_WORKSPACE}/TestResults/junit.xml" `
--filter "${env:TEST_FILTER}" `
-- RunConfiguration.DisableAppDomain=${env:DISABLE_APP_DOMAIN}
sudo chmod a+rw ./TestResults
- name: dotnet pack ${{ steps.resolve-project.outputs.title }}
if: matrix.os == 'windows-2025' && inputs.pack
run: dotnet pack ${env:PROJECT_PATH} --configuration Release --no-restore --no-build -p:EnablePackageValidation=true
shell: pwsh
env:
PROJECT_PATH: ${{ steps.resolve-project.outputs.project }}
SOURCE_DATE_EPOCH: ${{ steps.get-commit-timestamp.outputs.epoch }}
- name: Install dotnet-coverage
if: inputs.run-tests
run: dotnet tool install -g dotnet-coverage
- name: Merge test results
if: inputs.run-tests && hashFiles('./TestResults/**/*.coverage') != ''
run: dotnet-coverage merge -f cobertura -o ./TestResults/Cobertura.xml ./TestResults/**/*.coverage
- name: Upload code coverage ${{ inputs.code-cov-prefix }}-${{ inputs.code-cov-name }}
if: inputs.run-tests && hashFiles('./TestResults/Cobertura.xml') != ''
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
continue-on-error: true # Note: Don't fail for upload failures
timeout-minutes: 5
env:
OS: ${{ matrix.os }}
TFM: ${{ matrix.version }}
FILTER: ${{ inputs.test-case-filter }}
token: ${{ secrets.CODECOV_TOKEN }}
with:
disable_search: true
disable_telem: true
files: TestResults/Cobertura.xml
env_vars: OS,TFM,FILTER
flags: ${{ inputs.code-cov-prefix }}-${{ inputs.code-cov-name }}
name: Code Coverage for ${{ inputs.code-cov-prefix }}-${{ inputs.code-cov-name }} on [${{ matrix.os }}.${{ matrix.version }}]
codecov_yml_path: .github/codecov.yml
- name: Upload test results ${{ inputs.code-cov-prefix }}-${{ inputs.code-cov-name }}
if: ${{ !cancelled() && inputs.run-tests && hashFiles('./TestResults/junit.xml') != '' }}
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
continue-on-error: true # Note: Don't fail for upload failures
timeout-minutes: 5
with:
disable_search: true
disable_telem: true
env_vars: OS,TFM,FILTER
files: TestResults/junit.xml
flags: ${{ inputs.code-cov-prefix }}-${{ inputs.code-cov-name }}
name: Test results for ${{ inputs.code-cov-prefix }}-${{ inputs.code-cov-name }} on [${{ matrix.os }}.${{ matrix.version }}]
report_type: test_results
token: ${{ secrets.CODECOV_TOKEN }}
- name: Publish ${{ steps.resolve-project.outputs.name }} NuGet packages to Artifacts
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
# Only publish packages from the first job, which should be net462 for Windows in most cases, which is preferred for .NET Framework support
if: matrix.os == 'windows-2025' && inputs.pack && strategy.job-index == 0
with:
name: ${{ steps.resolve-project.outputs.name }}-packages
path: ./artifacts/package/release
if-no-files-found: error