From 5da09f58345f0926b900a30b00dc64672e795ad4 Mon Sep 17 00:00:00 2001 From: Shivani Bhardwaj Date: Fri, 7 Nov 2025 11:46:45 +0530 Subject: [PATCH] workflows: only run the modified tests Running all the tests on PR or push event of suricata-verify is irrelevant as the tests are supposed to be exclusive of one another. Make sure that unless there's a framework or workflows change, only the tests that are modified or added are run. This saves CI resources that would otherwise be unnecessarily spent. This does not affect the testing and coverage of the Suricata codebase as when there's an s-v PR, Suricata's workflow is to clone the entire repo and run all the tests in there. --- .github/workflows/builds.yml | 54 ++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index 9bbdf1b62..db666d018 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -9,7 +9,7 @@ concurrency: cancel-in-progress: true jobs: - + pcapng-check: name: PCAP Check runs-on: ubuntu-22.04 @@ -18,10 +18,51 @@ jobs: - run: ./pcapng-check.sh - run: ./pcap-check.sh + isolate-tests: + name: Isolate relevant tests + runs-on: ubuntu-22.04 + outputs: + test_names: ${{ steps.fetch_changed_files.outputs.args }} + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - id: fetch_changed_files + name: Getting changed test names + run: | + case '${{ github.event_name }}' in + pull_request) + firstCommit=${{ github.event.pull_request.base.sha }} + lastCommit=${{ github.event.pull_request.head.sha }} + # Get names of all dirs changed in a PR + dirnames=$(git diff --name-only "${firstCommit}" "${lastCommit}" | xargs dirname | sort -u) + echo "Dirnames: $dirnames" + + # check iff tests/ dir has changed + only_tests=1 + for dir in $dirnames; do + if [[ $dir != tests/* ]]; then + echo "$dir is not tests/" + only_tests=0 + break + fi + done + + if [ $only_tests == 1 ]; then + # Get the names of the innermost test dir + testnames=$(echo "$dirnames" | xargs -I {} basename "{}" | tr '\n' ' ') + echo "PR diff shows a change was done in test dirs. Running $testnames" + final_tests=$(echo "--exact $testnames") + fi + ;; + esac + echo "args=$final_tests" >> "$GITHUB_OUTPUT" + ubuntu-22-04: name: Ubuntu 22.04 runs-on: ubuntu-22.04 container: ubuntu:22.04 + needs: isolate-tests strategy: fail-fast: false matrix: @@ -87,12 +128,13 @@ jobs: make -j2 - name: Running suricata-verify working-directory: suricata - run: python3 ../run.py --quiet --outdir /tmp/sv-output + run: python3 ../run.py ${{ needs.isolate-tests.outputs.test_names }} --quiet --outdir /tmp/sv-output almalinux: name: AlmaLinux 8 runs-on: ubuntu-latest container: almalinux:8 + needs: isolate-tests strategy: fail-fast: false matrix: @@ -155,11 +197,12 @@ jobs: make -j2 - name: Running suricata-verify working-directory: suricata - run: python3 ../run.py --quiet + run: python3 ../run.py ${{ needs.isolate-tests.outputs.test_names }} --quiet macos: name: macOS runs-on: macos-latest + needs: isolate-tests strategy: fail-fast: false matrix: @@ -209,11 +252,12 @@ jobs: working-directory: suricata run: | . ../testenv/bin/activate - python3 ../run.py --quiet + python3 ../run.py ${{ needs.isolate-tests.outputs.test_names }} --quiet windows: name: Windows runs-on: windows-latest + needs: isolate-tests strategy: fail-fast: false matrix: @@ -261,4 +305,4 @@ jobs: make -j3 - name: Running suricata-verify working-directory: suricata - run: python3 ../run.py --quiet + run: python3 ../run.py ${{ needs.isolate-tests.outputs.test_names }} --quiet -- 2.47.3