-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathreusable-build-test-release.yml
More file actions
3339 lines (3280 loc) · 156 KB
/
Copy pathreusable-build-test-release.yml
File metadata and controls
3339 lines (3280 loc) · 156 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
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 mod_input marker'
type: string
default: >-
[""]
ucc-modinput-marker:
required: false
description: 'Parallel run ucc mod_input marker'
type: string
default: >-
[""]
ui_marker:
required: false
description: 'Parallel run ui marker'
type: string
default: >-
[""]
custom-version:
required: false
description: 'Version of release in the form of "x.x.x" string, specified by user instead of automatically generated semantic release'
type: string
default: ""
execute-tests-on-push-to-release:
required: false
description: 'Flag to run all tests on push to release branch'
type: string
default: 'false'
k8s-environment:
required: false
description: Specifies which environment to use for k8s testing. ["production", "staging"]
type: string
default: "production"
k8s-manifests-branch:
required: false
description: "branch for k8s manifests to run the tests on"
type: string
default: "v4.2"
scripted-inputs-os-list:
required: false
description: "list of OS used for scripted input tests"
type: string
default: >-
["ubuntu:18.04", "ubuntu:20.04", "ubuntu:22.04", "ubuntu:24.04", "redhat:8.4", "redhat:8.5", "redhat:8.6", "redhat:8.8", "redhat:9.5"]
upgrade-tests-ta-versions:
required: false
description: "List with TA versions (in 'X.X.X' format) that should be used as starting points for upgrade tests. Example: ['7.6.0', '7.7.0']"
type: string
default: >-
[""]
wfe-run-on-splunk-latest:
required: false
description: "Forces WFE tests to run only on the latest Splunk when set to true. When set to false - will run on all supported Splunk versions required for the release. When not set - default behavior."
type: string
default: "false"
python-version:
required: false
description: "Python version to use for testing"
type: string
default: "3.9"
spl2-generate:
required: false
description: "Run spl2-generate hook during pre-commit step"
type: boolean
default: false
gs-image-version:
required: false
description: "Version of the GS scorecard Docker image"
type: string
default: "1.2"
gs-version:
required: false
description: "Version of the GS scorecard"
type: string
default: "0.3"
secrets:
GH_TOKEN_ADMIN:
description: Github admin token
required: true
GH_APP_CLIENT_ID:
description: GitHub App Client ID for authentication
required: true
GH_APP_PRIVATE_KEY:
description: GitHub App private key for authentication
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
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
GSSA_AWS_ACCESS_KEY_ID:
description: GSSA AWS access key id
required: true
GSSA_AWS_SECRET_ACCESS_KEY:
description: GSSA AWS secret access key
required: true
permissions:
contents: read
packages: read
concurrency:
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
PYTHON_VERSION: ${{ inputs.python-version }}
POETRY_VERSION: "2.1.4"
POETRY_EXPORT_PLUGIN_VERSION: "1.9.0"
GS_IMAGE_VERSION: ${{ inputs.gs-image-version }}
GS_VERSION: ${{ inputs.gs-version }}
jobs:
validate-custom-version:
runs-on: ubuntu-latest
if: ${{ github.event.inputs.custom-version != '' }}
steps:
- uses: actions/checkout@v4
- name: Validate custom version
run: |
if [[ ! ${{ github.event.inputs.custom-version }} =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid custom version provided. Please provide a valid semver version."
exit 1
fi
git fetch --tags
if [ "$(git tag -l 'v${{ github.event.inputs.custom-version }}')" ]; then
echo "The provided version already exists. Please provide a unique version."
exit 1
fi
check-splunktafunctionaltests-exists:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
if grep -q 'splunktafunctionaltests' poetry.lock || grep -q 'splunktafunctionaltests' dev_deps/requirements_dev.txt 2>/dev/null; then
echo "::warning title=\"splunktafunctionaltests\" should NOT be used for modinput tests::For more details, please see https://splunk.slack.com/archives/C081JT7R69Z/p1754662758743839."
exit 1
else
exit 0
fi
check-docs-changes:
runs-on: ubuntu-latest
outputs:
docs-only: ${{ steps.check.outputs.docs-only }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Fetch all refs
run: git fetch --prune --unshallow
- name: Check if the changes are only in docs/*, mkdocs.yml or .github/workflows/validate-deploy-docs.yaml
id: check
run: |
set -o xtrace
# List all files modified in the commit or PR
changed_files=$(git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.sha }})
# Check if any of the changed files are not in docs/*, mkdocs.yml, or .github/workflows/validate-deploy-docs.yaml
if echo "$changed_files" | grep -vqE '^(docs/|mkdocs.yml|.github/workflows/validate-deploy-docs.yaml)'; then
echo "docs-only=false" >> "$GITHUB_OUTPUT"
else
echo "Only documentation changes found."
echo "docs-only=true" >> "$GITHUB_OUTPUT"
fi
setup-workflow:
runs-on: ubuntu-latest
needs:
- check-docs-changes
outputs:
execute-knowledge: ${{ steps.determine-test-execution-flags.outputs.execute_knowledge }}
execute-spl2: ${{ steps.determine-test-execution-flags.outputs.execute_spl2 }}
execute-ui: ${{ steps.determine-test-execution-flags.outputs.execute_ui }}
execute-modinput: ${{ steps.determine-test-execution-flags.outputs.execute_modinput_functional }}
execute-ucc_modinput: ${{ steps.determine-test-execution-flags.outputs.execute_ucc_modinput_functional }}
execute-scripted_inputs: ${{ steps.determine-test-execution-flags.outputs.execute_scripted_inputs }}
execute-upgrade: ${{ steps.determine-test-execution-flags.outputs.execute_upgrade }}
exit-first: ${{ steps.determine-test-execution-flags.outputs.exit-first }}
execute-unit: ${{ steps.determine-test-execution-flags.outputs.execute_unit }}
execute-gs-scorecard: ${{ steps.determine-test-execution-flags.outputs.execute_gs_scorecard }}
s3_bucket_k8s: ${{ steps.k8s-environment.outputs.s3_bucket }}
argo_server_domain_k8s: ${{ steps.k8s-environment.outputs.argo_server_domain }}
argo_token_secret_id_k8s: ${{ steps.k8s-environment.outputs.argo_token_secret_id }}
steps:
- name: set k8s environment
id: k8s-environment
run: |
if [[ ${{ inputs.k8s-environment }} == 'staging' ]]; then
echo "setting up argo variables for staging"
{
echo "s3_bucket=ta-staging-artifacts"
echo "argo_server_domain=argo.staging.wfe.splgdi.com"
echo "argo_token_secret_id=ta-staging-github-workflow-automation-token"
} >> "$GITHUB_OUTPUT"
else
echo "setting up argo variables for production"
{
echo "s3_bucket=ta-production-artifacts"
echo "argo_server_domain=argo.wfe.splgdi.com"
echo "argo_token_secret_id=ta-github-workflow-automation-token"
} >> "$GITHUB_OUTPUT"
fi
- name: Checkout code
uses: actions/checkout@v4
- name: Determine Test Execution Flags
id: determine-test-execution-flags
run: |
set +e
declare -A EXECUTION_FLAGS
TESTSET=("execute_unit" "execute_knowledge" "execute_spl2" "execute_ui" "execute_modinput_functional" "execute_ucc_modinput_functional" "execute_scripted_inputs" "execute_upgrade" "execute_gs_scorecard")
for test_type in "${TESTSET[@]}"; do
EXECUTION_FLAGS["$test_type"]="false"
done
if [[ "${{ needs.check-docs-changes.outputs.docs-only }}" == "true" ]]; then
echo "Docs-only changes detected. No tests will be executed."
else
echo "checking available test types."
declare -a TESTS_TO_CONSIDER_FOR_EXECUTION
while read -r TEST_BASE_NAME; do
if [[ -d "tests/$TEST_BASE_NAME" ]]; then
TESTS_TO_CONSIDER_FOR_EXECUTION+=("execute_$TEST_BASE_NAME")
echo "$TEST_BASE_NAME::true"
fi
done < <(find tests -type d -maxdepth 1 -mindepth 1 | sed 's|^tests/||g')
if [[ -d "package/default/data/spl2" ]]; then
TESTS_TO_CONSIDER_FOR_EXECUTION+=("execute_spl2")
echo "spl2::true"
fi
found_unit_test=false
for test_name in "${TESTS_TO_CONSIDER_FOR_EXECUTION[@]}"; do
if [[ "$test_name" == "execute_unit" ]]; then
found_unit_test=true
break
fi
done
if "$found_unit_test"; then
EXECUTION_FLAGS["execute_unit"]="true"
fi
case "${{ github.event_name }}" in
"pull_request")
labels=$(echo '${{ toJSON(github.event.pull_request.labels) }}' | jq -r '.[] | .name')
if ${{ github.base_ref == 'main' }} && ${{ contains(github.event.pull_request.labels.*.name, 'use_labels') }}; then
for test_type in "${TESTS_TO_CONSIDER_FOR_EXECUTION[@]}"; do
if [[ "$labels" =~ $test_type ]]; then
EXECUTION_FLAGS["$test_type"]="true"
fi
done
elif ${{ github.base_ref == 'main' }} || ${{ contains(github.event.pull_request.labels.*.name, 'execute_all_tests') }}; then
for test_type in "${TESTS_TO_CONSIDER_FOR_EXECUTION[@]}"; do
# Exclude upgrade tests on PRs to main
if [[ "$test_type" != "execute_upgrade" ]]; then
EXECUTION_FLAGS["$test_type"]="true"
fi
done
else
for test_type in "${TESTS_TO_CONSIDER_FOR_EXECUTION[@]}"; do
if [[ "$labels" =~ $test_type ]]; then
EXECUTION_FLAGS["$test_type"]="true"
fi
done
fi
;;
"push")
if ${{ github.ref_name == 'main' }} || ${{ github.ref_name == 'develop' }} ||
${{ startsWith(github.ref_name, 'release/') && inputs.execute-tests-on-push-to-release == 'true' }} ; then
for test_type in "${TESTS_TO_CONSIDER_FOR_EXECUTION[@]}"; do
# Exclude upgrade tests on push to main
if [[ "$test_type" != "execute_upgrade" ]]; then
EXECUTION_FLAGS["$test_type"]="true"
fi
done
fi
;;
"schedule")
for test_type in "${TESTS_TO_CONSIDER_FOR_EXECUTION[@]}"; do
# Exclude upgrade tests in scheduled runs
if [[ "$test_type" != "execute_upgrade" ]]; then
EXECUTION_FLAGS["$test_type"]="true"
fi
done
;;
"workflow_dispatch")
if ${{ inputs.custom-version != '' }} ; then
for test_type in "${TESTS_TO_CONSIDER_FOR_EXECUTION[@]}"; do
# Exclude upgrade tests in custom releases
if [[ "$test_type" != "execute_upgrade" ]]; then
EXECUTION_FLAGS["$test_type"]="true"
fi
done
fi
;;
*)
echo "No tests were labeled for execution!"
;;
esac
# GS Scorecard: runs when label is present (any PR) or on push to main
# Required (must not be skipped) for merging PRs to main -- enforced in pre-publish
if [[ "${{ github.event_name }}" == "pull_request" ]] && [[ "$labels" =~ execute_gs_scorecard ]]; then
EXECUTION_FLAGS["execute_gs_scorecard"]="true"
elif [[ "${{ github.event_name }}" == "push" ]] && [[ "${{ github.ref_name }}" == "main" ]]; then
EXECUTION_FLAGS["execute_gs_scorecard"]="true"
fi
fi
echo "Tests to be executed:"
for test_type in "${TESTSET[@]}"; do
echo "$test_type""=${EXECUTION_FLAGS["$test_type"]}" >> "$GITHUB_OUTPUT"
echo "$test_type"": ${EXECUTION_FLAGS["$test_type"]}"
done
# exit first fail if label exit-first is present
EXIT_FIRST=""
if ${{ contains(github.event.pull_request.labels.*.name, 'exit-first') }}; then
EXIT_FIRST="-x"
fi
echo "exit-first=${EXIT_FIRST}" >> "$GITHUB_OUTPUT"
echo "exit-first: ${EXIT_FIRST}"
validate-pr-title:
name: Validate PR title
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
pull-requests: read
statuses: write
steps:
- uses: amannn/action-semantic-pull-request@v5.5.3
with:
wip: true
validateSingleCommit: true
env:
GITHUB_TOKEN: ${{ github.token }}
meta:
runs-on: ubuntu-latest
outputs:
matrix_Splunk: ${{ steps.determine_splunk.outputs.matrixSplunk }}
matrix_splunkModinput: ${{ steps.determine_splunk.outputs.matrixSplunkModinput }}
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 }}
permissions:
contents: write
packages: read
steps:
- uses: actions/checkout@v4
with:
submodules: false
persist-credentials: false
- id: matrix
uses: splunk/addonfactory-test-matrix-action@feat/splunk-9-4-python-version
with:
features: PYTHON39
- id: determine_splunk
env:
wfe_run_on_splunk_latest: ${{ inputs.wfe-run-on-splunk-latest }}
run: |
if [[ "${{ github.event_name }}" == "schedule" ]]; then
wfe_run_on_splunk_latest="true"
else
if [[ "${{ github.base_ref }}" == "main" || "${{ github.ref_name }}" == "main" ]] || \
[[ "${{ github.ref_name }}" == "develop" && "${{ github.event_name }}" == "push" ]]; then
wfe_run_on_splunk_latest="false"
else
wfe_run_on_splunk_latest="true"
fi
fi
if [[ "$wfe_run_on_splunk_latest" == "true" ]]; then
echo "matrixSplunk=${{ toJson(steps.matrix.outputs.latestSplunk) }}" >> "$GITHUB_OUTPUT"
echo "matrixSplunkModinput=${{ toJson(steps.matrix.outputs.latestSplunk) }}" >> "$GITHUB_OUTPUT"
else
echo "matrixSplunk=${{ toJson(steps.matrix.outputs.supportedSplunk) }}" >> "$GITHUB_OUTPUT"
echo "matrixSplunkModinput=${{ toJson(steps.matrix.outputs.supportedSplunkModinput) }}" >> "$GITHUB_OUTPUT"
fi
- name: job summary
run: |
splunk_version_list=$(echo '${{ steps.determine_splunk.outputs.matrixSplunk }}' | jq -r '.[].version')
sc4s_version_list=$(echo '${{ steps.matrix.outputs.supportedSC4S }}' | jq -r '.[].version')
echo -e "## Summary of Versions Used\n- **Splunk versions used:** (${splunk_version_list})\n- **SC4S versions used:** (${sc4s_version_list})\n- Browser: Chrome" >> "$GITHUB_STEP_SUMMARY"
fossa-scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: run fossa analyze and create report
id: fossa-scan
run: |
curl -H 'Cache-Control: no-cache' https://raw.githubusercontent.com/fossas/fossa-cli/master/install-latest.sh | bash
fossa analyze --debug 2>&1 | tee /tmp/fossa_analyze_output.txt
exit_code="${PIPESTATUS[0]}"
FOSSA_REPORT_URL=$(grep -o 'https://app.fossa.com[^ ]*' /tmp/fossa_analyze_output.txt || true)
echo "url=$FOSSA_REPORT_URL"
echo "FOSSA_REPORT_URL=$FOSSA_REPORT_URL" >> "$GITHUB_OUTPUT"
fossa report attribution --format text --timeout 600 > /tmp/THIRDPARTY
exit "$exit_code"
env:
FOSSA_API_KEY: ${{ secrets.FOSSA_API_KEY }}
- name: upload THIRDPARTY file
uses: actions/upload-artifact@v4
with:
name: THIRDPARTY
path: /tmp/THIRDPARTY
- name: job summary
if: success() || failure()
run: |
echo "FOSSA Report: ${{ steps.fossa-scan.outputs.FOSSA_REPORT_URL }}" >> "$GITHUB_STEP_SUMMARY"
fossa-test:
continue-on-error: true
runs-on: ubuntu-latest
needs:
- fossa-scan
steps:
- uses: actions/checkout@v4
- 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
steps:
- name: Checkout
uses: actions/checkout@v4
- name: REUSE Compliance Check
uses: fsfe/reuse-action@v1.1
pre-commit:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: '17'
- name: Run pre-commit (skip spl2-generate)
if: ${{ !inputs['spl2-generate'] }}
uses: pre-commit/action@v3.0.1
env:
SKIP: spl2-generate
- name: Run pre-commit (with spl2-generate)
if: ${{ inputs['spl2-generate'] }}
uses: pre-commit/action@v3.0.1
review_secrets:
name: security-detect-secrets
runs-on: ubuntu-latest
steps:
- name: Checkout
if: github.event_name != 'pull_request'
uses: actions/checkout@v4
with:
submodules: false
fetch-depth: "0"
- name: Checkout for PR
if: github.event_name == 'pull_request'
uses: actions/checkout@v4
with:
submodules: false
fetch-depth: "0"
ref: ${{ github.head_ref }}
- name: Secret Scanning Trufflehog
uses: trufflesecurity/trufflehog@v3.88.5
with:
extra_args: -x .github/workflows/exclude-patterns.txt --json --only-verified
version: 3.77.0
semgrep:
uses: splunk/sast-scanning/.github/workflows/sast-scan.yml@main
secrets:
SEMGREP_KEY: ${{ secrets.SEMGREP_PUBLISH_TOKEN }}
with:
block_mode: "policy"
run-unit-tests:
name: run-unit-tests
runs-on: ubuntu-22.04
needs:
- setup-workflow
if: ${{ needs.setup-workflow.outputs.execute-unit == 'true' }}
permissions:
actions: read
deployments: read
contents: read
packages: read
statuses: read
checks: write
steps:
- uses: actions/create-github-app-token@v3
id: app-token
with:
client-id: ${{ secrets.GH_APP_CLIENT_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Setup addon
run: |
if [ -f "poetry.lock" ]
then
python${{ env.PYTHON_VERSION }} -m pip install poetry==${{ env.POETRY_VERSION }} poetry-plugin-export==${{ env.POETRY_EXPORT_PLUGIN_VERSION }}
mkdir -p package/lib || true
poetry check --lock
poetry export --without-hashes --with dev -o package/lib/requirements.txt
else
echo "No poetry.lock found, make sure your dependencies are managed through poetry, exiting"
exit 1
fi
git config --global --add url."https://x-access-token:${{ steps.app-token.outputs.token }}@github.com".insteadOf https://github.com
git config --global --add url."https://x-access-token:${{ steps.app-token.outputs.token }}@github.com".insteadOf ssh://git@github.com
python${{ env.PYTHON_VERSION }} -m venv ~/.dev_venv
~/.dev_venv/bin/python${{ env.PYTHON_VERSION }} -m pip install -r package/lib/requirements.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: ~/.dev_venv/bin/python${{ env.PYTHON_VERSION }} -m pytest --cov=./ --cov-report=xml --junitxml=test-results/junit.xml tests/unit
- name: Job summary
continue-on-error: true
run: |
sudo apt-get update
sudo apt-get install -y libxml2-utils
junit_xml_file=$(find "test-results" -name "*.xml" -type f 2>/dev/null | head -n 1)
if [ -n "$junit_xml_file" ]; then
total_tests=$(xmllint --xpath "count(//testcase)" "$junit_xml_file")
failures=$(xmllint --xpath "count(//testcase[failure])" "$junit_xml_file")
errors=$(xmllint --xpath "count(//testcase[error and not(failure)])" "$junit_xml_file")
skipped=$(xmllint --xpath "count(//testcase[skipped])" "$junit_xml_file")
passed=$((total_tests - failures - errors - skipped))
echo -e "| Total Tests | Passed Tests | Failed Tests | Errored Tests | Skipped Tests |\n| ----------- | ------------ | ------------ | ------------- | ------------- |\n| $total_tests | $passed | $failures | $errors | $skipped |" >> "$GITHUB_STEP_SUMMARY"
else
echo "no XML File found, exiting"
exit 1
fi
- uses: actions/upload-artifact@v4
if: success() || failure()
with:
name: test-results-unit-python_${{ env.PYTHON_VERSION }}
path: test-results/*
build:
runs-on: ubuntu-22.04
needs:
- check-docs-changes
- validate-custom-version
- setup-workflow
- meta
- compliance-copyrights
- pre-commit
- review_secrets
- semgrep
- run-unit-tests
- fossa-scan
if: ${{ !cancelled() && (needs.run-unit-tests.result == 'success' || needs.run-unit-tests.result == 'skipped') && (needs.validate-custom-version.result == 'success' || needs.validate-custom-version.result == 'skipped') && (needs.check-docs-changes.outputs.docs-only == 'false') }}
outputs:
buildname: ${{ steps.buildupload.outputs.name }}
permissions:
contents: write
packages: read
steps:
- uses: actions/create-github-app-token@v3
id: app-token
with:
client-id: ${{ secrets.GH_APP_CLIENT_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
- uses: actions/checkout@v4
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@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: '17'
- name: create requirements file for pip
run: |
git config --global --add url."https://x-access-token:${{ steps.app-token.outputs.token }}@github.com".insteadOf https://github.com
git config --global --add url."https://x-access-token:${{ steps.app-token.outputs.token }}@github.com".insteadOf ssh://git@github.com
if [ -f "poetry.lock" ]
then
echo " poetry.lock found "
python${{ env.PYTHON_VERSION }} -m pip install poetry==${{ env.POETRY_VERSION }} poetry-plugin-export==${{ env.POETRY_EXPORT_PLUGIN_VERSION }}
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
fi
- name: Setup UCC
run: |
if [ -f "dev_deps/requirements_ucc.txt" ]; then
echo "Found requirements_ucc.txt. Installing UCC dependencies in an isolated environment"
python${{ env.PYTHON_VERSION }} -m venv ~/.ucc_venv
~/.ucc_venv/bin/python${{ env.PYTHON_VERSION }} -m pip install -r dev_deps/requirements_ucc.txt
export UCC_GEN="$HOME/.ucc_venv/bin/ucc-gen"
if [ ! -f "$UCC_GEN" ]; then
echo "ucc-gen not found after installing requirements from dev_deps/requirements_ucc.txt"
exit 1
fi
echo "UCC_GEN=$UCC_GEN" >> "$GITHUB_ENV"
else
echo "No UCC requirements file found, skipping UCC setup"
echo "Create a dev_deps/requirements_ucc.txt file and place UCC requirement there, to avoid dependency conflicts"
exit 1
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 dev_deps/requirements_dev.txt ]; then echo "ENABLED=true" >> "$GITHUB_OUTPUT"; fi
- name: pip cache
if: ${{ steps.checklibs.outputs.ENABLED == 'true' }}
uses: actions/cache@v4
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip-${{ hashFiles('dev_deps/requirements_dev.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Semantic Release Get Next
id: semantic
if: github.event_name != 'pull_request'
uses: splunk/semantic-release-action@v1.3
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
run: |
INPUT_SEMVER="${{ github.event.inputs.custom-version != '' && github.event.inputs.custom-version || steps.semantic.outputs.new_release_version }}"
echo "Initial semver ${INPUT_SEMVER}"
INPUT_PRNUMBER="${{ github.event.number }}"
SEMVER_REGEX='^v?[0-9]+\.[0-9]+\.[0-9]+$'
BETA_REGEX='^v?[0-9]+\.[0-9]+\.[0-9]+-beta\.[0-9]+$'
echo working with version $INPUT_SEMVER
if [[ $INPUT_SEMVER =~ $SEMVER_REGEX ]];
then
echo using provided semver
VERSION=$INPUT_SEMVER
elif [[ $INPUT_SEMVER =~ $BETA_REGEX ]];
then
VERSION=$(echo $INPUT_SEMVER | awk '{gsub("-beta\.", "-B");print}')
else
if [[ $GITHUB_EVENT_NAME != 'pull_request' ]];
then
echo this is not a release build and NOT PR RUNID + run ID
VERSION=0.0.${GITHUB_RUN_ID}
else
echo this is not a release build and is a PR use run ID
VERSION=0.${INPUT_PRNUMBER}.${GITHUB_RUN_ID}
fi
fi
FINALVERSION="${VERSION//v}"
echo "Version to build is ${FINALVERSION}"
echo "VERSION=${FINALVERSION}" >> "$GITHUB_OUTPUT"
- name: Download THIRDPARTY
if: github.event_name != 'pull_request' && github.event_name != 'schedule'
uses: actions/download-artifact@v4
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@v4
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
run: |
"${UCC_GEN:-ucc-gen}" build --ta-version ${{ steps.BuildVersion.outputs.VERSION }}
if [ -f package.json ]
then
yarn
if [ -n ${{ steps.BuildVersion.outputs.VERSION }} ]
then
yarn version --new-version ${{ steps.BuildVersion.outputs.VERSION }} --no-git-tag-version
fi
yarn run build
fi
echo "OUTPUT=output/$(ls output/)" >> "$GITHUB_OUTPUT"
- name: Slim Package
id: slim
run: |
pip install splunk-packaging-toolkit==1.2.4
INPUT_SOURCE=${{ steps.uccgen.outputs.OUTPUT }}
SOURCE_REGEX='^.*/$'
if [[ $INPUT_SOURCE =~ $SOURCE_REGEX ]];then
echo Removing trailing / from INPUT_SOURCE slim is picky
INPUT_SOURCE=$(echo $INPUT_SOURCE | sed 's/\(.*\)\//\1/')
fi
slim generate-manifest "${INPUT_SOURCE}" --update >/tmp/app.manifest || true
cp /tmp/app.manifest "${INPUT_SOURCE}"/app.manifest
mkdir -p build/package/splunkbase
mkdir -p build/package/deployment
slim package -o build/package/splunkbase "${INPUT_SOURCE}"
for f in build/package/splunkbase/*.tar.gz; do
n=$(echo "${f}" | awk '{gsub("-[0-9]+.[0-9]+.[0-9]+-[a-f0-9]+-?", "");print}' | sed 's/.tar.gz/.spl/')
mv "${f}" "${n}"
done
PACKAGE=$(ls build/package/splunkbase/*)
slim partition "${PACKAGE}" -o build/package/deployment/ || true
for f in build/package/deployment/*.tar.gz; do
n=$(echo "${f}" | awk '{gsub("-[0-9]+.[0-9]+.[0-9]+-[a-f0-9]+-?", "");print}' | sed 's/.tar.gz/.spl/')
mv "${f}" "${n}"
done
slim validate "${PACKAGE}"
chmod -R +r build
echo "OUTPUT=$PACKAGE" >> "$GITHUB_OUTPUT"
if: always()
- name: artifact-openapi
uses: actions/upload-artifact@v4
with:
name: artifact-openapi
path: ${{ github.workspace }}/${{ steps.uccgen.outputs.OUTPUT }}/appserver/static/openapi.json
if: ${{ !cancelled() && needs.setup-workflow.outputs.execute-ucc_modinput == 'true' }}
- name: artifact-splunk-base
uses: actions/upload-artifact@v4
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://${{ needs.setup-workflow.outputs.s3_bucket_k8s }}/ta-apps/"
- name: artifact-splunk-parts
uses: actions/upload-artifact@v4
with:
name: package-deployment
path: build/package/deployment**
if: ${{ !cancelled() }}
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"
- "manual"
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: package-splunkbase
path: build/package/
- name: Scan
uses: splunk/appinspect-cli-action@v2.11
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@v4
with:
name: appinspect_${{ matrix.tags }}_checks.json
path: appinspect_result_${{ matrix.tags }}.json
- name: upload-markdown
if: matrix.tags == 'manual'
uses: actions/upload-artifact@v4
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' || startsWith(github.base_ref, 'release/') || startsWith(github.ref_name, 'release/') )
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
tags:
- "cloud"
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: package-splunkbase
path: build/package
- name: AppInspect API
uses: splunk/appinspect-api-action@v3.0
with:
username: ${{ secrets.SPL_COM_USER }}
password: ${{ secrets.SPL_COM_PASSWORD }}
app_path: build/package/
included_tags: ${{ matrix.tags }}
- uses: actions/upload-artifact@v4
if: always()
with:
name: appinspect-api-html-report-${{ matrix.tags }}
path: AppInspect_response.html
run-gs-scorecard:
name: quality-gs-scorecard
needs:
- build
- setup-workflow
if: ${{ !cancelled() && needs.build.result == 'success' && needs.setup-workflow.outputs.execute-gs-scorecard == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/create-github-app-token@v3
id: app-token
with:
client-id: ${{ secrets.GH_APP_CLIENT_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
- uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.GSSA_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.GSSA_AWS_SECRET_ACCESS_KEY }}
aws-region: us-west-2
- name: Login to Amazon ECR
uses: aws-actions/amazon-ecr-login@v2
- name: Pull GS Scorecard image
run:
docker pull 956110764581.dkr.ecr.us-west-2.amazonaws.com/ta-automation/gs-scorecard:${{ env.GS_IMAGE_VERSION }}
- name: Run GS Scorecard
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
GITHUB_USERNAME: ${{ secrets.SA_GH_USER_NAME }}
APPINSPECT_USER: ${{ secrets.SPL_COM_USER }}
APPINSPECT_PASS: ${{ secrets.SPL_COM_PASSWORD }}
run: |
docker run --rm \
-e GITHUB_TOKEN \
-e GITHUB_USERNAME \
-e AWS_ACCESS_KEY_ID="${{ secrets.GSSA_AWS_ACCESS_KEY_ID }}" \
-e AWS_SECRET_ACCESS_KEY="${{ secrets.GSSA_AWS_SECRET_ACCESS_KEY }}" \
-e AWS_DEFAULT_REGION="us-west-2" \
-e APPINSPECT_USER \
-e APPINSPECT_PASS \
-e GS_VERSION="${{ env.GS_VERSION }}" \
-v "$(pwd)":/addon \
956110764581.dkr.ecr.us-west-2.amazonaws.com/ta-automation/gs-scorecard:"${{ env.GS_IMAGE_VERSION }}"
- name: Upload GS Scorecard report
uses: actions/upload-artifact@v4
with:
name: gs-scorecard-report
path: ./gs_scorecard.json
- name: Print and verify GS Scorecard report
run: |
if [ ! -f ./gs_scorecard.json ]; then
echo "::error::GS Scorecard report not found"
exit 1
fi
echo "::group::GS Scorecard Report"
jq . ./gs_scorecard.json
echo "::endgroup::"
passed=$(jq -r '.result.passed' ./gs_scorecard.json)
if [ "$passed" != "true" ]; then
echo "::error::GS Scorecard failed"
exit 1
fi
setup:
needs:
- setup-workflow
- build
if: ${{ !cancelled() && needs.build.result == 'success' }}
runs-on: ubuntu-22.04
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/create-github-app-token@v3
id: app-token
with:
client-id: ${{ secrets.GH_APP_CLIENT_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
- uses: actions/checkout@v4
with:
submodules: recursive
token: ${{ steps.app-token.outputs.token }}
- 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}') ]];