Skip to content

Commit 8c5f61c

Browse files
feat: label handling for reusable workflow (#148)
* chore: first implementation * chore: refactor of code * chore: remove unused parts of code * chore: add basic loging * chore: fix for preserve_infra condition * chore: update typos * chore: refine github array handling * chore: back to yes/no delay-destroy and refactor * chore: further refactoring * chore: fixed handling of other than pr events * chore: add wokrflow_dispatch condition * chore: input handling for workflow_dispatch * chore: fix manual_dispatch inputs handling * chore: refactor if to case statement * chore: add workflow concurrency * fix: handling of github empty values * chore: update README * chore: remove workflow_dispatch and concurenct, other minor fixes * chore: limit new features added * chore: fixing pre commit * chore: add all_tests label handling * fix: correct test execution conditional statements * fix: specify labels names
1 parent e3fec7d commit 8c5f61c

File tree

2 files changed

+89
-57
lines changed

2 files changed

+89
-57
lines changed

.github/workflows/reusable-build-test-release.yml

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ jobs:
7272
execute-modinput_functional: ${{ steps.delay-destroy-setup.outputs.execute-modinput_functional }}
7373
execute-scripted_inputs: ${{ steps.delay-destroy-setup.outputs.execute-scripted_inputs }}
7474
execute-requirement_test: ${{ steps.delay-destroy-setup.outputs.execute-requirement_test }}
75+
execute-labeled-knowledge: ${{ steps.configure-tests-on-labels.outputs.execute-labeled-knowledge }}
76+
execute-labeled-ui: ${{ steps.configure-tests-on-labels.outputs.execute-labeled-ui }}
77+
execute-labeled-escu: ${{ steps.configure-tests-on-labels.outputs.execute-labeled-escu }}
78+
execute-labeled-modinput: ${{ steps.configure-tests-on-labels.outputs.execute-labeled-modinput_functional }}
79+
execute-labeled-scripted_inputs: ${{ steps.configure-tests-on-labels.outputs.execute-labeled-scripted_inputs }}
80+
execute-labeled-requirement: ${{ steps.configure-tests-on-labels.outputs.execute-labeled-requirement_test }}
7581
steps:
7682
- name: skip workflow if description is empty for labeled pr
7783
id: skip-workflow
@@ -106,7 +112,7 @@ jobs:
106112
TESTSET="${{ steps.skip-workflow.outputs.testset }}"
107113
for test_type in $TESTSET; do
108114
eval DELAY_DESTROY_"$test_type"="No"
109-
eval EXECUTE_"$test_type"="Yes"
115+
eval EXECUTE_"$test_type"="No"
110116
done
111117
if [[ '${{ github.event.label.name }}' == 'preserve_infra' ]]; then
112118
echo "$PR_BODY" >> body.txt
@@ -116,9 +122,8 @@ jobs:
116122
fi
117123
for test_type in $TESTSET; do
118124
if [[ $tests =~ $test_type ]]; then
125+
eval EXECUTE_"$test_type"="Yes"
119126
eval DELAY_DESTROY_"$test_type"="Yes"
120-
else
121-
eval EXECUTE_"$test_type"="No"
122127
fi
123128
done
124129
fi
@@ -138,6 +143,53 @@ jobs:
138143
echo "execute-escu=$EXECUTE_escu"
139144
echo "execute-requirement_test=$EXECUTE_requirement_test"
140145
} >> "$GITHUB_OUTPUT"
146+
- name: configure tests based on labels
147+
id: configure-tests-on-labels
148+
run: |
149+
set +e
150+
declare -A EXECUTE_LABELED
151+
TESTSET=("execute_knowledge" "execute_ui" "execute_modinput_functional" "execute_scripted_inputs" "execute_escu" "execute_requirement_test")
152+
for test_type in "${TESTSET[@]}"; do
153+
EXECUTE_LABELED["$test_type"]="false"
154+
done
155+
156+
case "${{ github.event_name }}" in
157+
"pull_request")
158+
if ${{ github.base_ref == 'main' }} || ${{ contains(github.event.pull_request.labels.*.name, 'execute_all_tests') }}; then
159+
for test_type in "${TESTSET[@]}"; do
160+
EXECUTE_LABELED["$test_type"]="true"
161+
done
162+
else
163+
labels=$(echo '${{ toJSON(github.event.pull_request.labels) }}' | jq -r '.[] | .name')
164+
for test_type in "${TESTSET[@]}"; do
165+
if [[ "$labels" =~ $test_type ]]; then
166+
EXECUTE_LABELED["$test_type"]="true"
167+
fi
168+
done
169+
fi
170+
;;
171+
"push")
172+
if ${{ github.ref_name == 'main' }} || ${{ github.ref_name == 'develop' }}; then
173+
for test_type in "${TESTSET[@]}"; do
174+
EXECUTE_LABELED["$test_type"]="true"
175+
done
176+
fi
177+
;;
178+
"schedule")
179+
for test_type in "${TESTSET[@]}"; do
180+
EXECUTE_LABELED["$test_type"]="true"
181+
done
182+
;;
183+
*)
184+
echo "No tests were labeled for execution!"
185+
;;
186+
esac
187+
188+
echo "Tests to execute based on labels:"
189+
for test_type in "${TESTSET[@]}"; do
190+
echo "execute-labeled-$test_type=${EXECUTE_LABELED["$test_type"]}" >> "$GITHUB_OUTPUT"
191+
echo "execute-labeled-$test_type: ${EXECUTE_LABELED["$test_type"]}"
192+
done
141193
meta:
142194
runs-on: ubuntu-latest
143195
needs:
@@ -735,7 +787,7 @@ jobs:
735787
} >> "$GITHUB_OUTPUT"
736788
737789
run-knowledge-tests:
738-
if: ${{ needs.test-inventory.outputs.knowledge == 'true' && needs.setup-workflow.outputs.execute-ko == 'Yes' }}
790+
if: ${{ needs.test-inventory.outputs.knowledge == 'true' && (needs.setup-workflow.outputs.execute-ko == 'Yes' || needs.setup-workflow.outputs.execute-labeled-knowledge == 'true') }}
739791
needs:
740792
- build
741793
- test-inventory
@@ -942,7 +994,7 @@ jobs:
942994
${{ needs.setup.outputs.directory-path }}/diag*
943995
944996
run-requirement-tests:
945-
if: ${{ needs.test-inventory.outputs.requirement_test == 'true' && needs.setup-workflow.outputs.execute-requirement_test == 'Yes' }}
997+
if: ${{ needs.test-inventory.outputs.requirement_test == 'true' && (needs.setup-workflow.outputs.execute-requirement_test == 'Yes' || needs.setup-workflow.outputs.execute-labeled-requirement == 'true') }}
946998
needs:
947999
- build
9481000
- test-inventory
@@ -1128,7 +1180,7 @@ jobs:
11281180
${{ needs.setup.outputs.directory-path }}/diag*
11291181
11301182
run-ui-tests:
1131-
if: ${{ needs.test-inventory.outputs.ui == 'true' && needs.setup-workflow.outputs.execute-ui == 'Yes' }}
1183+
if: ${{ needs.test-inventory.outputs.ui == 'true' && (needs.setup-workflow.outputs.execute-ui == 'Yes' || needs.setup-workflow.outputs.execute-labeled-ui == 'true') }}
11321184
needs:
11331185
- build
11341186
- test-inventory
@@ -1322,7 +1374,7 @@ jobs:
13221374
${{ needs.setup.outputs.directory-path }}/diag*
13231375
13241376
run-modinput-tests:
1325-
if: ${{ needs.test-inventory.outputs.modinput_functional == 'true' && needs.setup-workflow.outputs.execute-modinput_functional == 'Yes' }}
1377+
if: ${{ needs.test-inventory.outputs.modinput_functional == 'true' && (needs.setup-workflow.outputs.execute-modinput_functional == 'Yes' || needs.setup-workflow.outputs.execute-labeled-modinput == 'true') }}
13261378
needs:
13271379
- build
13281380
- test-inventory
@@ -1529,7 +1581,7 @@ jobs:
15291581
${{ needs.setup.outputs.directory-path }}/diag*
15301582
15311583
run-scripted-input-tests-full-matrix:
1532-
if: ${{ needs.test-inventory.outputs.scripted_inputs == 'true' && ( github.base_ref == 'main' || github.ref_name == 'main' ) && needs.setup-workflow.outputs.execute-scripted_inputs == 'Yes' }}
1584+
if: ${{ needs.test-inventory.outputs.scripted_inputs == 'true' && ( github.base_ref == 'main' || github.ref_name == 'main' ) && (needs.setup-workflow.outputs.execute-scripted_inputs == 'Yes' || needs.setup-workflow.outputs.execute-labeled-scripted_inputs == 'true') }}
15331585
needs:
15341586
- build
15351587
- test-inventory
@@ -1730,7 +1782,7 @@ jobs:
17301782
${{ needs.setup.outputs.directory-path }}/diag*
17311783
17321784
run-scripted-input-tests-canary:
1733-
if: ${{ needs.test-inventory.outputs.scripted_inputs == 'true' && ( github.base_ref == 'develop' || github.ref_name == 'develop' ) && needs.setup-workflow.outputs.execute-scripted_inputs == 'Yes' }}
1785+
if: ${{ needs.test-inventory.outputs.scripted_inputs == 'true' && ( github.base_ref == 'develop' || github.ref_name == 'develop' ) && (needs.setup-workflow.outputs.execute-scripted_inputs == 'Yes' || needs.setup-workflow.outputs.execute-labeled-scripted_inputs == 'true') }}
17341786
needs:
17351787
- build
17361788
- test-inventory
@@ -1930,7 +1982,7 @@ jobs:
19301982
${{ needs.setup.outputs.directory-path }}/diag*
19311983
19321984
run-escu-tests:
1933-
if: ${{ needs.test-inventory.outputs.escu == 'true' && ( github.base_ref == 'main' || github.ref_name == 'main' || github.base_ref == 'develop' || github.ref_name == 'develop' ) && needs.setup-workflow.outputs.execute-escu == 'Yes' }}
1985+
if: ${{ needs.test-inventory.outputs.escu == 'true' && ( github.base_ref == 'main' || github.ref_name == 'main' || github.base_ref == 'develop' || github.ref_name == 'develop' ) && (needs.setup-workflow.outputs.execute-escu == 'Yes' || needs.setup-workflow.outputs.execute-labeled-escu == 'true') }}
19341986
needs:
19351987
- build
19361988
- test-inventory

