Skip to content

Commit 8adf4a0

Browse files
feat: skip tests on docs only change (#389)
### Description [ [ADDON-78394](https://splunk.atlassian.net/browse/ADDON-78394) ] Added conditions skip tests, build, app-inspect and publish if the changes in PR are only related to documentation. Tests: https://docs.google.com/document/d/1IFxbIwzDM0lBkO3ciNxFrPlOPPE9YQhcaVStQg7lYEM/edit?usp=sharing ### Checklist - [ ] `README.md` has been updated or is not required - [ ] push trigger tests - [ ] manual release test - [ ] automated releases test - [ ] pull request trigger tests - [ ] schedule trigger tests - [ ] workflow errors/warnings reviewed and addressed ### Testing done (for each selected checkbox, the corresponding test results link should be listed here)
1 parent 92a7bdf commit 8adf4a0

File tree

1 file changed

+43
-6
lines changed

1 file changed

+43
-6
lines changed

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

+43-6
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,37 @@ jobs:
122122
exit 1
123123
fi
124124
125+
check-docs-changes:
126+
runs-on: ubuntu-latest
127+
outputs:
128+
docs-only: ${{ steps.check.outputs.docs-only }}
129+
steps:
130+
- name: Checkout code
131+
uses: actions/checkout@v4
132+
133+
- name: Fetch all refs
134+
run: git fetch --prune --unshallow
135+
136+
- name: Check if the changes are only in docs/*, mkdocs.yml, or .github/workflows/docs.yml
137+
id: check
138+
run: |
139+
set -o xtrace
140+
# List all files modified in the commit or PR
141+
changed_files=$(git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.sha }})
142+
# changed_files=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }})
143+
144+
# Check if any of the changed files are not in docs/*, mkdocs.yml, or .github/workflows/docs.yml
145+
if echo "$changed_files" | grep -vqE '^(docs/|mkdocs.yml|.github/workflows/docs.yml)'; then
146+
echo "docs-only=false" >> "$GITHUB_OUTPUT"
147+
else
148+
echo "Only documentation changes found."
149+
echo "docs-only=true" >> "$GITHUB_OUTPUT"
150+
fi
151+
125152
setup-workflow:
126153
runs-on: ubuntu-latest
154+
needs:
155+
- check-docs-changes
127156
outputs:
128157
execute-knowledge-labeled: ${{ steps.configure-tests-on-labels.outputs.execute_knowledge_labeled }}
129158
execute-spl2-labeled: ${{ steps.configure-tests-on-labels.outputs.execute_spl2_labeled }}
@@ -169,7 +198,9 @@ jobs:
169198
case "${{ github.event_name }}" in
170199
"pull_request")
171200
labels=$(echo '${{ toJSON(github.event.pull_request.labels) }}' | jq -r '.[] | .name')
172-
if ${{ github.base_ref == 'main' }} && ${{ contains(github.event.pull_request.labels.*.name, 'use_labels') }}; then
201+
if ${{ needs.check-docs-changes.outputs.docs-only == 'true' }}; then
202+
echo -e "\033[1;33m⚠️ Skipping tests as there are only documentation related changes ⚠️\033[0m"
203+
elif ${{ github.base_ref == 'main' }} && ${{ contains(github.event.pull_request.labels.*.name, 'use_labels') }}; then
173204
for test_type in "${TESTSET[@]}"; do
174205
if [[ "$labels" =~ $test_type ]]; then
175206
EXECUTE_LABELED["$test_type"]="true"
@@ -381,6 +412,8 @@ jobs:
381412

382413
test-inventory:
383414
runs-on: ubuntu-latest
415+
needs:
416+
- check-docs-changes
384417
# Map a step output to a job output
385418
outputs:
386419
spl2: ${{ steps.testset.outputs.spl2 }}
@@ -396,8 +429,8 @@ jobs:
396429
- id: testset
397430
name: Check available test types
398431
run: |
399-
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
400-
find package/default/data -type d -name "spl2" -maxdepth 1 -mindepth 1 | sed 's|^package/default/data/||g' | while read -r TESTSET; do echo "$TESTSET=true" >> "$GITHUB_OUTPUT"; echo "$TESTSET::true"; done
432+
find tests -type d -maxdepth 1 -mindepth 1 | sed 's|^tests/||g' | while read -r TESTSET; do echo "$TESTSET=${{ needs.check-docs-changes.outputs.docs-only == 'false' && 'true' || 'false' }}" >> "$GITHUB_OUTPUT"; echo "$TESTSET::${{ needs.check-docs-changes.outputs.docs-only == 'false' && 'true' || 'false' }}"; done
433+
find package/default/data -type d -name "spl2" -maxdepth 1 -mindepth 1 | sed 's|^package/default/data/||g' | while read -r TESTSET; do echo "$TESTSET=${{ needs.check-docs-changes.outputs.docs-only == 'false' && 'true' || 'false' }}" >> "$GITHUB_OUTPUT"; echo "$TESTSET::${{ needs.check-docs-changes.outputs.docs-only == 'false' && 'true' || 'false' }}"; done
401434
402435
run-unit-tests:
403436
name: test-unit-python3-${{ matrix.python-version }}
@@ -540,6 +573,7 @@ jobs:
540573
build:
541574
runs-on: ubuntu-22.04
542575
needs:
576+
- check-docs-changes
543577
- validate-custom-version
544578
- setup-workflow
545579
- test-inventory
@@ -550,7 +584,7 @@ jobs:
550584
- semgrep
551585
- run-unit-tests
552586
- fossa-scan
553-
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') }}
587+
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') }}
554588
outputs:
555589
buildname: ${{ steps.buildupload.outputs.name }}
556590
permissions:
@@ -728,6 +762,7 @@ jobs:
728762
build-3_9:
729763
runs-on: ubuntu-latest
730764
needs:
765+
- check-docs-changes
731766
- validate-custom-version
732767
- setup-workflow
733768
- test-inventory
@@ -741,7 +776,8 @@ jobs:
741776
if: |
742777
always() &&
743778
(needs.run-unit-tests-3_9.result == 'success' || needs.run-unit-tests-3_9.result == 'skipped') &&
744-
(needs.validate-custom-version.result == 'success' || needs.validate-custom-version.result == 'skipped')
779+
(needs.validate-custom-version.result == 'success' || needs.validate-custom-version.result == 'skipped') &&
780+
(needs.check-docs-changes.outputs.docs-only == 'false')
745781
permissions:
746782
contents: write
747783
packages: read
@@ -2903,6 +2939,7 @@ jobs:
29032939
outputs:
29042940
run-publish: ${{ steps.check.outputs.run-publish }}
29052941
needs:
2942+
- check-docs-changes
29062943
- validate-custom-version
29072944
- meta
29082945
- compliance-copyrights
@@ -2928,7 +2965,7 @@ jobs:
29282965
shell: bash
29292966
run: |
29302967
RUN_PUBLISH=$(echo "$NEEDS" | jq ".[] | select( ( .result != \"skipped\" ) and .result != \"success\" ) | length == 0")
2931-
if [[ "$RUN_PUBLISH" != *'false'* ]]
2968+
if [[ "$RUN_PUBLISH" != *'false'* ]] && [[ "${{ needs.check-docs-changes.outputs.docs-only }}" == 'false' ]]
29322969
then
29332970
echo "run-publish=true" >> "$GITHUB_OUTPUT"
29342971
echo "Publish conditions are met."

0 commit comments

Comments
 (0)