-
Notifications
You must be signed in to change notification settings - Fork 5
2782 lines (2751 loc) · 127 KB
/
reusable-build-test-release.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
name: build-test-release
on:
workflow_call:
inputs:
marker:
required: false
description: 'Parallel run marker'
type: string
default: >-
[""]
secrets:
GH_TOKEN_ADMIN:
description: Github admin token
required: true
SEMGREP_PUBLISH_TOKEN:
description: Semgrep token
required: true
AWS_ACCESS_KEY_ID:
description: AWS access key id
required: true
AWS_DEFAULT_REGION:
description: AWS default region
required: true
AWS_SECRET_ACCESS_KEY:
description: AWS secret access key
required: true
VT_API_KEY:
description: Virustotal api key
required: true
OTHER_TA_REQUIRED_CONFIGS:
description: other required configs
required: true
FOSSA_API_KEY:
description: API token for FOSSA app
required: true
SA_GH_USER_NAME:
description: GPG signature username
required: true
SA_GH_USER_EMAIL:
description: GPG signature user email
required: true
SA_GPG_PRIVATE_KEY:
description: GPG signature private key
required: true
SA_GPG_PASSPHRASE:
description: GPG signature passphrase
required: true
SPL_COM_USER:
description: username to splunk.com
required: true
SPL_COM_PASSWORD:
description: password to splunk.com
required: true
permissions:
contents: read
packages: read
concurrency:
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
setup-workflow:
runs-on: ubuntu-latest
outputs:
skip-workflow: ${{ steps.skip-workflow.outputs.skip-workflow }}
delay-destroy-ko: ${{ steps.delay-destroy-setup.outputs.delay-destroy-ko }}
delay-destroy-ui: ${{ steps.delay-destroy-setup.outputs.delay-destroy-ui }}
delay-destroy-modinput_functional: ${{ steps.delay-destroy-setup.outputs.delay-destroy-modinput_functional }}
delay-destroy-escu: ${{ steps.delay-destroy-setup.outputs.delay-destroy-escu }}
delay-destroy-scripted_inputs: ${{ steps.delay-destroy-setup.outputs.delay-destroy-scripted_inputs }}
delay-destroy-requirement_test: ${{ steps.delay-destroy-setup.outputs.delay-destroy-requirement_test }}
execute-ko: ${{ steps.delay-destroy-setup.outputs.execute-ko }}
execute-ui: ${{ steps.delay-destroy-setup.outputs.execute-ui }}
execute-escu: ${{ steps.delay-destroy-setup.outputs.execute-escu }}
execute-modinput_functional: ${{ steps.delay-destroy-setup.outputs.execute-modinput_functional }}
execute-scripted_inputs: ${{ steps.delay-destroy-setup.outputs.execute-scripted_inputs }}
execute-requirement_test: ${{ steps.delay-destroy-setup.outputs.execute-requirement_test }}
execute-knowledge-labeled: ${{ steps.configure-tests-on-labels.outputs.execute_knowledge_labeled }}
execute-ui-labeled: ${{ steps.configure-tests-on-labels.outputs.execute_ui_labeled }}
execute-escu-labeled: ${{ steps.configure-tests-on-labels.outputs.execute_escu_labeled }}
execute-modinput-labeled: ${{ steps.configure-tests-on-labels.outputs.execute_modinput_functional_labeled }}
execute-scripted_inputs-labeled: ${{ steps.configure-tests-on-labels.outputs.execute_scripted_inputs_labeled }}
execute-requirement-labeled: ${{ steps.configure-tests-on-labels.outputs.execute_requirement_test_labeled }}
steps:
- name: skip workflow if description is empty for labeled pr
id: skip-workflow
env:
PR_BODY: ${{ github.event.pull_request.body }}
run: |
set +e
TESTSET="knowledge ui modinput_functional scripted_inputs escu requirement_test"
echo "testset=$TESTSET" >> "$GITHUB_OUTPUT"
SKIP_WORKFLOW="No"
if [[ '${{ github.event.action }}' == 'labeled' && '${{ github.event.label.name }}' == 'preserve_infra' ]]; then
echo "$PR_BODY" >> body.txt
SKIP_WORKFLOW="Yes"
tests=$(grep -i "^preserve:" body.txt | { grep -v grep || true; })
for test_type in $TESTSET; do
if [[ $tests =~ $test_type ]]; then
SKIP_WORKFLOW="No"
fi
done
fi
echo "skip-workflow=$SKIP_WORKFLOW" >> "$GITHUB_OUTPUT"
if [ "$SKIP_WORKFLOW" == "Yes" ]; then
echo "No description is provided with preserve infra label"
fi
- name: setup for delay destroy
id: delay-destroy-setup
shell: bash
env:
PR_BODY: ${{ github.event.pull_request.body }}
run: |
set +e
TESTSET="${{ steps.skip-workflow.outputs.testset }}"
for test_type in $TESTSET; do
eval DELAY_DESTROY_$test_type="No"
eval EXECUTE_$test_type="No"
done
if [[ '${{ github.event.label.name }}' == 'preserve_infra' ]]; then
echo "$PR_BODY" >> body.txt
tests=$(grep -i "^preserve:" body.txt | { grep -v grep || true; })
if [[ $tests =~ "escu" ]]; then
echo "preserve_infra for escu test-type is not supported yet"
fi
for test_type in $TESTSET; do
if [[ $tests =~ $test_type ]]; then
eval EXECUTE_$test_type="Yes"
eval DELAY_DESTROY_$test_type="Yes"
fi
done
fi
# PRESERVE_INFRA for escu test-type is not supported yet.
DELAY_DESTROY_escu="No"
{
echo "delay-destroy-ko=$DELAY_DESTROY_knowledge"
echo "delay-destroy-ui=$DELAY_DESTROY_ui"
echo "delay-destroy-modinput_functional=$DELAY_DESTROY_modinput_functional"
echo "delay-destroy-scripted_inputs=$DELAY_DESTROY_scripted_inputs"
echo "delay-destroy-escu=$DELAY_DESTROY_escu"
echo "delay-destroy-requirement_test=$DELAY_DESTROY_requirement_test"
echo "execute-ko=$EXECUTE_knowledge"
echo "execute-ui=$EXECUTE_ui"
echo "execute-modinput_functional=$EXECUTE_modinput_functional"
echo "execute-scripted_inputs=$EXECUTE_scripted_inputs"
echo "execute-escu=$EXECUTE_escu"
echo "execute-requirement_test=$EXECUTE_requirement_test"
} >> "$GITHUB_OUTPUT"
- name: configure tests based on labels
id: configure-tests-on-labels
run: |
set +e
declare -A EXECUTE_LABELED
TESTSET=("execute_knowledge" "execute_ui" "execute_modinput_functional" "execute_scripted_inputs" "execute_escu" "execute_requirement_test")
for test_type in "${TESTSET[@]}"; do
EXECUTE_LABELED["$test_type"]="false"
done
case "${{ github.event_name }}" in
"pull_request")
if ${{ github.base_ref == 'main' }} || ${{ contains(github.event.pull_request.labels.*.name, 'execute_all_tests') }}; then
for test_type in "${TESTSET[@]}"; do
EXECUTE_LABELED["$test_type"]="true"
done
else
labels=$(echo '${{ toJSON(github.event.pull_request.labels) }}' | jq -r '.[] | .name')
for test_type in "${TESTSET[@]}"; do
if [[ "$labels" =~ $test_type ]]; then
EXECUTE_LABELED["$test_type"]="true"
fi
done
fi
;;
"push")
if ${{ github.ref_name == 'main' }} || ${{ github.ref_name == 'develop' }} || ${{ github.ref_type == 'tag' }} ; then
for test_type in "${TESTSET[@]}"; do
EXECUTE_LABELED["$test_type"]="true"
done
fi
;;
"schedule")
for test_type in "${TESTSET[@]}"; do
EXECUTE_LABELED["$test_type"]="true"
done
;;
*)
echo "No tests were labeled for execution!"
;;
esac
echo "Tests to execute based on labels:"
for test_type in "${TESTSET[@]}"; do
echo "$test_type""_labeled=${EXECUTE_LABELED["$test_type"]}" >> "$GITHUB_OUTPUT"
echo "$test_type""_labeled: ${EXECUTE_LABELED["$test_type"]}"
done
validate-pr-title:
name: Validate PR title
needs:
- setup-workflow
if: ${{ needs.setup-workflow.outputs.skip-workflow != 'Yes' && github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
pull-requests: read
statuses: write
steps:
- uses: amannn/[email protected]
with:
wip: true
validateSingleCommit: true
env:
GITHUB_TOKEN: ${{ github.token }}
meta:
runs-on: ubuntu-latest
needs:
- setup-workflow
if: ${{ needs.setup-workflow.outputs.skip-workflow != 'Yes' }}
outputs:
sc4s: ghcr.io/${{ github.repository }}/container:${{ fromJSON(steps.docker_action_meta.outputs.json).labels['org.opencontainers.image.version'] }}
container_tags: ${{ steps.docker_action_meta.outputs.tags }}
container_labels: ${{ steps.docker_action_meta.outputs.labels }}
container_buildtime: ${{ fromJSON(steps.docker_action_meta.outputs.json).labels['org.opencontainers.image.created'] }}
container_version: ${{ fromJSON(steps.docker_action_meta.outputs.json).labels['org.opencontainers.image.version'] }}
container_revision: ${{ fromJSON(steps.docker_action_meta.outputs.json).labels['org.opencontainers.image.revision'] }}
container_base: ${{ fromJSON(steps.docker_action_meta.outputs.json).tags[0] }}
matrix_supportedSplunk: ${{ steps.matrix.outputs.supportedSplunk }}
matrix_latestSplunk: ${{ steps.matrix.outputs.latestSplunk }}
matrix_supportedSC4S: ${{ steps.matrix.outputs.supportedSC4S }}
matrix_supportedModinputFunctionalVendors: ${{ steps.matrix.outputs.supportedModinputFunctionalVendors }}
matrix_supportedUIVendors: ${{ steps.matrix.outputs.supportedUIVendors }}
python39_splunk: ${{steps.python39_splunk.outputs.splunk}}
python39_sc4s: ${{steps.python39_splunk.outputs.sc4s}}
permissions:
contents: write
packages: read
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: false
persist-credentials: false
- name: Semantic Release
id: version
uses: splunk/[email protected]
with:
dry_run: true
git_committer_name: ${{ secrets.SA_GH_USER_NAME }}
git_committer_email: ${{ secrets.SA_GH_USER_EMAIL }}
gpg_private_key: ${{ secrets.SA_GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.SA_GPG_PASSPHRASE }}
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Docker meta
id: docker_action_meta
uses: docker/[email protected]
with:
images: ghcr.io/${{ github.repository }}/container
tags: |
type=sha,format=long
type=sha
type=semver,pattern={{version}},value=${{ steps.version.outputs.new_release_version }}
type=semver,pattern={{major}},value=${{ steps.version.outputs.new_release_version }}
type=semver,pattern={{major}}.{{minor}},value=${{ steps.version.outputs.new_release_version }}
type=ref,event=branch
type=ref,event=pr
- name: matrix
id: matrix
uses: splunk/[email protected]
- name: python39_Splunk
id: python39_splunk
run: |
echo "splunk={\"version\":\"unreleased-python3_9-a076ce4c50aa\", \"build\":\"a076ce4c50aa\", \"islatest\":false, \"isoldest\":false}" >> "$GITHUB_OUTPUT"
echo "sc4s={\"version\":\"2.49.5\", \"docker_registry\":\"ghcr.io/splunk/splunk-connect-for-syslog/container2\"}" >> "$GITHUB_OUTPUT"
fossa-scan:
runs-on: ubuntu-latest
needs:
- setup-workflow
if: ${{ needs.setup-workflow.outputs.skip-workflow != 'Yes' }}
steps:
- uses: actions/checkout@v3
- name: run fossa anlyze and create report
run: |
curl -H 'Cache-Control: no-cache' https://raw.githubusercontent.com/fossas/fossa-cli/master/install-latest.sh | bash
fossa analyze --debug
fossa report attribution --format text --timeout 600 > /tmp/THIRDPARTY
env:
FOSSA_API_KEY: ${{ secrets.FOSSA_API_KEY }}
- name: upload THIRDPARTY file
uses: actions/upload-artifact@v3
with:
name: THIRDPARTY
path: /tmp/THIRDPARTY
fossa-test:
continue-on-error: true
runs-on: ubuntu-latest
needs:
- fossa-scan
if: ${{ needs.setup-workflow.outputs.skip-workflow != 'Yes' }}
steps:
- uses: actions/checkout@v3
- name: run fossa test
run: |
curl -H 'Cache-Control: no-cache' https://raw.githubusercontent.com/fossas/fossa-cli/master/install-latest.sh | bash
fossa test --debug
env:
FOSSA_API_KEY: ${{ secrets.FOSSA_API_KEY }}
compliance-copyrights:
name: compliance-copyrights
runs-on: ubuntu-latest
needs:
- setup-workflow
if: ${{ needs.setup-workflow.outputs.skip-workflow != 'Yes' }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: REUSE Compliance Check
uses: fsfe/[email protected]
lint:
runs-on: ubuntu-latest
needs:
- setup-workflow
if: ${{ needs.setup-workflow.outputs.skip-workflow != 'Yes' }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.7"
- uses: pre-commit/[email protected]
review_secrets:
name: security-detect-secrets
runs-on: ubuntu-latest
needs:
- setup-workflow
if: ${{ needs.setup-workflow.outputs.skip-workflow != 'Yes' }}
steps:
- name: Checkout
if: github.event_name != 'pull_request'
uses: actions/checkout@v3
with:
submodules: false
fetch-depth: "0"
- name: Checkout for PR
if: github.event_name == 'pull_request'
uses: actions/checkout@v3
with:
submodules: false
fetch-depth: "0"
ref: ${{ github.head_ref }}
- name: Trufflehog Actions Scan
uses: edplato/[email protected]
with:
scanArguments: "--max_dept 5 -x .github/workflows/exclude-patterns.txt --allow .github/workflows/trufflehog-false-positive.json"
semgrep:
runs-on: ubuntu-latest
name: security-sast-semgrep
needs:
- setup-workflow
if: ${{ needs.setup-workflow.outputs.skip-workflow != 'Yes' && github.actor != 'dependabot[bot]' }}
steps:
- uses: actions/checkout@v3
- name: Semgrep
id: semgrep
uses: semgrep/semgrep-action@v1
with:
publishToken: ${{ secrets.SEMGREP_PUBLISH_TOKEN }}
test-inventory:
runs-on: ubuntu-latest
needs: setup-workflow
if: ${{ needs.setup-workflow.outputs.skip-workflow != 'Yes' }}
# Map a step output to a job output
outputs:
unit: ${{ steps.testset.outputs.unit }}
knowledge: ${{ steps.testset.outputs.knowledge }}
ui: ${{ steps.testset.outputs.ui }}
modinput_functional: ${{ steps.testset.outputs.modinput_functional }}
requirement_test: ${{ steps.testset.outputs.requirement_test }}
scripted_inputs: ${{ steps.testset.outputs.scripted_inputs }}
escu: ${{ steps.testset.outputs.escu }}
ucc_modinput_functional: ${{ steps.modinput-version.outputs.ucc_modinput_tests }}
steps:
- uses: actions/checkout@v3
- id: testset
name: Check available test types
run: |
find tests -type d -maxdepth 1 -mindepth 1 | sed 's|^tests/||g' | while read -r TESTSET; do echo "$TESTSET=true" >> "$GITHUB_OUTPUT"; echo "$TESTSET::true"; done
- id: modinput-version
name: Check modinput tests version
run: |
CENTAURS_MODINPUT_TESTS_CHECK_DIR="tests/modinput_functional/centaurs"
ucc_modinput_tests="true"
if [ -d "$CENTAURS_MODINPUT_TESTS_CHECK_DIR" ]; then
ucc_modinput_tests="false"
fi
echo "ucc_modinput_tests=$ucc_modinput_tests" >> "$GITHUB_OUTPUT"
run-unit-tests:
name: test-unit-python3-${{ matrix.python-version }}
if: ${{ needs.test-inventory.outputs.unit == 'true' }}
runs-on: ubuntu-latest
needs:
- test-inventory
strategy:
fail-fast: false
matrix:
python-version:
- "3.7"
permissions:
actions: read
deployments: read
contents: read
packages: read
statuses: read
checks: write
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Setup addon
run: |
if [ -f "poetry.lock" ]
then
mkdir -p package/lib || true
pip install poetry==1.5.1 poetry-plugin-export==1.4.0
poetry export --without-hashes -o package/lib/requirements.txt
poetry export --without-hashes --dev -o requirements_dev.txt
fi
if [ ! -f requirements_dev.txt ]; then echo no requirements;exit 0 ;fi
pip install -r requirements_dev.txt
- name: Create directories
run: |
mkdir -p /opt/splunk/var/log/splunk
chmod -R 777 /opt/splunk/var/log/splunk
- name: Copy pytest ini
run: cp tests/unit/pytest-ci.ini pytest.ini
- name: Run Pytest with coverage
run: pytest --cov=./ --cov-report=xml --junitxml=test-results/junit.xml tests/unit
- uses: actions/upload-artifact@v3
if: success() || failure()
with:
name: test-results-unit-python_${{ matrix.python-version }}
path: test-results/*
run-unit-tests-3_9:
name: test-unit-python3-${{ matrix.python-version }}
if: ${{ needs.test-inventory.outputs.unit == 'true' }}
runs-on: ubuntu-latest
needs:
- test-inventory
strategy:
fail-fast: false
matrix:
python-version:
- "3.9"
permissions:
actions: read
deployments: read
contents: read
packages: read
statuses: read
checks: write
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Setup addon
run: |
if [ -f "poetry.lock" ]
then
mkdir -p package/lib || true
pip install poetry==1.5.1 poetry-plugin-export==1.4.0
poetry export --without-hashes -o package/lib/requirements.txt
poetry export --without-hashes --dev -o requirements_dev.txt
fi
if [ ! -f requirements_dev.txt ]; then echo no requirements;exit 0 ;fi
pip install -r requirements_dev.txt
- name: Create directories
run: |
mkdir -p /opt/splunk/var/log/splunk
chmod -R 777 /opt/splunk/var/log/splunk
- name: Copy pytest ini
run: cp tests/unit/pytest-ci.ini pytest.ini
- name: Run Pytest with coverage
run: pytest --cov=./ --cov-report=xml --junitxml=test-results/junit.xml tests/unit
- uses: actions/upload-artifact@v3
if: success() || failure()
with:
name: test-results-unit-python_${{ matrix.python-version }}
path: test-results/*
build:
runs-on: ubuntu-latest
needs:
- setup-workflow
- test-inventory
- meta
- compliance-copyrights
- lint
- review_secrets
- semgrep
- run-unit-tests
- fossa-scan
if: ${{ !cancelled() && (needs.run-unit-tests.result == 'success' || needs.run-unit-tests.result == 'skipped') }}
outputs:
buildname: ${{ steps.buildupload.outputs.name }}
permissions:
contents: write
packages: read
steps:
- uses: actions/checkout@v3
with:
# Very Important semantic-release won't trigger a tagged
# build if this is not set false
persist-credentials: false
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: 3.7
- name: create requirements file for pip
run: |
if [ -f "poetry.lock" ]
then
echo " poetry.lock found "
sudo pip3 install poetry==1.5.1 poetry-plugin-export==1.4.0
poetry lock --check
poetry export --without-hashes -o requirements.txt
if [ "$(grep -cve '^\s*$' requirements.txt)" -ne 0 ]
then
echo "Prod dependencies were found, creating package/lib folder"
mkdir -p package/lib || true
mv requirements.txt package/lib
else
echo "No prod dependencies were found"
rm requirements.txt
fi
poetry export --without-hashes --dev -o requirements_dev.txt
cat requirements_dev.txt
fi
- name: Get pip cache dir
id: pip-cache
run: |
echo "dir=$(pip cache dir)" >> "$GITHUB_OUTPUT"
- name: Run Check there are libraries to scan
id: checklibs
run: if [ -f requirements_dev.txt ]; then echo "ENABLED=true" >> "$GITHUB_OUTPUT"; fi
- name: pip cache
if: ${{ steps.checklibs.outputs.ENABLED == 'true' }}
uses: actions/cache@v3
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip-${{ hashFiles('requirements_dev.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install deps
if: ${{ steps.checklibs.outputs.ENABLED == 'true' }}
run: pip install -r requirements_dev.txt
- name: Semantic Release Get Next
id: semantic
if: github.event_name != 'pull_request'
uses: splunk/[email protected]
with:
dry_run: true
git_committer_name: ${{ secrets.SA_GH_USER_NAME }}
git_committer_email: ${{ secrets.SA_GH_USER_EMAIL }}
gpg_private_key: ${{ secrets.SA_GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.SA_GPG_PASSPHRASE }}
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Determine the version to build
id: BuildVersion
uses: splunk/addonfactory-get-splunk-package-version-action@v1
with:
SemVer: ${{ steps.semantic.outputs.new_release_version }}
PrNumber: ${{ github.event.number }}
- name: Download THIRDPARTY
if: github.event_name != 'pull_request' && github.event_name != 'schedule'
uses: actions/download-artifact@v3
with:
name: THIRDPARTY
- name: Download THIRDPARTY (Optional for PR and schedule)
if: github.event_name == 'pull_request' || github.event_name == 'schedule'
continue-on-error: true
uses: actions/download-artifact@v3
with:
name: THIRDPARTY
- name: Update Notices
run: |
cp -f THIRDPARTY package/THIRDPARTY || echo "THIRDPARTY file not found (allowed for PR and schedule)"
- name: Build Package
id: uccgen
uses: splunk/addonfactory-ucc-generator-action@v2
with:
version: ${{ steps.BuildVersion.outputs.VERSION }}
- name: Slim Package
id: slim
uses: splunk/addonfactory-packaging-toolkit-action@v1
with:
source: ${{ steps.uccgen.outputs.OUTPUT }}
if: always()
- name: artifact-openapi
uses: actions/upload-artifact@v3
with:
name: artifact-openapi
path: ${{ github.workspace }}/${{ steps.uccgen.outputs.OUTPUT }}/static/openapi.json
if: ${{ !cancelled() && needs.test-inventory.outputs.ucc_modinput_functional == 'true' && needs.test-inventory.outputs.modinput_functional == 'true' }}
- name: artifact-splunk-base
uses: actions/upload-artifact@v3
with:
name: package-splunkbase
path: ${{ steps.slim.outputs.OUTPUT }}
if: ${{ !cancelled() }}
- name: upload-build-to-s3
id: buildupload
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
echo "name=$(basename "${{ steps.slim.outputs.OUTPUT }}")" >> "$GITHUB_OUTPUT"
basename "${{ steps.slim.outputs.OUTPUT }}"
aws s3 cp "${{ steps.slim.outputs.OUTPUT }}" s3://ta-production-artifacts/ta-apps/
- name: artifact-splunk-parts
uses: actions/upload-artifact@v3
with:
name: package-deployment
path: build/package/deployment**
if: ${{ !cancelled() }}
build-3_9:
runs-on: ubuntu-latest
needs:
- setup-workflow
- test-inventory
- meta
- compliance-copyrights
- lint
- review_secrets
- semgrep
- run-unit-tests-3_9
- fossa-scan
if: |
always() &&
(needs.run-unit-tests-3_9.result == 'success' || needs.run-unit-tests-3_9.result == 'skipped')
permissions:
contents: write
packages: read
steps:
- uses: actions/checkout@v3
with:
# Very Important semantic-release won't trigger a tagged
# build if this is not set false
persist-credentials: false
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: create requirements file for pip
run: |
if [ -f "poetry.lock" ]
then
echo " poetry.lock found "
sudo pip3 install poetry==1.5.1 poetry-plugin-export==1.4.0
poetry export --without-hashes -o requirements.txt
if [ "$(grep -cve '^\s*$' requirements.txt)" -ne 0 ]
then
echo "Prod dependencies were found, creating package/lib folder"
mkdir -p package/lib || true
mv requirements.txt package/lib
else
echo "No prod dependencies were found"
rm requirements.txt
fi
poetry export --without-hashes --dev -o requirements_dev.txt
cat requirements_dev.txt
fi
- id: pip-cache
run: |
echo "dir=$(pip cache dir)" >> "$GITHUB_OUTPUT"
- name: pip cache
uses: actions/cache@v3
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip-python3_9-${{ hashFiles('requirements_dev.txt') }}
restore-keys: |
${{ runner.os }}-pip-python3_9
- run: pip install -r requirements_dev.txt
- id: semantic
if: github.event_name != 'pull_request'
uses: splunk/[email protected]
with:
dry_run: true
git_committer_name: ${{ secrets.SA_GH_USER_NAME }}
git_committer_email: ${{ secrets.SA_GH_USER_EMAIL }}
gpg_private_key: ${{ secrets.SA_GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.SA_GPG_PASSPHRASE }}
env:
GITHUB_TOKEN: ${{ github.token }}
- id: BuildVersion
uses: splunk/addonfactory-get-splunk-package-version-action@v1
with:
SemVer: ${{ steps.semantic.outputs.new_release_version }}
PrNumber: ${{ github.event.number }}
- id: uccgen
uses: splunk/addonfactory-ucc-generator-action@v2
with:
version: ${{ steps.BuildVersion.outputs.VERSION }}
security-virustotal:
continue-on-error: true
name: security-virustotal
needs: build
if: ${{ !cancelled() && needs.build.result == 'success' }}
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v3
with:
name: package-splunkbase
path: build/package/
- name: VirusTotal Scan
uses: crazy-max/ghaction-virustotal@v3
with:
vt_api_key: ${{ secrets.VT_API_KEY }}
files: |
build/package/*
run-requirements-unit-tests:
runs-on: ubuntu-latest
needs:
- build
- test-inventory
if: ${{ !cancelled() && needs.build.result == 'success' && needs.test-inventory.outputs.requirement_test == 'true' }}
permissions:
actions: read
deployments: read
contents: read
packages: read
statuses: read
checks: write
steps:
- uses: actions/checkout@v3
- name: Install Python 3
uses: actions/setup-python@v4
with:
python-version: 3.7
- name: run-tests
uses: splunk/[email protected]
with:
input-files: tests/requirement_test/logs
- name: Archive production artifacts
if: ${{ !cancelled() }}
uses: actions/upload-artifact@v3
with:
name: test-results
path: |
test_*.txt
appinspect:
name: quality-appinspect-${{ matrix.tags }}
needs: build
if: ${{ !cancelled() && needs.build.result == 'success' }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
tags:
- "cloud"
- "appapproval"
- "deprecated_feature"
- "developer_guidance"
- "future"
- "self-service"
- "splunk_appinspect"
- "manual"
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: package-splunkbase
path: build/package/
- name: Scan
uses: splunk/[email protected]
with:
app_path: build/package/
included_tags: ${{ matrix.tags }}
result_file: appinspect_result_${{ matrix.tags }}.json
- name: upload-appinspect-report
if: ${{ !cancelled() }}
uses: actions/upload-artifact@v3
with:
name: appinspect_${{ matrix.tags }}_checks.json
path: appinspect_result_${{ matrix.tags }}.json
- name: upload-markdown
if: matrix.tags == 'manual'
uses: actions/upload-artifact@v3
with:
name: check_markdown
path: |
*_markdown.txt
appinspect-api:
name: appinspect api ${{ matrix.tags }}
needs: build
if: |
!cancelled() &&
needs.build.result == 'success' &&
( github.base_ref == 'main' || github.ref_name == 'main' )
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
tags:
- "cloud"
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: package-splunkbase
path: build/package
- name: AppInspect API
uses: splunk/[email protected]
with:
username: ${{ secrets.SPL_COM_USER }}
password: ${{ secrets.SPL_COM_PASSWORD }}
app_path: build/package/
included_tags: ${{ matrix.tags }}
- uses: actions/upload-artifact@v3
if: always()
with:
name: appinspect-api-html-report-${{ matrix.tags }}
path: AppInspect_response.html
artifact-registry:
runs-on: ubuntu-latest
needs:
- security-virustotal
- meta
if: ${{ !cancelled() && needs.security-virustotal.result == 'success' && needs.meta.result == 'success' }}
outputs:
artifact: ${{ steps.artifactid.outputs.result }}
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: package-splunkbase
path: build/package/splunkbase
- id: getappid
run: |
appid=$(jq -r '.info.id.name' package/app.manifest)
echo appid="$appid"
echo "result=$appid" >> "$GITHUB_OUTPUT"
- run: |
curl -LO https://github.com/oras-project/oras/releases/download/v0.12.0/oras_0.12.0_linux_amd64.tar.gz
mkdir -p oras-install/
tar -zxf oras_0.12.0_*.tar.gz -C oras-install/
mv oras-install/oras /usr/local/bin/
rm -rf oras_0.12.0_*.tar.gz oras-install/
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Packages Docker Registry
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Docker meta
id: meta
uses: docker/[email protected]
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern=v{{major}}.{{minor}},prefix=${{ steps.getappid.outputs.result }}-
type=semver,pattern=v{{major}},prefix=${{ steps.getappid.outputs.result }}-
type=semver,pattern=v{{version}},prefix=${{ steps.getappid.outputs.result }}-
type=semver,pattern={{major}}.{{minor}},prefix=${{ steps.getappid.outputs.result }}-
type=semver,pattern={{major}},prefix=${{ steps.getappid.outputs.result }}-
type=semver,pattern={{version}},prefix=${{ steps.getappid.outputs.result }}-
type=ref,event=branch,prefix=${{ steps.getappid.outputs.result }}-
type=ref,event=pr,prefix=${{ steps.getappid.outputs.result }}-
type=sha,prefix=${{ steps.getappid.outputs.result }}-
type=sha,format=long,prefix=${{ steps.getappid.outputs.result }}-
- name: Upload artifacts
run: |
tee /tmp/tags &>/dev/null <<EOF
${{ steps.meta.outputs.tags }}
EOF
pushd build/package/splunkbase/
PACKAGE=$(ls ./*)
echo "$PACKAGE"
mv "$PACKAGE" "${{ steps.getappid.outputs.result }}".spl
while IFS= read -r line
do
echo ">>$line<<"
oras push \
--manifest-config /dev/null:application/vnd.splunk.ent.package.v1.tar+gzip \
"$line" \
"${{ steps.getappid.outputs.result }}".spl
echo " complete"
done < /tmp/tags
popd
- name: Output artifact locator
id: artifactid
run: |
echo "result= ${{ needs.meta.outputs.sc4s }}" >> "$GITHUB_OUTPUT"
setup:
needs:
- build
- test-inventory
if: ${{ !cancelled() && needs.build.result == 'success' }}
runs-on: ubuntu-latest
outputs:
argo-server: ${{ steps.test-setup.outputs.argo-server }}
argo-http1: ${{ steps.test-setup.outputs.argo-http1 }}
argo-secure: ${{ steps.test-setup.outputs.argo-secure }}
spl-host-suffix: ${{ steps.test-setup.outputs.spl-host-suffix }}
argo-href: ""
argo-base-href: ${{ steps.test-setup.outputs.argo-base-href }}
argo-workflow-tmpl-name: ${{ steps.test-setup.outputs.argo-workflow-tmpl-name }}
argo-cancel-workflow-tmpl-name: ${{ steps.test-setup.outputs.argo-cancel-workflow-tmpl-name }}
k8s-manifests-branch: ${{ steps.test-setup.outputs.k8s-manifests-branch }}
argo-namespace: ${{ steps.test-setup.outputs.argo-namespace }}
addon-name: ${{ steps.test-setup.outputs.addon-name }}
job-name: ${{ steps.test-setup.outputs.job-name }}
labels: ${{ steps.test-setup.outputs.labels }}
addon-upload-path: ${{ steps.test-setup.outputs.addon-upload-path }}
directory-path: ${{ steps.test-setup.outputs.directory-path }}
s3-bucket: ${{ steps.test-setup.outputs.s3-bucket }}
env:
BUILD_NAME: ${{ needs.build.outputs.buildname }}
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
token: ${{ secrets.GH_TOKEN_ADMIN }}
- name: setup for test
id: test-setup
shell: bash
run: |
sudo apt-get install -y crudini
ADDON_NAME=$(crudini --get package/default/app.conf id name | tr '[:lower:]' '[:upper:]')
if [[ -n $(echo "${ADDON_NAME}" | awk -F 'SPLUNK_TA_' '{print $2}') ]];
then
ADDON_NAME=$(echo "${ADDON_NAME}" | awk -F 'SPLUNK_TA_' '{print $2}')
elif [[ -n $(echo "${ADDON_NAME}" | awk -F '_FOR_SPLUNK' '{print $1}') ]];
then
ADDON_NAME=$(echo "${ADDON_NAME}" | awk -F '_FOR_SPLUNK' '{print $1}')
fi
JOB_NAME=$(echo "$ADDON_NAME" | tail -c 16)-$(echo "${GITHUB_SHA}" | tail -c 8)-TEST-TYPE-${GITHUB_RUN_ID}
JOB_NAME=${JOB_NAME//[_.]/-}
LABELS="addon-name=${ADDON_NAME}"
ADDON_UPLOAD_PATH="s3://ta-production-artifacts/ta-apps/${{ needs.build.outputs.buildname }}"
{
echo "argo-server=argo.wfe.splgdi.com:443"
echo "argo-http1=true"
echo "argo-secure=true"
echo "argo-base-href=\'\'"
echo "argo-namespace=workflows"
echo "argo-workflow-tmpl-name=ta-workflow"
echo "argo-cancel-workflow-tmpl-name=cancel-workflow"
echo "directory-path=/tmp"
echo "s3-bucket=ta-production-artifacts"
echo "addon-name=\"$ADDON_NAME\""
echo "job-name=wf-$JOB_NAME"
echo "labels=$LABELS"
echo "addon-upload-path=$ADDON_UPLOAD_PATH"
echo "spl-host-suffix=wfe.splgdi.com"
echo "k8s-manifests-branch=main"
} >> "$GITHUB_OUTPUT"
- uses: actions/download-artifact@v3
if: ${{ needs.test-inventory.outputs.ucc_modinput_functional == 'true' && needs.test-inventory.outputs.modinput_functional == 'true'}}
id: download-openapi
with:
name: artifact-openapi
path: ${{ github.workspace }}
- name: Setup python
if: steps.download-openapi.conclusion != 'skipped'
uses: actions/setup-python@v4
with:
python-version: 3.7
- name: modinput-test-prerequisites
if: steps.download-openapi.conclusion != 'skipped'
shell: bash
env:
PYTHON_KEYRING_BACKEND: keyring.backends.null.Keyring
run: |
sudo pip3 install poetry==1.5.1
export POETRY_REPOSITORIES_SPLUNK_ADD_ON_UCC_MODINPUT_TEST_URL=https://github.com/splunk/addonfactory-ucc-test.git