README.md

Lines changed: 27 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,27 @@ General troubleshooting
6161
- Validate If the failure is caused by a code change in the action which modified behaviour in the latest release causing the stage to fail.
6262
6363
64+
setup-workflow
65+
=======================
66+
67+
**Description:**
68+
- Job that is scanning pull_request and based on PR body or included labels defining tests to be executed or infrastructures to be preserved.
69+
- To preserve infrastructure:
70+
- add to PR label `preserve_infra`
71+
- add to PR description add `preserve: {comma separated list of test type}`
72+
- available choices: `knowledge ui modinput_functional scripted_inputs escu requirement_test`
73+
- to trigger tests again, reapply `preserve_infra` label
74+
- To trigger specified test type
75+
- add to PR one or multiple labels
76+
- available choices: `execute_knowledge execute_ui execute_modinput_functional execute_scripted_inputs execute_escu execute_requirement_test execute_all_tests`
77+
- adding labels will result retriggering job
78+
- All tests are executed by default when:
79+
- PR target branch is 'main'
80+
- PUSH event on branches 'main' and 'develop'
81+
- SCHEDULE event
82+
6483
meta stage
65-
==========
84+
=======================
6685

6786
**Description:**
6887

@@ -77,45 +96,6 @@ meta stage
7796
<img src="images/meta/meta_logs.png" alt="meta_logs" style="width:200px;"/>
7897

