Skip to content

Commit 86974df

Browse files
committed
Only run unit-testing when there's something to test
1 parent b924b36 commit 86974df

1 file changed

Lines changed: 22 additions & 17 deletions

File tree

.github/workflows/unit-testing.yml

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ name: unit-testing
22
on:
33
pull_request:
44
types: [opened, reopened, synchronize]
5+
paths:
6+
- detections/**
7+
- data_sources/**
8+
- lookups/**
9+
- macros/**
510
jobs:
611
unit-testing:
712
runs-on: large-ubuntu-22.04-32core
@@ -13,16 +18,16 @@ jobs:
1318
with:
1419
repository: 'splunk/security_content' #this should be the TARGET repo of the PR. we hardcode it for now
1520
ref: ${{ github.base_ref }}
16-
21+
1722
- name: Print out information abour PR target
1823
run: |
1924
echo "The PR target branch is: ${{ github.base_ref }}"
2025
echo "The PR head branch is: ${{ github.head_ref }}"
2126
echo "My current branch is"
2227
git branch --show-current
2328
git rev-parse HEAD
24-
25-
29+
30+
2631
- name: Set up Python
2732
uses: actions/setup-python@v6
2833
with:
@@ -34,38 +39,38 @@ jobs:
3439
run: |
3540
echo "- Build Tool Version - $(cat requirements.txt)"
3641
pip install -r requirements.txt
37-
42+
3843
# Check out the PR, even if it lives in a fork.
39-
# Instructions for pulling a PR were taken from:
44+
# Instructions for pulling a PR were taken from:
4045
# https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally
4146
- name: Checkout the PR branch and the target to calculate changed files for testing
4247
run: |
43-
48+
4449
echo "Current Branch (Head Ref): ${{ github.head_ref }}"
4550
echo "Target Branch (Base Ref): ${{ github.base_ref }}"
4651
git pull > /dev/null 2>&1
4752
#We checkout into a new branch - new_branch_for_testing to avoid name collisions with develop incase the forked PR is from develop
4853
git fetch origin pull/${{ github.event.pull_request.number }}/head:new_branch_for_testing
49-
#We must specifically get the PR's target branch from security_content, not the one that resides in the fork PR's forked repo
54+
#We must specifically get the PR's target branch from security_content, not the one that resides in the fork PR's forked repo
5055
git switch new_branch_for_testing
51-
56+
5257
- name: Run a contentctl-ng build command to create a package that will be tested.
5358
run: |
5459
contentctl-ng build
55-
60+
5661
- name: Start the test environment
5762
run: |
5863
docker run -d --platform linux/amd64 -p 8088:8088 -p 8089:8089 -p 8000:8000 -e 'SPLUNK_START_ARGS=--accept-license' -e 'SPLUNK_GENERAL_TERMS=--accept-sgt-current-at-splunk-com' -e 'SPLUNK_PASSWORD=Chang3d!' --name splunk splunk/splunk:latest
5964
# Wait some time for this environment to be ready
6065
sleep 180
61-
66+
6267
- name: Run a contentctl-ng install to configure the testing environment
6368
env:
6469
APPINSPECTUSERNAME: "${{ secrets.APPINSPECTUSERNAME }}"
65-
APPINSPECTPASSWORD: "${{ secrets.APPINSPECTPASSWORD }}"
70+
APPINSPECTPASSWORD: "${{ secrets.APPINSPECTPASSWORD }}"
6671
run : |
67-
contentctl-ng install --splunkbase-username "$APPINSPECTUSERNAME" --splunkbase-password "$APPINSPECTPASSWORD"
68-
72+
contentctl-ng install --splunkbase-username "$APPINSPECTUSERNAME" --splunkbase-password "$APPINSPECTPASSWORD"
73+
6974
- name: Test content which has changed between this branch and the target branch
7075
run: |
7176
contentctl-ng test --verbose --post-test-behavior NEVER_PAUSE --mode CHANGED --git-ref ${{ github.base_ref }}
@@ -81,15 +86,15 @@ jobs:
8186
test_results/summary.yml
8287
dist/*.tar.gz
8388
84-
# Print entire result summary so that the users can view it in the Github Actions logs
89+
# Print entire result summary so that the users can view it in the Github Actions logs
8590
- name: Print entire test_results/summary.yml
8691
if: always()
8792
run: cat test_results/summary.yml
8893

8994
# Run a simple custom script created to pretty print results in a markdown friendly format in Github Actions Summary
9095
- name: Check the test_results/summary.yml for pass/fail.
9196
if: always()
92-
run: |
93-
echo "This job will fail if there are failures in unit-testing"
97+
run: |
98+
echo "This job will fail if there are failures in unit-testing"
9499
python .github/workflows/format_test_results.py >> $GITHUB_STEP_SUMMARY
95-
echo "The Unit testing is completed. See details in the unit-testing job summary UI "
100+
echo "The Unit testing is completed. See details in the unit-testing job summary UI "

0 commit comments

Comments
 (0)