forked from osquery/osquery
-
Notifications
You must be signed in to change notification settings - Fork 1
1389 lines (1115 loc) · 47.5 KB
/
hosted_runners.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
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
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#
# Copyright (c) 2014-present, The osquery authors
#
# This source code is licensed as defined by the LICENSE file found in the
# root directory of this source tree.
#
# SPDX-License-Identifier: (Apache-2.0 OR GPL-2.0-only)
#
# Due to a limitation in how GitHub Actions works, we can't reference
# jobs in another file inside the `needs` statement.
#
# This configuration file takes care of the Windows, macOS and Linux
# builds on the x86 platform.
name: build_x86
on:
# Run this workflow once every 6 hours against the master branch
schedule:
- cron: "0 */6 * * *"
push:
branches:
- 'master'
- 'main'
- 'stefano/ci/update-windows-build-tools'
tags:
- '*'
pull_request:
branches:
- '*'
# Cancel old jobs of a PR if a new job is started.
# Fallback on using the run id if it's not a PR, which is unique, so no job canceling.
concurrency:
group: hosted-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: true
# Please remember to update values for both x86 and aarch64 workflows.
env:
PACKAGING_REPO: https://github.com/osquery/osquery-packaging
PACKAGING_COMMIT: c089fb2d3d796d976e3b2fbea7ee69a1616b9576
SUBMODULE_CACHE_VERSION: 3
# If the initial code sanity checks are passing, then one job
# per [`platform` * `build_type`] will start, building osquery
# and generating packages that are later attached to the commit
# (or PR) as build artifacts.
jobs:
# This job performs basic source code check, looking for formatting
# issues and missing copyright headers
check_code_style:
runs-on: ubuntu-20.04
container:
image: osquery/builder20.04:7e9ee0339
options: --user 1001
steps:
- name: Setup the build paths
shell: bash
id: build_paths
run: |
rel_build_path="workspace/build"
rel_source_path="workspace/src"
mkdir -p "${rel_build_path}"
mkdir -p "${rel_source_path}"
echo "SOURCE=$(realpath ${rel_source_path})" >> $GITHUB_OUTPUT
echo "BINARY=$(realpath ${rel_build_path})" >> $GITHUB_OUTPUT
- name: Clone the osquery repository
uses: actions/checkout@v4
with:
path: ${{ steps.build_paths.outputs.SOURCE }}
fetch-depth: 0
# This script makes sure that the copyright headers have been correctly
# placed on all the source code files
- name: Check the copyright headers
working-directory: ${{ steps.build_paths.outputs.SOURCE }}
run: |
./tools/ci/scripts/check_copyright_headers.py
- name: Configure the project
working-directory: ${{ steps.build_paths.outputs.BINARY }}
run: |
cmake -G "Unix Makefiles" \
-DOSQUERY_TOOLCHAIN_SYSROOT:PATH="/usr/local/osquery-toolchain" \
-DOSQUERY_ENABLE_FORMAT_ONLY=ON \
"${{ steps.build_paths.outputs.SOURCE }}"
# Formatting is tested against the clang-format binary we ship
# with the osquery-toolchain, so this job is only performed once on
# a Linux machine.
- name: Check code formatting
working-directory: ${{ steps.build_paths.outputs.BINARY }}
run:
cmake --build . --target format_check
# This jobs checks that the third party libraries manifest has the correct format
# and that is up to date compared to the current state of the repository
check_libraries_manifest:
runs-on: ubuntu-20.04
steps:
- name: Clone the osquery repository
uses: actions/checkout@v4
- name: Install python pre-requisites
run: |
pip3 install -r ./tools/ci/scripts/cve/requirements.txt
- name: Verify the third party libraries manifest
run: |
./tools/ci/scripts/cve/validate_manifest_libraries_versions.py --manifest libraries/third_party_libraries_manifest.json \
--repository .
# Test generating the website json
check_genwebsitejson:
needs: [check_code_style, check_libraries_manifest]
runs-on: ubuntu-20.04
steps:
- name: Clone the osquery repository
uses: actions/checkout@v4
- name: genwebsitejson.py
run: python3 tools/codegen/genwebsitejson.py --specs=specs/
# This job runs source code analysis tools (currently, just cppcheck)
check_source_code:
if: false
needs: [check_code_style, check_libraries_manifest]
runs-on: ${{ matrix.os }}
container:
image: osquery/builder20.04:7e9ee0339
options: --user 1001
strategy:
matrix:
os: [ubuntu-20.04]
steps:
- name: Setup the build paths
shell: bash
id: build_paths
run: |
rel_build_path="workspace/build"
rel_source_path="workspace/src"
rel_install_path="workspace/install"
mkdir -p ${rel_build_path} \
${rel_source_path} \
${rel_install_path}
echo "SOURCE=$(realpath ${rel_source_path})" >> $GITHUB_OUTPUT
echo "BINARY=$(realpath ${rel_build_path})" >> $GITHUB_OUTPUT
echo "REL_BINARY=${rel_build_path}" >> $GITHUB_OUTPUT
- name: Clone the osquery repository
uses: actions/checkout@v4
with:
path: ${{ steps.build_paths.outputs.SOURCE }}
fetch-depth: 0
- name: Update the cache (git submodules)
uses: actions/cache@v3
with:
path: ${{ steps.build_paths.outputs.SOURCE }}/.git/modules
key: |
gitmodules_${{ matrix.os }}_${{env.SUBMODULE_CACHE_VERSION}}_${{ github.sha }}
restore-keys: |
gitmodules_${{ matrix.os }}_${{env.SUBMODULE_CACHE_VERSION}}
- name: Update the git submodules
working-directory: ${{ steps.build_paths.outputs.SOURCE }}
run: |
git submodule sync --recursive
- name: Configure the project (Release)
working-directory: ${{ steps.build_paths.outputs.BINARY }}
run: |
cmake -G "Unix Makefiles" \
-DOSQUERY_TOOLCHAIN_SYSROOT:PATH="/usr/local/osquery-toolchain" \
-DCMAKE_BUILD_TYPE:STRING=Release \
-DOSQUERY_BUILD_TESTS=ON \
-DOSQUERY_BUILD_ROOT_TESTS=ON \
"${{ steps.build_paths.outputs.SOURCE }}"
- name: Initialize the project (Release)
working-directory: ${{ steps.build_paths.outputs.BINARY }}
run: |
cmake --build . --target prepare_for_ide
- name: Run cppcheck (Release)
shell: bash
id: release_cppcheck_runner
working-directory: ${{ steps.build_paths.outputs.BINARY }}
run: |
cmake --build . --target cppcheck 2>&1 | tee cppcheck_release.txt
- name: Store the cppcheck log (Release)
uses: actions/[email protected]
with:
name: cppcheck-release
path: ${{ steps.build_paths.outputs.REL_BINARY }}/cppcheck_release.txt
- name: Configure the project (Debug)
working-directory: ${{ steps.build_paths.outputs.BINARY }}
run: |
cmake -G "Unix Makefiles" \
-DOSQUERY_TOOLCHAIN_SYSROOT:PATH="/usr/local/osquery-toolchain" \
-DCMAKE_BUILD_TYPE:STRING=Debug \
-DOSQUERY_BUILD_TESTS=ON \
-DOSQUERY_BUILD_ROOT_TESTS=ON \
"${{ steps.build_paths.outputs.SOURCE }}"
- name: Initialize the project (Debug)
working-directory: ${{ steps.build_paths.outputs.BINARY }}
run: |
cmake --build . --target prepare_for_ide
- name: Run cppcheck (Debug)
shell: bash
id: debug_cppcheck_runner
working-directory: ${{ steps.build_paths.outputs.BINARY }}
run: |
cmake --build . --target cppcheck 2>&1 | tee cppcheck_debug.txt
- name: Store the cppcheck log (Debug)
uses: actions/[email protected]
with:
name: cppcheck-debug
path: ${{ steps.build_paths.outputs.REL_BINARY }}/cppcheck_debug.txt
# The Linux build will only start once we know that the code
# has been properly formatted
build_linux:
if: false
needs: [check_code_style, check_libraries_manifest]
runs-on: ${{ matrix.os }}
container:
image: osquery/builder20.04:7e9ee0339
options: --privileged --init -v /var/run/docker.sock:/var/run/docker.sock --pid=host --user 1001
strategy:
matrix:
build_type: [Release, RelWithDebInfo, Debug]
os: [ubuntu-20.04]
steps:
- name: Make space uninstalling packages
shell: bash
run: |
run_on_host="sudo nsenter -t 1 -m -u -n -i"
packages_to_remove=$($run_on_host dpkg-query -f '${Package}\n' -W | grep "^clang-.*\|^llvm-.*\|^php.*\|^mono-.*\|^mongodb-.*\
\|^libmono-.*\|^temurin-8-jdk\|^temurin-11-jdk\|^temurin-17-jdk\|^dotnet-.*\|^google-chrome-stable\|^microsoft-edge-stable\|^google-cloud-sdk\|^firefox\|^hhvm\|^snapd")
$run_on_host apt purge $packages_to_remove
# Due to how the RPM packaging tools work, we have to adhere to some
# character count requirements in the build path vs source path.
#
# Failing to do so, will break the debuginfo RPM package.
- name: Setup the build paths
id: build_paths
run: |
rel_build_path="workspace/usr/src/debug/osquery/build"
rel_src_path="workspace/padding-required-by-rpm-packages/src"
rel_ccache_path="workspace/ccache"
rel_package_data_path="workspace/package_data"
rel_packaging_path="workspace/osquery-packaging"
rel_package_build_path="workspace/package-build"
mkdir -p ${rel_build_path} \
${rel_src_path} \
${rel_ccache_path} \
${rel_src_path} \
${rel_package_data_path} \
${rel_package_build_path}
echo "SOURCE=$(realpath ${rel_src_path})" >> $GITHUB_OUTPUT
echo "BINARY=$(realpath ${rel_build_path})" >> $GITHUB_OUTPUT
echo "CCACHE=$(realpath ${rel_ccache_path})" >> $GITHUB_OUTPUT
echo "PACKAGING=$(realpath ${rel_packaging_path})" >> $GITHUB_OUTPUT
echo "PACKAGE_DATA=$(realpath ${rel_package_data_path})" >> $GITHUB_OUTPUT
echo "REL_PACKAGE_BUILD=${rel_package_build_path}" >> $GITHUB_OUTPUT
echo "PACKAGE_BUILD=$(realpath ${rel_package_build_path})" >> $GITHUB_OUTPUT
- name: Clone the osquery repository
uses: actions/checkout@v4
with:
path: ${{ steps.build_paths.outputs.SOURCE }}
fetch-depth: 0
- name: Select the build job count
shell: bash
id: build_job_count
run: |
echo "VALUE=$(($(nproc) + 1))" >> $GITHUB_OUTPUT
- name: Select the build options for the tests
shell: bash
id: tests_build_settings
run: |
if [[ "${{ matrix.build_type }}" == "RelWithDebInfo" ]] ; then
echo "VALUE=OFF" >> $GITHUB_OUTPUT
else
echo "VALUE=ON" >> $GITHUB_OUTPUT
fi
- name: Get runner hardware info
shell: bash
id: runner_stats
run: |
df -h
echo "Cores: $(nproc)"
free -m
# We don't have enough space on the worker to actually generate all
# the debug symbols (osquery + dependencies), so we have a flag to
# disable them when running a Debug build
- name: Select the debug symbols options
shell: bash
id: debug_symbols_settings
run: |
if [[ "${{ matrix.build_type }}" == "Debug" ]] ; then
echo "VALUE=ON" >> $GITHUB_OUTPUT
else
echo "VALUE=OFF" >> $GITHUB_OUTPUT
fi
- name: Clone the osquery-packaging repository
run: |
git clone ${{ env.PACKAGING_REPO }} \
${{ steps.build_paths.outputs.PACKAGING }}
cd ${{ steps.build_paths.outputs.PACKAGING }}
git checkout ${{ env.PACKAGING_COMMIT }}
- name: Update the cache (ccache)
uses: actions/cache@v3
with:
path: ${{ steps.build_paths.outputs.CCACHE }}
key: |
ccache_${{ matrix.os }}_${{ matrix.build_type }}_${{ github.sha }}
restore-keys: |
ccache_${{ matrix.os }}_${{ matrix.build_type }}
- name: Update the cache (git submodules)
uses: actions/cache@v3
with:
path: ${{ steps.build_paths.outputs.SOURCE }}/.git/modules
key: |
gitmodules_${{ matrix.os }}_${{env.SUBMODULE_CACHE_VERSION}}_${{ github.sha }}
restore-keys: |
gitmodules_${{ matrix.os }}_${{env.SUBMODULE_CACHE_VERSION}}
- name: Update the git submodules
working-directory: ${{ steps.build_paths.outputs.SOURCE }}
run: |
git submodule sync --recursive
- name: Configure the project
working-directory: ${{ steps.build_paths.outputs.BINARY }}
env:
CCACHE_DIR: ${{ steps.build_paths.outputs.CCACHE }}
run: |
cmake -G "Unix Makefiles" \
-DOSQUERY_NO_DEBUG_SYMBOLS=${{ steps.debug_symbols_settings.outputs.VALUE }} \
-DOSQUERY_TOOLCHAIN_SYSROOT:PATH="/usr/local/osquery-toolchain" \
-DCMAKE_BUILD_TYPE:STRING="${{ matrix.build_type }}" \
-DOSQUERY_BUILD_TESTS=${{ steps.tests_build_settings.outputs.VALUE }} \
-DOSQUERY_BUILD_ROOT_TESTS=${{ steps.tests_build_settings.outputs.VALUE }} \
"${{ steps.build_paths.outputs.SOURCE }}"
- name: Build the project
working-directory: ${{ steps.build_paths.outputs.BINARY }}
env:
CCACHE_DIR: ${{ steps.build_paths.outputs.CCACHE }}
run: |
cmake --build . -j ${{ steps.build_job_count.outputs.VALUE }}
- name: Disk space information
shell: bash
id: disk_space_info_post_build
run: |
df -h
du -sh ${{ steps.build_paths.outputs.BINARY }}
# Only run the tests on Debug and Release configurations; skip RelWithDebInfo
- name: Run the tests as normal user
working-directory: ${{ steps.build_paths.outputs.BINARY }}
if: matrix.build_type != 'RelWithDebInfo'
run: |
ctest --build-nocmake -LE "root-required" -V
- name: Run the tests as root user
working-directory: ${{ steps.build_paths.outputs.BINARY }}
if: matrix.build_type != 'RelWithDebInfo'
run: |
sudo -u root ctest --build-nocmake -L "root-required" -V
- name: Run the install target
if: matrix.build_type == 'RelWithDebInfo'
working-directory: ${{ steps.build_paths.outputs.BINARY }}
env:
CCACHE_DIR: ${{ steps.build_paths.outputs.CCACHE }}
DESTDIR: ${{ steps.build_paths.outputs.PACKAGE_DATA }}
run: |
cmake \
--build . \
--target install \
-j ${{ steps.build_job_count.outputs.VALUE }}
- name: Create the packages
if: matrix.build_type == 'RelWithDebInfo'
working-directory: ${{ steps.build_paths.outputs.PACKAGE_BUILD }}
shell: bash
run: |
osquery_version=$(cd ${{ steps.build_paths.outputs.SOURCE }} && git describe --tags --always )
tar pcvzf package_data.tar.gz \
${{ steps.build_paths.outputs.PACKAGE_DATA }}
package_format_list=( "DEB" "RPM" "TGZ" )
for package_format in "${package_format_list[@]}" ; do
cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-DCPACK_GENERATOR=${package_format} \
-DOSQUERY_PACKAGE_VERSION=${osquery_version} \
-DOSQUERY_DATA_PATH=${{ steps.build_paths.outputs.PACKAGE_DATA }} \
-DOSQUERY_SOURCE_DIRECTORY_LIST="${{ steps.build_paths.outputs.SOURCE }};${{ steps.build_paths.outputs.BINARY }}" \
${{ steps.build_paths.outputs.PACKAGING }}
cmake --build . \
--target package
done
- name: Locate the packages
if: matrix.build_type == 'RelWithDebInfo'
id: packages
shell: bash
run: |
echo "REL_UNSIGNED_RELEASE_PACKAGE_DATA_PATH=${{ steps.build_paths.outputs.REL_PACKAGE_BUILD }}/package_data.tar.gz" >> $GITHUB_OUTPUT
echo "REL_UNSIGNED_RELEASE_DEB_PATH=$(ls ${{ steps.build_paths.outputs.REL_PACKAGE_BUILD }}/*.deb)" >> $GITHUB_OUTPUT
echo "REL_UNSIGNED_DEBUG_DEB_PATH=$(ls ${{ steps.build_paths.outputs.REL_PACKAGE_BUILD }}/*.ddeb)" >> $GITHUB_OUTPUT
echo "REL_UNSIGNED_RELEASE_RPM_PATH=$(ls ${{ steps.build_paths.outputs.REL_PACKAGE_BUILD }}/osquery-?.*.rpm)" >> $GITHUB_OUTPUT
echo "REL_UNSIGNED_DEBUG_RPM_PATH=$(ls ${{ steps.build_paths.outputs.REL_PACKAGE_BUILD }}/osquery-debuginfo-*.rpm)" >> $GITHUB_OUTPUT
echo "REL_UNSIGNED_RELEASE_TGZ_PATH=$(ls ${{ steps.build_paths.outputs.REL_PACKAGE_BUILD }}/*linux_x86_64.tar.gz)" >> $GITHUB_OUTPUT
- name: Store the unsigned release package data artifact
if: matrix.build_type == 'RelWithDebInfo'
uses: actions/[email protected]
with:
name: linux_unsigned_release_package_data
path: ${{ steps.packages.outputs.REL_UNSIGNED_RELEASE_PACKAGE_DATA_PATH }}
- name: Store the unsigned release DEB artifact
if: matrix.build_type == 'RelWithDebInfo'
uses: actions/[email protected]
with:
name: linux_unsigned_release_deb
path: ${{ steps.packages.outputs.REL_UNSIGNED_RELEASE_DEB_PATH }}
- name: Store the unsigned debug DEB artifact
if: matrix.build_type == 'RelWithDebInfo'
uses: actions/[email protected]
with:
name: linux_unsigned_debug_deb
path: ${{ steps.packages.outputs.REL_UNSIGNED_DEBUG_DEB_PATH }}
- name: Store the unsigned release RPM artifact
if: matrix.build_type == 'RelWithDebInfo'
uses: actions/[email protected]
with:
name: linux_unsigned_release_rpm
path: ${{ steps.packages.outputs.REL_UNSIGNED_RELEASE_RPM_PATH }}
- name: Store the unsigned debug RPM artifact
if: matrix.build_type == 'RelWithDebInfo'
uses: actions/[email protected]
with:
name: linux_unsigned_debug_rpm
path: ${{ steps.packages.outputs.REL_UNSIGNED_DEBUG_RPM_PATH }}
- name: Store the unsigned release TGZ artifact
if: matrix.build_type == 'RelWithDebInfo'
uses: actions/[email protected]
with:
name: linux_unsigned_release_tgz
path: ${{ steps.packages.outputs.REL_UNSIGNED_RELEASE_TGZ_PATH }}
# Before we terminate this job, delete the build folder. The cache
# actions will require the disk space to create the archives.
- name: Reclaim disk space
run: |
rm -rf ${{ steps.build_paths.outputs.BINARY }}
# The macOS build will only start once we know that the code
# has been properly formatted
build_macos:
if: false
needs: [check_code_style, check_libraries_manifest]
runs-on: ${{ matrix.os }}
strategy:
matrix:
build_type: [Release, Debug]
architecture: [x86_64, arm64]
os: [macos-14, macos-15]
steps:
- name: Select the build job count
shell: bash
id: build_job_count
run: |
echo "VALUE=$(($(sysctl -n hw.logicalcpu) + 1))" >> $GITHUB_OUTPUT
- name: Setup the build paths
shell: bash
id: build_paths
run: |
rel_build_path="workspace/build"
rel_src_path="workspace/src"
rel_ccache_path="workspace/ccache"
rel_downloads_path="workspace/downloads"
rel_install_path="workspace/install"
rel_package_data_path="workspace/package_data"
rel_packaging_path="workspace/osquery-packaging"
rel_package_build_path="workspace/package-build"
mkdir -p ${rel_build_path} \
${rel_ccache_path} \
${rel_downloads_path} \
${rel_install_path} \
${rel_package_data_path} \
${rel_package_build_path}
echo "SOURCE=$(pwd)/${rel_src_path}" >> $GITHUB_OUTPUT
echo "REL_SOURCE=${rel_src_path}" >> $GITHUB_OUTPUT
echo "BINARY=$(pwd)/${rel_build_path}" >> $GITHUB_OUTPUT
echo "CCACHE=$(pwd)/${rel_ccache_path}" >> $GITHUB_OUTPUT
echo "DOWNLOADS=$(pwd)/${rel_downloads_path}" >> $GITHUB_OUTPUT
echo "INSTALL=$(pwd)/${rel_install_path}" >> $GITHUB_OUTPUT
echo "PACKAGING=$(pwd)/${rel_packaging_path}" >> $GITHUB_OUTPUT
echo "PACKAGE_DATA=$(pwd)/${rel_package_data_path}" >> $GITHUB_OUTPUT
echo "REL_PACKAGE_BUILD=${rel_package_build_path}" >> $GITHUB_OUTPUT
echo "PACKAGE_BUILD=$(pwd)/${rel_package_build_path}" >> $GITHUB_OUTPUT
- name: Clone the osquery repository
uses: actions/checkout@v2
with:
fetch-depth: 0
path: ${{ steps.build_paths.outputs.REL_SOURCE }}
- name: Get runner hardware info
shell: bash
id: runner_stats
run: |
df -h
echo "Cores: $(sysctl -n hw.logicalcpu)"
vm_stat
- name: Update the cache (ccache)
uses: actions/cache@v3
with:
path: ${{ steps.build_paths.outputs.CCACHE }}
key: |
ccache_${{ matrix.os }}_${{ matrix.architecture }}_${{ matrix.build_type }}_${{ github.sha }}
restore-keys: |
ccache_${{ matrix.os }}_${{ matrix.architecture }}_${{ matrix.build_type }}
- name: Update the cache (git submodules)
uses: actions/cache@v3
with:
path: ${{ steps.build_paths.outputs.SOURCE }}/.git/modules
key: |
gitmodules_${{ matrix.os }}_${{ matrix.architecture }}_${{env.SUBMODULE_CACHE_VERSION}}_${{ github.sha }}
restore-keys: |
gitmodules_${{ matrix.os }}_${{ matrix.architecture }}_${{env.SUBMODULE_CACHE_VERSION}}
- name: Update the cache (downloads)
uses: actions/cache@v3
with:
path: ${{ steps.build_paths.outputs.DOWNLOADS }}
key: |
downloads_${{ matrix.os }}_${{ matrix.architecture }}_${{ github.sha }}
restore-keys: |
downloads_${{ matrix.os }}_${{ matrix.architecture }}
- name: Update the git submodules
working-directory: ${{ steps.build_paths.outputs.SOURCE }}
run: |
git submodule sync --recursive
- name: Install build dependencies
run: |
brew install \
ccache \
flex \
bison \
coreutils \
gnu-sed
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: '3.12.2'
architecture: 'x64'
- name: Install tests dependencies
id: install_test_deps
run: |
pip3 install setuptools \
pexpect==3.3 \
psutil \
timeout_decorator \
six \
thrift==0.11.0 \
osquery
- name: Install CMake
shell: bash
run: |
${{ steps.build_paths.outputs.REL_SOURCE }}/tools/ci/scripts/macos/install_cmake.sh \
"${{ steps.build_paths.outputs.DOWNLOADS }}" \
"${{ steps.build_paths.outputs.INSTALL }}" \
"3.21.4"
- name: Select the Xcode version
shell: bash
id: xcode_selector
run: |
if [[ "${{ matrix.os }}" == "macos-14" ]]; then
xcode_path="/Applications/Xcode_14.3.1.app/Contents/Developer"
elif [[ "${{ matrix.os }}" == "macos-15" ]]; then
xcode_path="/Applications/Xcode_16.app/Contents/Developer"
else
echo "Invalid matrix.os: ${{ matrix.os }}"
exit 1
fi
echo "PATH=${path}" >> $GITHUB_OUTPUT
sudo xcode-select -s "${xcode_path}"
echo "DEPLOYMENT_TARGET=10.15" >> $GITHUB_OUTPUT
# We don't have enough space on the worker to actually generate all
# the debug symbols (osquery + dependencies), so we have a flag to
# disable them when running a Debug build
- name: Select the debug symbols options
shell: bash
id: debug_symbols_settings
run: |
if [[ "${{ matrix.build_type }}" == "Debug" ]] ; then
echo "VALUE=ON" >> $GITHUB_OUTPUT
else
echo "VALUE=OFF" >> $GITHUB_OUTPUT
fi
- name: Configure the project
shell: bash
working-directory: ${{ steps.build_paths.outputs.BINARY }}
env:
CCACHE_DIR: ${{ steps.build_paths.outputs.CCACHE }}
run: |
cmake -G "Unix Makefiles" \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_OSX_ARCHITECTURES="${{ matrix.architecture }}" \
-DCMAKE_OSX_DEPLOYMENT_TARGET="${{ steps.xcode_selector.outputs.DEPLOYMENT_TARGET }}" \
-DCMAKE_BUILD_TYPE:STRING="${{ matrix.build_type }}" \
-DOSQUERY_BUILD_TESTS=ON \
-DOSQUERY_NO_DEBUG_SYMBOLS=${{ steps.debug_symbols_settings.outputs.VALUE }} \
${{ steps.build_paths.outputs.SOURCE }}
- name: Build the project
working-directory: ${{ steps.build_paths.outputs.BINARY }}
env:
CCACHE_DIR: ${{ steps.build_paths.outputs.CCACHE }}
run: |
cmake --build . -j ${{ steps.build_job_count.outputs.VALUE }}
- name: Disk space information
shell: bash
id: disk_space_info_post_build
run: |
df -h
du -sh ${{ steps.build_paths.outputs.BINARY }}
- name: Run the tests
if: matrix.architecture == 'arm64'
working-directory: ${{ steps.build_paths.outputs.BINARY }}
run: |
ctest --build-nocmake -V
- name: Run the install target
working-directory: ${{ steps.build_paths.outputs.BINARY }}
env:
CCACHE_DIR: ${{ steps.build_paths.outputs.CCACHE }}
DESTDIR: ${{ steps.build_paths.outputs.PACKAGE_DATA }}
run: |
cmake \
--build . \
--target install \
-j ${{ steps.build_job_count.outputs.VALUE }}
- name: Create the package data
working-directory: ${{ steps.build_paths.outputs.PACKAGE_BUILD }}
run: |
tar pcvzf package_data.tar.gz \
-C ${{ steps.build_paths.outputs.PACKAGE_DATA }} \
.
- name: Locate the package data
if: matrix.build_type == 'Release'
id: packages
shell: bash
run: |
echo "REL_UNSIGNED_RELEASE_PACKAGE_DATA_PATH=$(ls ${{ steps.build_paths.outputs.REL_PACKAGE_BUILD }}/package_data.tar.gz)" >> $GITHUB_OUTPUT
- name: Store the ${{ matrix.architecture }} unsigned release package data artifact
if: matrix.build_type == 'Release' && matrix.os == 'macos-14'
uses: actions/[email protected]
with:
name: macos_unsigned_release_package_data_${{ matrix.architecture }}
path: ${{ steps.packages.outputs.REL_UNSIGNED_RELEASE_PACKAGE_DATA_PATH }}
- name: Package the tests for the x86_64 macOS-12 worker
if: matrix.architecture == 'x86_64' && matrix.os == 'macos-14'
working-directory: ${{ github.workspace }}/workspace
run: |
mkdir macos_tests_${{ matrix.build_type }}
${{ steps.build_paths.outputs.SOURCE }}/tools/ci/scripts/macos/package_tests.sh build macos_tests_${{ matrix.build_type }}
- name: Store the packaged tests for the x86_64 macOS-12 worker
if: matrix.architecture == 'x86_64' && matrix.os == 'macos-14'
uses: actions/[email protected]
with:
name: macos_tests_${{ matrix.build_type }}
path: workspace/macos_tests_${{ matrix.build_type }}.tar.gz
# Before we terminate this job, delete the build folder. The cache
# actions will require the disk space to create the archives.
- name: Reclaim disk space
run: |
rm -rf ${{ steps.build_paths.outputs.BINARY }}
# This job takes the packaged tests (Release + Debug) from the Sonoma
# builder and runs them on a new Monterey instance
test_macos_monterey:
needs: build_macos
runs-on: macos-12
steps:
- name: Clone the osquery repository
uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/[email protected]
with:
name: macos_tests_Release
- uses: actions/[email protected]
with:
name: macos_tests_Debug
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: '3.12.2'
architecture: 'x64'
- name: Install tests dependencies
id: install_test_deps
run: |
pip3 install setuptools \
pexpect==3.3 \
psutil \
timeout_decorator \
six \
thrift==0.11.0 \
osquery
- name: Install CMake
shell: bash
run: |
mkdir -p "workspace/downloads" \
"workspace/install"
./tools/ci/scripts/macos/install_cmake.sh \
"workspace/downloads" \
"workspace/install" \
"3.21.4"
- name: Extract the tests
run: |
tar xzf macos_tests_Release.tar.gz
tar xzf macos_tests_Debug.tar.gz
- name: Run the Debug tests
run: |
( cd macos_tests_Debug && ./run.sh )
- name: Run the Release tests
run: |
( cd macos_tests_Release && ./run.sh )
# This job builds the universal macOS artifacts
build_universal_macos_artifacts:
needs: test_macos_monterey
runs-on: macos-14
steps:
- name: Clone the osquery repository
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install CMake
shell: bash
run: |
mkdir -p "workspace/downloads" \
"workspace/install"
./tools/ci/scripts/macos/install_cmake.sh \
"workspace/downloads" \
"workspace/install" \
"3.21.4"
- uses: actions/[email protected]
with:
name: macos_unsigned_release_package_data_x86_64
path: macos_unsigned_release_package_data_x86_64
- uses: actions/[email protected]
with:
name: macos_unsigned_release_package_data_arm64
path: macos_unsigned_release_package_data_arm64
- name: Create the universal package data
run: |
tools/ci/scripts/macos/build_universal_package_data.sh
- name: Store the universal unsigned release package data artifact
uses: actions/[email protected]
with:
name: macos_unsigned_release_package_data_universal
path: package_data.tar.gz
- name: Clone the osquery-packaging repository
run: |
git clone ${{ env.PACKAGING_REPO }} osquery-packaging
cd osquery-packaging
git checkout ${{ env.PACKAGING_COMMIT }}
- name: Create the packages
shell: bash
run: |
osquery_version=$(git describe --tags --always )
package_format_list=( "productbuild" "TGZ" )
for package_format in "${package_format_list[@]}" ; do
cmake -DCMAKE_BUILD_TYPE=Release \
-DCPACK_GENERATOR=${package_format} \
-DOSQUERY_PACKAGE_VERSION=${osquery_version} \
-DOSQUERY_DATA_PATH=$(pwd)/universal \
-S osquery-packaging \
-B package_build
cmake --build package_build \
--target package
done
- name: Locate the packages
id: packages
shell: bash
run: |
echo "REL_UNSIGNED_RELEASE_PKG_PATH=$(ls package_build/*.pkg)" >> $GITHUB_OUTPUT
echo "REL_UNSIGNED_RELEASE_TGZ_PATH=$(ls package_build/*.tar.gz)" >> $GITHUB_OUTPUT
- name: Store the PKG unsigned release packages
uses: actions/[email protected]
with:
name: macos_unsigned_pkg_universal
path: ${{ steps.packages.outputs.REL_UNSIGNED_RELEASE_PKG_PATH }}
- name: Store the TGZ unsigned release packages
uses: actions/[email protected]
with:
name: macos_unsigned_tgz_universal
path: ${{ steps.packages.outputs.REL_UNSIGNED_RELEASE_TGZ_PATH }}
# The Windows build will only start once we know that the code
# has been properly formatted
build_windows:
needs: [check_code_style, check_libraries_manifest]
runs-on: ${{ matrix.os }}
strategy:
matrix:
build_type: [Release]
bitness: [64, arm64]
os: [windows-2019]
steps:
- name: Select the build job count
shell: powershell
id: build_job_count
run: |
$cores=(Get-CIMInstance Win32_ComputerSystem).NumberOfLogicalProcessors + 1
echo "VALUE=$cores" >> $env:GITHUB_OUTPUT
- name: Setup the build paths
shell: powershell
id: build_paths
run: |
$rel_src_path = "w\src"
$rel_build_path = "w\build"
$rel_sccache_path = "w\sccache"
$rel_downloads_path = "w\downloads"
$rel_install_path = "w\install"
$rel_package_data_path = "w\package_data"
$rel_packaging_path = "w\osquery-packaging"
New-Item -ItemType Directory -Force -Path $rel_build_path
New-Item -ItemType Directory -Force -Path $rel_sccache_path
New-Item -ItemType Directory -Force -Path $rel_downloads_path
New-Item -ItemType Directory -Force -Path $rel_install_path
New-Item -ItemType Directory -Force -Path $rel_package_data_path
$base_dir = (Get-Item .).FullName
echo "SOURCE=$base_dir\$rel_src_path" >> $env:GITHUB_OUTPUT
echo "REL_SOURCE=$rel_src_path" >> $env:GITHUB_OUTPUT
echo "BINARY=$base_dir\$rel_build_path" >> $env:GITHUB_OUTPUT
echo "SCCACHE=$base_dir\$rel_sccache_path" >> $env:GITHUB_OUTPUT
echo "DOWNLOADS=$base_dir\$rel_downloads_path" >> $env:GITHUB_OUTPUT