7998

80-
compliance-sample-scanner
81-
=========================
82-
83-
**Description:**
84-
85-
- This action scans Splunk Add-on test data for potentially identifying information which should be anonymized.
86-
87-
**Action used:** https://github.com/splunk/addonfactory-sample-scanner
88-
89-
90-
**Pass/fail behaviour:**
91-
92-
- The action will check `tests/knowledge/*` for potentially identifying data and update the build or pr with annotations identifying violations.
93-
94-
**Troubleshooting steps for failures if any:**
95-
96-
- Tokenise the sensitive data which is shown in the failures using PSA tool's data generator Data Generator — pytest-splunk-addon documentation
97-
98-
- If you get failures in the .samples or .sample file, replace that value with a token, and add that token's replacement, relevant details
99-
100-
**Exception file:**
101-
102-
- `.ge_ignore` in addon root folder All the false positive can be added in this file.
103-
104-
- ref: https://github.com/splunk/splunk-add-on-for-box/blob/4fe6f4ec2ceaf847211a335f6ca3c154cc805fb7/.ge_ignore
105-
106-
- apart from `.ge_ignore` also `.false-positives.yaml` can be used
107-
108-
- ref: https://github.com/splunk/splunk-add-on-for-microsoft-sysmon/blob/main/.false-positives.yaml
109-
110-
**Artifacts:**
111-
112-
- Annotations, and test report like is also available in stage logs
113-
114-
<img src="images/sample_scanner/annotations.png" alt="annotations" style="width:200px;"/>
115-
<img src="images/sample_scanner/results.png" alt="results" style="width:200px;"/>
116-
<img src="images/sample_scanner/report_link.png" alt="report_link" style="width:200px;"/>
117-
118-
11999
fossa-scan
120100
=======================
121101

@@ -198,7 +178,7 @@ i.e <img src="images/compliance-copyrights/license.png" alt="license" style="wid
198178
199179
200180
lint
201-
====
181+
=======================
202182
203183
**Description:**
204184
@@ -263,7 +243,7 @@ security-detect-secrets
263243
264244
265245
security-sast-semgrep
266-
=====================
246+
=======================
267247
268248
**Description:**
269249
@@ -304,7 +284,7 @@ security-sast-semgrep
304284
- Findings can be observed in the console logs of the stage and also at Semgrep link for which is provided in the end.
305285
306286
test-inventory
307-
==============
287+
=======================
308288
309289
**Description**
310290
@@ -321,7 +301,7 @@ modinput_functional::true
321301
```
322302
323303
Validate PR title
324-
=================
304+
=======================
325305
326306
**Description**
327307
@@ -350,7 +330,7 @@ feat(ui): Add Button component.
350330
See https://www.conventionalcommits.org/ for more examples.
351331
352332
build
353-
=====
333+
=======================
354334
355335
**Description**
356336
@@ -385,7 +365,7 @@ installation-update.json
385365
- package-raw
386366
387367
security-virustotal
388-
===================
368+
=======================
389369
390370
**Description**
391371
@@ -400,7 +380,7 @@ GitHub Action to upload and scan files with VirusTotal which analyze files, doma
400380
401381
402382
AppInspect
403-
==========
383+
=======================
404384
405385
**Description**
406386

0 commit comments

Comments
 (0)