forked from microsoft/ntosebpfext
-
Notifications
You must be signed in to change notification settings - Fork 0
229 lines (200 loc) · 9.66 KB
/
reusable-build.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
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
# Copyright (c) Microsoft Corporation
# SPDX-License-Identifier: MIT
# This workflow performs a build of the project and uploads the result as a build artifact.
name: Reusable MSBuild Workflow
on:
workflow_call:
inputs:
ref:
required: true
type: string
# Name associated with the output of this build.
build_artifact:
required: true
type: string
# Additional options passed to msbuild.
build_options:
required: false
type: string
generate_release_package:
required: false
type: boolean
build_codeql:
required: false
type: boolean
build_msi:
required: false
type: boolean
build_nuget:
required: false
type: boolean
cxx_flags:
required: false
type: string
ld_flags:
required: false
type: string
configurations:
required: false
type: string
default: '["Debug", "Release"]'
permissions:
contents: read
security-events: write # Required by codeql task
jobs:
build:
timeout-minutes: 90
strategy:
matrix:
configurations: ${{ fromJSON(inputs.configurations) }}
runs-on: windows-2022
env:
# Path to the solution file relative to the root of the project.
SOLUTION_FILE_PATH: ntosebpfext.sln
BUILD_ARTIFACT_NAME: ${{inputs.build_artifact}}
BUILD_CONFIGURATION: ${{matrix.configurations}}
BUILD_PLATFORM: x64
BUILD_OPTIONS: ${{inputs.build_options}}
CXX_FLAGS: ${{inputs.cxx_flags}}
LD_FLAGS: ${{inputs.ld_flags}}
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
egress-policy: audit
- id: skip_check
uses: fkirc/skip-duplicate-actions@f75f66ce1886f00957d99748a42c724f4330bdcf # v5.3.1
with:
cancel_others: 'false'
paths_ignore: '["**.md", "**/docs/**"]'
- name: Set MSVC Environment Variables
shell: cmd
run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
powershell.exe "echo 'msvc_tools_path=%VCToolsInstallDir%' | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append"
powershell.exe "echo 'msvc_tools_version=%VCToolsVersion%' | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append"
powershell.exe "echo 'ASAN_WIN_CONTINUE_ON_INTERCEPTION_FAILURE=true' | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append"
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
if: steps.skip_check.outputs.should_skip != 'true'
with:
repository: ${{github.repository}}
submodules: 'recursive'
ref: ${{inputs.ref}}
- name: Configure Windows Error Reporting to make a local copy of any crashes that occur.
id: configure_windows_error_reporting
if: steps.skip_check.outputs.should_skip != 'true'
run: |
mkdir c:/dumps/${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}}
New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" -ErrorAction SilentlyContinue
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" -Name "DumpType" -Value 2 -PropertyType DWord -ErrorAction SilentlyContinue
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" -Name "DumpFolder" -Value "c:\dumps\${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}}" -PropertyType ExpandString -ErrorAction SilentlyContinue
- name: Initialize CodeQL
if: inputs.build_codeql == true && steps.skip_check.outputs.should_skip != 'true'
uses: github/codeql-action/init@662472033e021d55d94146f66f6058822b0b39fd
with:
languages: 'cpp'
- name: Add MSBuild to PATH
uses: microsoft/setup-msbuild@6fb02220983dee41ce7ae257b6f4d8f9bf5ed4ce
- name: Setup choco cache folder
# Set the choco cache to a local folder so that it can be cached.
if: steps.skip_check.outputs.should_skip != 'true'
id: choco-cache
run: |
mkdir ${{github.workspace}}\choco_cache
choco config set --name cacheLocation --value ${{github.workspace}}\choco_cache
- name: Cache choco packages
# Add cache entry for any choco packages that are installed.
# The cache key is based on the hash of this file so if any choco packages are added or removed, the cache will be invalidated.
if: steps.skip_check.outputs.should_skip != 'true'
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a
env:
cache-name: cache-choco-packages
with:
path: ${{github.workspace}}\choco_cache
key: ${{ hashFiles('.github/workflows/reusable-build.yml') }}
- name: Install tools
if: steps.skip_check.outputs.should_skip != 'true'
working-directory: ${{env.GITHUB_WORKSPACE}}
run: |
choco install -y llvm --version 11.0.1 --allow-downgrade
echo "C:\Program Files\LLVM\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
where clang.exe
- name: Install .NET 8 SDK
if: steps.skip_check.outputs.should_skip != 'true'
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x
- name: Cache nuget packages
if: steps.skip_check.outputs.should_skip != 'true'
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a
env:
cache-name: cache-nuget-modules
with:
path: packages
key: ${{ runner.os }}-${{env.BUILD_PLATFORM}}-${{env.BUILD_CONFIGURATION}}-${{env.BUILD_ARTIFACT_NAME}}-${{ hashFiles('**/packages.config') }}-${{env.msvc_tools_version}}
- name: Configuring repo for first build
if: steps.skip_check.outputs.should_skip != 'true'
working-directory: ${{env.GITHUB_WORKSPACE}}
env:
CXXFLAGS: /ZH:SHA_256 ${{env.CXX_FLAGS}}
LDFLAGS: ${{env.LD_FLAGS}}
run: |
.\scripts\initialize_repo.ps1
- name: NuGet Restore
if: steps.skip_check.outputs.should_skip != 'true'
working-directory: ${{env.GITHUB_WORKSPACE}}
run: dotnet restore ${{env.SOLUTION_FILE_PATH}} /p:Configuration=${{env.BUILD_CONFIGURATION}} /p:Platform=${{env.BUILD_PLATFORM}}
- name: Build
if: steps.skip_check.outputs.should_skip != 'true'
working-directory: ${{env.GITHUB_WORKSPACE}}
run: msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} /p:Platform=${{env.BUILD_PLATFORM}} /bl:${{env.BUILD_PLATFORM}}_${{env.BUILD_CONFIGURATION}}\build_logs\build.binlog ${{env.BUILD_OPTIONS}} ${{env.SOLUTION_FILE_PATH}}
- name: Zip Build Output
if: always() && (steps.skip_check.outputs.should_skip != 'true')
working-directory: ${{github.workspace}}
run: |
Compress-Archive -Path ${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}} -DestinationPath .\build-${{ matrix.configurations }}.zip
- name: Upload Build Output
if: always() && (steps.skip_check.outputs.should_skip != 'true')
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882
with:
name: ${{inputs.build_artifact}}-${{matrix.configurations}}
path: ${{github.workspace}}/build-${{ matrix.configurations }}.zip
retention-days: 5
- name: Build the NuGet package
if: inputs.build_nuget == true && matrix.configurations == 'Release' && steps.skip_check.outputs.should_skip != 'true'
working-directory: ${{env.GITHUB_WORKSPACE}}
run: msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} /p:Platform=${{env.BUILD_PLATFORM}} /bl:${{env.BUILD_PLATFORM}}_${{env.BUILD_CONFIGURATION}}\build_logs\nuget_build.binlog ${{env.BUILD_OPTIONS}} tools\nuget\nuget.proj /t:Restore,Build,Pack
- name: Upload the NuGet package
if: inputs.build_nuget == true && matrix.configurations == 'Release' && steps.skip_check.outputs.should_skip != 'true'
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882
with:
name: ebpf-for-windows-extensions - NuGet package (${{inputs.build_artifact}}_${{env.BUILD_CONFIGURATION}})
path: ${{github.workspace}}\${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}}\*.nupkg
if-no-files-found: error
retention-days: 5
- name: Upload Build Logs
if: always()
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882
with:
name: ${{inputs.build_artifact}} Build Logs-${{matrix.configurations}}
path: ${{github.workspace}}\${{env.BUILD_PLATFORM}}_${{env.BUILD_CONFIGURATION}}\build_logs\*.binlog
retention-days: 5
- name: Check for crash dumps
# Check for crash dumps even if the workflow failed.
if: (success() || failure()) && (steps.skip_check.outputs.should_skip != 'true')
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6
id: check_dumps
with:
files: c:/dumps/${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}}/*.dmp
- name: Upload any crash dumps
# Upload crash dumps even if the workflow failed.
if: (success() || failure()) && (steps.skip_check.outputs.should_skip != 'true') && (steps.check_dumps.outputs.files_exists == 'true')
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882
id: upload_crash_dumps
with:
name: Crash-Dumps-${{env.NAME}}-${{env.BUILD_PLATFORM}}-${{env.BUILD_CONFIGURATION}}
path: c:/dumps/${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}}
retention-days: 5
- name: Perform CodeQL Analysis
if: inputs.build_codeql == true && steps.skip_check.outputs.should_skip != 'true'
uses: github/codeql-action/analyze@662472033e021d55d94146f66f6058822b0b39fd