-
Notifications
You must be signed in to change notification settings - Fork 293
142 lines (123 loc) · 4.95 KB
/
Component.BuildTest.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
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-latest", "ubuntu-22.04" ]'
required: false
type: string
tfm-list:
default: '[ "net462", "net8.0", "net9.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
jobs:
build-test:
strategy:
fail-fast: false # ensures the entire test matrix is run, even if one permutation fails
matrix:
os: ${{ fromJSON(inputs.os-list) }}
version: ${{ fromJSON(inputs.tfm-list) }}
exclude:
- os: ubuntu-22.04
version: net462
- os: macos-latest
version: net462
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
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
- name: Resolve project
id: resolve-project
shell: pwsh
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 '${{ inputs.project-name }}' `
-title ([ref]$title) `
-project ([ref]$project) `
-component ([ref]$component)
echo "title=$title" >> $env:GITHUB_OUTPUT
echo "project=$project" >> $env:GITHUB_OUTPUT
# Note: BUILD_COMPONENT envvar tells Component.proj what to build. Only
# used if $project ends up Component.proj.
echo "BUILD_COMPONENT=$component" >> $env:GITHUB_ENV
- name: Setup dotnet
uses: actions/setup-dotnet@v4
- name: dotnet restore ${{ steps.resolve-project.outputs.title }}
run: dotnet restore ${{ steps.resolve-project.outputs.project }} -p:EnablePackageValidation=true
- name: dotnet build ${{ steps.resolve-project.outputs.title }}
run: dotnet build ${{ steps.resolve-project.outputs.project }} --configuration Release --no-restore
- name: dotnet test ${{ steps.resolve-project.outputs.title }}
if: ${{ inputs.run-tests }}
run: >
${{ inputs.test-require-elevated && matrix.os != 'windows-latest' && 'sudo -E' || '' }}
dotnet test ${{ steps.resolve-project.outputs.project }}
--collect:"Code Coverage"
--results-directory:TestResults
--framework ${{ matrix.version }}
--configuration Release
--no-restore
--no-build
--logger:"console;verbosity=detailed"
--filter "${{ inputs.test-case-filter }}"
-- RunConfiguration.DisableAppDomain=true
${{ inputs.test-require-elevated && matrix.os != 'windows-latest' && '&& sudo chmod a+rw ./TestResults' || '' }}
- name: dotnet pack ${{ steps.resolve-project.outputs.title }}
if: ${{ matrix.os == 'windows-latest' && inputs.pack }}
run: dotnet pack ${{ steps.resolve-project.outputs.project }} --configuration Release --no-restore --no-build -p:EnablePackageValidation=true
- name: Install coverage tool
if: ${{ inputs.run-tests }}
run: dotnet tool install -g dotnet-coverage
- name: Merging 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@v5
continue-on-error: true # Note: Don't fail for upload failures
env:
OS: ${{ matrix.os }}
TFM: ${{ matrix.version }}
FILTER: ${{ inputs.test-case-filter }}
token: ${{ secrets.CODECOV_TOKEN }}
with:
file: 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