-
Notifications
You must be signed in to change notification settings - Fork 5
413 lines (337 loc) · 15.2 KB
/
main.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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
name: CI pipeline
on: push
jobs:
debug_ubuntu_22:
runs-on: ubuntu-22.04
strategy:
matrix:
zeek: [{version: 6.0.2-0, tag: -lts}]
env:
ZEEK_VERSION: ${{ matrix.zeek.version }}
ZEEK_TAG: ${{ matrix.zeek.tag }}
ZEEK_AGENT_CONFIGURE_ADDL: ${{ matrix.configure }}
LD_LIBRARY_PATH: /usr/lib/llvm-17/lib/clang/17/lib/linux
steps:
- name: Prepare
run: |
export DEBIAN_FRONTEND=noninteractive
sudo apt-get update
sudo apt-get install -y ninja-build ccache curl ca-certificates
sudo pip3 install btest zkg pre-commit
# LLVM toolchain
echo 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main' | sudo tee -a /etc/apt/sources.list.d/llvm17.list
echo 'deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main' | sudo tee -a /etc/apt/sources.list.d/llvm17.list
sudo curl https://apt.llvm.org/llvm-snapshot.gpg.key -o /etc/apt/trusted.gpg.d/llvm.asc
sudo apt-get update
sudo apt-get install -y llvm-17-dev clang-17 libclang-17-dev clang-format-17 clang-tidy-17 libclang-rt-17-dev
# for bpftool
sudo ln -s $(which llvm-strip-17) /usr/local/bin/llvm-strip
sudo apt-get install libelf-dev gcc-multilib
- name: Install Zeek
run: |
(cd /tmp && curl -L -O https://download.zeek.org/binary-packages/xUbuntu_22.04/amd64/zeek${ZEEK_TAG}-core_${ZEEK_VERSION}_amd64.deb)
sudo apt install -y /tmp/zeek${ZEEK_TAG}-core_${ZEEK_VERSION}_amd64.deb
echo "/opt/zeek/bin:$PATH" >> $GITHUB_PATH
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up ccache
uses: hendrikmuhs/ccache-action@v1.2
with:
key: ${{ github.job }}
- name: Build
run: |
./configure --prefix=/tmp/zeek-agent --enable-debug --enable-sanitizer --enable-ccache --enable-werror --generator=Ninja $ZEEK_AGENT_CONFIGURE_ADDL
ninja -C build
- name: Test
run: |
make test
- name: Check code
run: |
pre-commit run -a --show-diff-on-failure
# TODO: tidy fails in Broker currently
# ninja -C build tidy
- uses: actions/upload-artifact@v4
if: failure()
with:
name: Test output
path: |
tests/.tmp
zeek-agent/tests/.tmp
# TODO: Install Zeek and run Zeek tests.
release_alpine_3_19_static:
runs-on: ubuntu-22.04
environment: ${{ (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/topic/ci-release-test' || startsWith(github.ref, 'refs/tags/v')) && 'release' || '' }}
container:
image: alpine:3.19
steps:
- name: Prepare
run: |
apk update
apk add linux-headers ccache cmake g++ gcc git make ninja tar zlib-static zlib-dev openssl-libs-static openssl-dev zstd-static python3 py3-pip bash
pip3 install --break-system-packages btest zkg
# for bpftool
apk add clang llvm libelf elfutils-dev
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up ccache
uses: hendrikmuhs/ccache-action@v1.2
with:
key: ${{ github.job }}
- name: Build
run: |
./configure --prefix=/tmp/zeek-agent --enable-ccache --enable-werror --enable-static --generator=Ninja --with-openssl=
ninja -C build
- name: Test
run: |
ldd build/bin/zeek-agent 2>&1 | grep -q "Not a valid dynamic program"
make -C tests test-no-zeek
- name: Install
run: |
ninja -C build install
find /tmp/zeek-agent -exec ls -ald '{}' ';'
- name: Package
run: |
ninja -C build package
(cd build/dist && echo "ZA_DIST=$(echo *.tar.gz)" >>$GITHUB_ENV)
- uses: actions/upload-artifact@v4
with:
name: ${{env.ZA_DIST}}
path: build/dist/${{env.ZA_DIST}}
# TODO: Install Zeek and run Zeek tests.
release_macos_13:
env:
MACOS_VERSION: 13.0
runs-on: macos-13
environment: ${{ (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/topic/ci-release-test' || startsWith(github.ref, 'refs/tags/v')) && 'release' || '' }}
steps:
- name: Prepare
run: |
brew update
brew upgrade cmake
brew install ninja ccache
pip3 install btest zkg
# time can be off, which confuses codesigning; this host can be accessed from GH actions
sudo sntp -sS time.windows.com
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up ccache
uses: hendrikmuhs/ccache-action@v1.2
with:
key: ${{ github.job }}
- name: Build universal arch OpenSSL
env:
OPENSSL_VERSION: 1.1.1w
run: |
curl -O https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz
tar xvzf openssl-${OPENSSL_VERSION}.tar.gz && mv openssl-${OPENSSL_VERSION} openssl_x86_64
tar xvzf openssl-${OPENSSL_VERSION}.tar.gz && mv openssl-${OPENSSL_VERSION} openssl_arm64
(cd openssl_x86_64 && CC="ccache cc" ./Configure darwin64-x86_64-cc no-shared no-tests -mmacosx-version-min=${MACOS_VERSION} && make -j)
(cd openssl_arm64 && CC="ccache cc" ./Configure darwin64-arm64-cc no-shared no-tests -mmacosx-version-min=${MACOS_VERSION} && make -j)
mkdir -p /tmp/openssl/lib /tmp/openssl/include
lipo -create openssl_arm64/libcrypto.a openssl_x86_64/libcrypto.a -output /tmp/openssl/lib/libcrypto.a
lipo -create openssl_arm64/libssl.a openssl_x86_64/libssl.a -output /tmp/openssl/lib/libssl.a
cp -r openssl_x86_64/include/openssl /tmp/openssl/include/
rm -rf openssl-${OPENSSL_VERSION}*
- name: Build
run: |
./configure --prefix=${{runner.temp}}/zeek-agent --enable-ccache --enable-werror --enable-osx-universal --generator=Ninja --with-openssl=/tmp/openssl --osx-deployment-target=${MACOS_VERSION}
ninja -C build
- name: Test
run: |
file build/bin/zeek-agent | grep -q "universal binary with 2 architectures"
make -C tests test-no-zeek || true
- name: Install
run: |
ninja -C build install
find ${{runner.temp}}/zeek-agent -exec ls -ald '{}' ';'
### Only on topic branches
- name: Package (without codesign)
if: github.ref_name != 'main' && github.ref != 'refs/heads/topic/ci-release-test' && !startsWith(github.ref, 'refs/tags/v')
run: |
ninja -C build package
(cd build/dist && echo "ZA_DIST=$(echo *.dmg)" >>$GITHUB_ENV)
### Only on the main branch
- name: Set up keychain for code signing
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/topic/ci-release-test' || startsWith(github.ref, 'refs/tags/v')
env:
MACOS_APP_STORE_CONNECT_ISSUER_ID: ${{ secrets.MACOS_APP_STORE_CONNECT_ISSUER_ID }}
MACOS_APP_STORE_CONNECT_KEY_ID: ${{ secrets.MACOS_APP_STORE_CONNECT_KEY_ID }}
MACOS_APP_STORE_CONNECT_KEY_P8: ${{ secrets.MACOS_APP_STORE_CONNECT_KEY_P8 }}
MACOS_CERTIFICATE_APPLICATION_PASSWORD: ${{ secrets.MACOS_CERTIFICATE_APPLICATION_PASSWORD }}
MACOS_CERTIFICATE_APPLICATION_PEM: ${{ secrets.MACOS_CERTIFICATE_APPLICATION_PEM }}
MACOS_KEYCHAIN_PASSWORD: ${{ secrets.MACOS_KEYCHAIN_PASSWORD }}
run: |
echo -n "${MACOS_CERTIFICATE_APPLICATION_PEM}" >"${RUNNER_TEMP}/cert.pem"
security create-keychain -p "${MACOS_KEYCHAIN_PASSWORD}" "${RUNNER_TEMP}/keychain-db"
security set-keychain-settings -lut 100 "${RUNNER_TEMP}/keychain-db"
security default-keychain -s "${RUNNER_TEMP}/keychain-db"
security unlock-keychain -p "${MACOS_KEYCHAIN_PASSWORD}" "${RUNNER_TEMP}/keychain-db"
security import "${RUNNER_TEMP}/cert.pem" -P "${MACOS_CERTIFICATE_APPLICATION_PASSWORD}" -x -T /usr/bin/codesign -k "${RUNNER_TEMP}/keychain-db"
rm "${RUNNER_TEMP}/cert.pem"
echo -n "${MACOS_APP_STORE_CONNECT_KEY_P8}" >"${RUNNER_TEMP}/key.p8"
xcrun notarytool store-credentials -k "${RUNNER_TEMP}/key.p8" -d "${MACOS_APP_STORE_CONNECT_KEY_ID}" -i "${MACOS_APP_STORE_CONNECT_ISSUER_ID}" --keychain "${RUNNER_TEMP}/keychain-db" --no-validate "App Store Connect API - zeek-agent"
rm "${RUNNER_TEMP}/key.p8"
# must come last
security set-key-partition-list -S apple-tool:,apple: -s -k "${MACOS_KEYCHAIN_PASSWORD}" "${RUNNER_TEMP}/keychain-db"
- name: Package (with codesign)
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/topic/ci-release-test' || startsWith(github.ref, 'refs/tags/v')
env:
MACOS_NOTARIZE: 1
MACOS_CERTIFICATE_APPLICATION_ID: ${{ secrets.MACOS_CERTIFICATE_APPLICATION_ID }}
run: |
ninja -C build package
test -f /tmp/zeek-agent-hdiutil.log && cat /tmp/zeek-agent-hdiutil.log
(cd build/dist && echo "ZA_DIST=$(echo *.dmg)" >>$GITHUB_ENV)
- name: Clean up keychain
if: always() && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/topic/ci-release-test' || startsWith(github.ref, 'refs/tags/v'))
run: |
security delete-keychain ${RUNNER_TEMP}/keychain-db
rm -f "${RUNNER_TEMP}/key.p8" "${RUNNER_TEMP}/cert.p8"
### Back to running on all branches
- uses: actions/upload-artifact@v4
with:
name: ${{env.ZA_DIST}}
path: build/dist/${{env.ZA_DIST}}
release_windows_2022:
runs-on: windows-2022
env:
VCPKG_ROOT: ${{ github.workspace }}/3rdparty/vcpkg
VCPKG_DEFAULT_BINARY_CACHE: ${{ github.workspace }}/3rdparty/vcpkg/bincache
VCPKG_TARGET_TRIPLET: x64-windows-static
# Something in the Windows build configuration breaks ccache and causes it to forget
# what its configuration is by the time we call configure and run the build. This
# forces it to remember.
CCACHE_CONFIGPATH: ~/ccache/ccache.conf
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
- name: Create vcpkg binary cache directory
run: mkdir -p $VCPKG_DEFAULT_BINARY_CACHE
shell: bash
# The github runner provides a version of ccache, but it's too old to
# properly support use with cl.exe. We need at least version 4.6 for
# everything to work right. The ccache-action below should be doing
# if but it's still picking up the wrong version of ccache.
- name: Install newer ccache
run: >
choco install ccache
shell: cmd
- name: Set up ccache
uses: hendrikmuhs/ccache-action@v1.2
with:
key: ${{ github.job }}
- name: Set up Visual Studio shell
uses: egor-tensin/vs-shell@v2
with:
arch: x64
- name: Cache vcpkg output
uses: actions/cache@v4
with:
path: |
${{ env.VCPKG_ROOT }}
!${{ env.VCPKG_ROOT }}/buildtrees
!${{ env.VCPKG_ROOT }}/packages
!${{ env.VCPKG_ROOT }}/downloads
!${{ env.VCPKG_ROOT }}/installed
key: |
${{ hashFiles( 'vcpkg.json' ) }}-${{ hashFiles( '.git/modules/vcpkg/HEAD' )}}-${{ env.VCPKG_TARGET_TRIPLET }}
- name: Configure
run: >
cmake -S . -B build -G Ninja -DCMAKE_C_COMPILER=cl.exe -DCMAKE_CXX_COMPILER=cl.exe -DCMAKE_MAKE_PROGRAM=ninja.exe -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE=ON -DUSE_CCACHE=yes -DCMAKE_TOOLCHAIN_FILE="3rdparty/vcpkg/scripts/buildsystems/vcpkg.cmake" -DVCPKG_TARGET_TRIPLET=${{env.VCPKG_TARGET_TRIPLET}}
shell: cmd
- name: Build
run: >
cmake --build build --target install --config Release --parallel 2
shell: cmd
### We can't run btest here for a number of reasons. See
### https://github.com/zeek/btest/issues/26. This also means
### there's no artifacts to upload upon failure.
- name: Test
run: >
"C:\Program Files (x86)\ZeekAgent\bin\zeek-agent.exe" -T
shell: cmd
- name: Build installer
run: |
cmake --build build --target package --config Release
(cd build/dist && echo "ZA_DIST=$(echo *.msi)" >>$GITHUB_ENV)
shell: bash
- uses: actions/upload-artifact@v4
with:
name: ${{env.ZA_DIST}}
path: build/dist/${{env.ZA_DIST}}
release_source:
runs-on: ubuntu-22.04
environment: ${{ (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/topic/ci-release-test' || startsWith(github.ref, 'refs/tags/v')) && 'release' || '' }}
steps:
- name: Prepare
run: |
export DEBIAN_FRONTEND=noninteractive
sudo apt-get update
sudo apt-get install -y ninja-build ccache curl ca-certificates
# for bpftool
sudo apt-get install llvm libelf-dev gcc-multilib
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up ccache
uses: hendrikmuhs/ccache-action@v1.2
with:
key: ${{ github.job }}
- name: Configure
run: |
./configure --generator=Ninja
- name: Package source code
run: |
ninja -C build package_source
(cd build/dist && echo "ZA_DIST=$(echo *.tar.gz)" >>$GITHUB_ENV)
- name: Test build of source code
run: |
mkdir -p ${{ runner.temp }}/test-build
cat build/dist/${{env.ZA_DIST}} | (cd ${{ runner.temp }}/test-build && tar xzvf -)
(cd $(echo ${{ runner.temp }}/test-build/zeek-agent*) && ./configure --generator=Ninja --enable-ccache && ninja -C build && ninja -C build test)
- uses: actions/upload-artifact@v4
with:
name: ${{env.ZA_DIST}}
path: build/dist/${{env.ZA_DIST}}
publish_release:
permissions:
contents: write
runs-on: ubuntu-22.04
if: (startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, '-dev'))
needs: [debug_ubuntu_22, release_alpine_3_19_static, release_macos_13, release_windows_2022, release_source]
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive
- name: Prepare release message
run: |
cat CHANGES | awk '/^[0-9]+\./{ n++; next; } n < 2 { print }' >${{ runner.temp }}/release-msg
echo "release_name=$(echo ${{ github.ref_name }} | sed 's/^v//')" >> $GITHUB_ENV
- uses: actions/download-artifact@v4
with:
path: artifacts
- name: Display artifacts
run: ls -al artifacts/*/*
- name: Upload artifacts
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
draft: false
prerelease: false
name: ${{ env.release_name }}
body_path: ${{ runner.temp }}/release-msg
files: |
artifacts/*/*.tar.gz
artifacts/*/*.dmg
artifacts/*/*.msi