-
Notifications
You must be signed in to change notification settings - Fork 32
504 lines (416 loc) · 16.8 KB
/
build-release.yml
File metadata and controls
504 lines (416 loc) · 16.8 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
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
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
name: Build-release
on:
workflow_dispatch:
pull_request:
branches:
- master
push:
branches:
- master
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
CTEST_OUTPUT_ON_FAILURE: 1
CONAN_NON_INTERACTIVE: 1
CONAN_REVISIONS_ENABLED: 1
jobs:
unit-tests:
strategy:
matrix:
os: [ ubuntu-latest ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v6
- name: Create Build Environment
run: cmake -E make_directory ${{github.workspace}}/build
- name: Get Conan
id: conan
uses: turtlebrowser/get-conan@c171f295f3f507360ee018736a6608731aa2109d #v1.2
- name: Setup Conan Cache
uses: actions/cache@v5
with:
path: ${{github.workspace}}/build/p/
key: conan-${{ runner.os }}-${{ hashFiles('conanfile.py', '*/conanfile.py') }}
restore-keys: conan-${{ runner.os }}-
- name: Configure CMake
shell: bash
working-directory: ${{github.workspace}}/build
run: PKG_CONFIG_PATH=${{github.workspace}}/local/lib/pkgconfig cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=./cmake/conan_provider.cmake
- name: Build
working-directory: ${{github.workspace}}/build
shell: bash
run: cmake --build . --config $BUILD_TYPE -- -j 4
- name: Test
working-directory: ${{github.workspace}}/build
shell: bash
run: sudo ctest --output-on-failure
prebuild-package:
needs: [ unit-tests ]
runs-on: ubuntu-latest
outputs:
version_number: ${{ steps.build.outputs.version }}
branch_name: ${{ steps.branch.outputs.name }}
if: github.event_name != 'pull_request'
steps:
- uses: actions/checkout@v6
- name: Remove suffix from Cmakelists.txt file
run: |
ESCAPED_REPLACE_RELEASE=$(printf '%s\n' 'VISOR_PRERELEASE ""' | sed -e 's/[\/&]/\\&/g')
sed -i -e "s/VISOR_PRERELEASE \"-develop\"/$ESCAPED_REPLACE_RELEASE/g" CMakeLists.txt
- name: Create Build Environment
run: cmake -E make_directory ${{github.workspace}}/build
- name: Get Conan
id: conan
uses: turtlebrowser/get-conan@c171f295f3f507360ee018736a6608731aa2109d #v1.2
- name: Configure CMake to generate VERSION
shell: bash
working-directory: ${{github.workspace}}/build
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=./cmake/conan_provider.cmake
- name: Get VERSION
id: build
run: echo "VERSION=`cat ${{github.workspace}}/build/VERSION`" >> $GITHUB_ENV
- name: Get branch name
id: branch
shell: bash
run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_ENV
- name: Persist to workspace
uses: actions/upload-artifact@v7
with:
name: workspace
path: ./
retention-days: 1
release:
needs: [ unit-tests ]
runs-on: ubuntu-latest
# if this is a push into one of our main branches (rather than just a pull request), we will also package
if: github.event_name != 'pull_request'
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Remove suffix from Cmakelists.txt file
run: |
ESCAPED_REPLACE_RELEASE=$(printf '%s\n' 'VISOR_PRERELEASE ""' | sed -e 's/[\/&]/\\&/g')
sed -i -e "s/VISOR_PRERELEASE \"-develop\"/$ESCAPED_REPLACE_RELEASE/g" CMakeLists.txt
- name: Create Build Environment
run: cmake -E make_directory ${{github.workspace}}/build
- name: Get Conan
id: conan
uses: turtlebrowser/get-conan@c171f295f3f507360ee018736a6608731aa2109d #v1.2
- name: Configure CMake to generate VERSION
shell: bash
working-directory: ${{github.workspace}}/build
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=./cmake/conan_provider.cmake
- name: Set variables
run: |
echo "LAST_TAG=`git tag --sort=committerdate | tail -1`" >> $GITHUB_ENV
echo "TAG=v`cat ${{github.workspace}}/build/VERSION`" >> $GITHUB_ENV
echo "VERSION=`cat ${{github.workspace}}/build/VERSION`" >> $GITHUB_ENV
- name: Generate release changelog
run: |
echo "# What's new" > changelog.md
git log ${{ env.LAST_TAG }}..HEAD --pretty=format:"$ad- %s [%an]" >> changelog.md
sed -i -e "s/- /• /g" changelog.md
- name: Post pktvisor changelog in slack channel
run: |
curl -d "text=:mega: *Pktvisor release reporter* :mega:
$(cat changelog.md)" -d "channel=C041B9204CF" -H "Authorization: Bearer ${{secrets.SLACK_APP_TOKEN}}" -X POST https://slack.com/api/chat.postMessage
- name: Create release
id: create_release
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ env.TAG }}
release_name: ${{ env.VERSION }}
body_path: ${{github.workspace}}/changelog.md
draft: false
prerelease: false
build-win64:
runs-on: windows-latest
outputs:
version_number: ${{ env.VERSION }}
steps:
- uses: actions/checkout@v6
- name: Create Build Environment
run: cmake -E make_directory ${{github.workspace}}\build
- name: Get Conan
id: conan
uses: turtlebrowser/get-conan@c171f295f3f507360ee018736a6608731aa2109d #v1.2
- name: Setup Conan Profile
shell: bash
run: |
conan profile detect --force
sed -i 's/compiler.cppstd=14/compiler.cppstd=17/' "$(conan profile path default)"
- name: Setup Conan Cache
uses: actions/cache@v5
with:
path: ${{github.workspace}}/build/p/
key: conan-${{ runner.os }}-${{ hashFiles('conanfile.py', '*/conanfile.py') }}
restore-keys: conan-${{ runner.os }}-
- name: Configure CMake
shell: bash
working-directory: ${{github.workspace}}\build
run: PKG_CONFIG_PATH=${{github.workspace}}\local\lib\pkgconfig cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=./cmake/conan_provider.cmake
- name: Get VERSION
shell: pwsh
id: build
run: |
$text = Get-Content ${{github.workspace}}\build\VERSION -Raw
echo "VERSION=$text" >> $env:GITHUB_ENV
- name: Build
working-directory: ${{github.workspace}}\build
shell: bash
# Execute the build. You can specify a specific target with "--target <NAME>"
run: cmake --build . --config $BUILD_TYPE -- -m
# TODO: Fix unit tests for windows platform
#- name: Test
# working-directory: ${{github.workspace}}/build
# shell: bash
# # Execute tests defined by the CMake configuration.
# # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
# run: ctest -C $BUILD_TYPE
- name: Debug artifacts
shell: pwsh
run: |
Get-ChildItem -Force ${{github.workspace}}
Get-ChildItem -Force ${{github.workspace}}\build
Get-ChildItem -Force ${{github.workspace}}\build\bin
- name: Persist to workspace
uses: actions/upload-artifact@v7
with:
name: windows-build
path: |
${{github.workspace}}\build\bin\pktvisor-reader.exe
${{github.workspace}}\build\bin\pktvisord.exe
${{github.workspace}}\golang\pkg\client\version.go
retention-days: 1
build-cli-win64:
needs: [ build-win64, release ]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Attach to workspace
uses: actions/download-artifact@v8
with:
name: windows-build
- name: Debug artifacts
shell: bash
run: |
ls -lha
- name: Debug artifacts
shell: bash
run: |
mv src pktvisor-src
cp -rpf golang/pkg/client/version.go .
- name: Build pktvisor-cli
uses: ./.github/actions/build-go
with:
context: "."
goos: windows
file: "./Dockerfile"
- name: Debug artifacts
shell: bash
run: |
mv ./pktvisor-cli pktvisor-cli.exe
mv ./build/bin/pktvisord.exe ./pktvisord.exe
mv ./build/bin/pktvisor-reader.exe ./pktvisor-reader.exe
- name: compacting windows binary
run: |
zip pktvisor-win64.zip pktvisor-cli.exe pktvisor-reader.exe pktvisord.exe
- name: Upload win64 binary to latest release
shell: bash
run: |
chmod a+x ./docker/upload-gh-asset.sh
./docker/upload-gh-asset.sh github_api_token=${{ secrets.BOT_TOKEN }} owner=netboxlabs repo=pktvisor tag=LATEST filename=./pktvisor-win64.zip
package-arm64:
needs: [ prebuild-package ]
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
steps:
- name: Attach to workspace
uses: actions/download-artifact@v8
with:
name: workspace
- name: Create Build Environment
run: cmake -E make_directory ${{github.workspace}}/build
- name: Setup Conan Cache
uses: actions/cache@v5
with:
path: ${{github.workspace}}/build/p/
key: conan-${{ runner.os }}-arm64-${{ hashFiles('conanfile.py', '*/conanfile.py') }}
restore-keys: conan-${{ runner.os }}-arm64-
- name: Build pktvisord + push symbol to backtrace.io
uses: ./.github/actions/build-cpp
with:
context: "."
build_type: "Release"
asan: "OFF"
bugsplat_key: ${{secrets.BUGSPLAT_KEY}}
bugsplat_symbol_url: ${{secrets.BUGSPLAT_SYMBOL_URL}}
bugsplat: "false"
file: "./Dockerfile"
- name: Build pktvisor-cli
uses: ./.github/actions/build-go
with:
context: "."
goarch: arm64
file: "./Dockerfile"
- name: Debug artifacts
run: ls -lha .
- name: compacting arm64 binary
run: |
zip pktvisor-arm64.zip pktvisor-cli pktvisor-reader pktvisord
- name: Upload arm64 binary to latest release
run: |
chmod a+x ./docker/upload-gh-asset.sh
./docker/upload-gh-asset.sh github_api_token=${{ secrets.BOT_TOKEN }} owner=netboxlabs repo=pktvisor tag=LATEST filename=./pktvisor-arm64.zip
- name: Get branch name
shell: bash
run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_ENV
- name: Debug branch name
run: echo ${{ env.BRANCH_NAME }}
- name: Get VERSION
run: echo "VERSION=`cat ${{github.workspace}}/build/VERSION`" >> $GITHUB_ENV
- name: Debug version
run: echo ${{ env.VERSION }}
- name: Generate ref tag (master)
if: ${{ env.BRANCH_NAME == 'master' }}
run: |
echo "REF_TAG=latest" >> $GITHUB_ENV
- name: Debug ref tag
run: echo ${{ env.REF_TAG }}
- name: Login to Docker Hub
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 #v4.1.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a #v4.0.0
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd #v4.0.0
- name: Replace token
run: |
sed -i -e "s/CP_TOKEN/${{ secrets.CRASHPAD_TOKEN }}/g" docker/run.sh
- name: Replace escape url
run: |
REPLACE=${{ secrets.BUGSPLAT_CP_URL }}
ESCAPED_REPLACE=$(printf '%s\n' "$REPLACE" | sed -e 's/[\/&]/\\&/g')
sed -i -e "s/CP_URL/$ESCAPED_REPLACE/g" docker/run.sh
- name: Build + push - pktvisor (multi-arch)
id: docker_build
env:
IMAGE_NAME: netboxlabs/pktvisor
uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f #v7.1.0
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./docker/Dockerfile.crashhandler
platforms: linux/arm64
tags: ${{ env.IMAGE_NAME }}:latest, ${{ env.IMAGE_NAME }}:${{ env.VERSION }}
outputs: type=docker,dest=/tmp/arm64.tar
- name: Load image
env:
IMAGE_NAME: netboxlabs/pktvisor
run: |
docker load --input /tmp/arm64.tar
docker image ls -a
docker push ${{ env.IMAGE_NAME }}:latest
docker push ${{ env.IMAGE_NAME }}:${{ env.VERSION }}
package-amd64:
needs: [ prebuild-package ]
runs-on: ubuntu-latest
outputs:
release_version: ${{ env.VERSION }}
if: github.event_name != 'pull_request'
steps:
- name: Attach to workspace
uses: actions/download-artifact@v8
with:
name: workspace
- name: Create Build Environment
run: cmake -E make_directory ${{github.workspace}}/build
- name: Setup Conan Cache
uses: actions/cache@v5
with:
path: ${{github.workspace}}/build/p/
key: conan-${{ runner.os }}-${{ hashFiles('conanfile.py', '*/conanfile.py') }}
restore-keys: conan-${{ runner.os }}-
- name: Build pktvisord + push symbol to backtrace.io
uses: ./.github/actions/build-cpp
with:
context: "."
build_type: "Release"
asan: "OFF"
bugsplat_key: ${{secrets.BUGSPLAT_KEY}}
bugsplat_symbol_url: ${{secrets.BUGSPLAT_SYMBOL_URL}}
bugsplat: "true"
file: "./Dockerfile"
- name: Build pktvisor-cli
uses: ./.github/actions/build-go
with:
context: "."
file: "./Dockerfile"
- name: Debug artifacts
run: ls -lha .
- name: compacting amd64 binary
run: |
zip pktvisor-amd64.zip pktvisor-cli pktvisor-reader pktvisord
- name: Upload amd64 binary to latest release
run: |
chmod a+x ./docker/upload-gh-asset.sh
./docker/upload-gh-asset.sh github_api_token=${{ secrets.BOT_TOKEN }} owner=netboxlabs repo=pktvisor tag=LATEST filename=./pktvisor-amd64.zip
- name: Get branch name
shell: bash
run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_ENV
- name: Debug branch name
run: echo ${{ env.BRANCH_NAME }}
- name: Get VERSION
run: echo "VERSION=`cat ${{github.workspace}}/build/VERSION`" >> $GITHUB_ENV
- name: Debug version
run: echo ${{ env.VERSION }}
- name: Generate ref tag (master)
if: ${{ env.BRANCH_NAME == 'master' }}
run: echo "REF_TAG=latest" >> $GITHUB_ENV
- name: Debug ref tag
run: echo ${{ env.REF_TAG }}
- name: Login to Docker Hub
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 #v4.1.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd #v4.0.0
- name: Set up QEMU
uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a #v4.0.0
- name: Replace token
run: |
sed -i -e "s/CP_TOKEN/${{ secrets.CRASHPAD_TOKEN }}/g" docker/run.sh
- name: Replace escape url
run: |
REPLACE=${{ secrets.BUGSPLAT_CP_URL }}
ESCAPED_REPLACE=$(printf '%s\n' "$REPLACE" | sed -e 's/[\/&]/\\&/g')
sed -i -e "s/CP_URL/$ESCAPED_REPLACE/g" docker/run.sh
- name: Build + push - pktvisor (multi-arch)
env:
IMAGE_NAME: netboxlabs/pktvisor
uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f #v7.1.0
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./docker/Dockerfile.crashhandler
platforms: linux/amd64
tags: ${{ env.IMAGE_NAME }}:latest, ${{ env.IMAGE_NAME }}:${{ env.VERSION }}
outputs: type=docker,dest=/tmp/amd64.tar
- name: Load image
env:
IMAGE_NAME: netboxlabs/pktvisor
run: |
docker load --input /tmp/amd64.tar
docker image ls -a
docker push ${{ env.IMAGE_NAME }}:latest
docker push ${{ env.IMAGE_NAME }}:${{ env.VERSION }}