Skip to content

Conversation

@inashivb
Copy link
Member

@inashivb inashivb commented Nov 7, 2025

Previous PR: #2743

Changes since v4:

  • cleaned up git history; presentable
  • works correctly:
    • any workflow changes -- all tests must be run
    • only changes in tests/ -- only the respective changed tests must be run
  • made the commands to find this out much simpler

Ticket: None. Should there be one?

Known TODOs:

  • Fail if any of the changed tests are skipped (as follow up work? I have something.)

@inashivb inashivb requested a review from catenacyber November 7, 2025 06:27
@inashivb inashivb added the framework Has a suricata-verify framework change label Nov 7, 2025
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.
@inashivb inashivb force-pushed the run-workflows-only-on-change/v5 branch from 636ea71 to 63bb027 Compare November 7, 2025 07:02
Comment on lines +37 to +56
# 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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I could put all of this in a bash script btw and call it here to make the job even smaller to read.

# check iff tests/ dir has changed
only_tests=1
for dir in $dirnames; do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of loop, single grep -v ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL. Thank you! 🙇🏽‍♀️

fi
;;
esac
echo "args=$final_tests" >> "$GITHUB_OUTPUT"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we go about final_tests here ? and test_names in other jobs ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, should not final_tests be defined also if [ $only_tests != 1 ]; ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we go about final_tests here ? and test_names in other jobs ?

I guess I changed the varname at some point. Do you prefer test_names better?

Also, should not final_tests be defined also if [ $only_tests != 1 ]; ?

It is then set to nothing and we want no args to s-v in such a case so it runs the entire test suite. Is this not what you mean? Please lmk. Thank you!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I changed the varname at some point. Do you prefer test_names better?

No preference, but consistency ;-)

It is then set to nothing

I do not see where...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh. I thought bash variables are declared as and when they're used and set to null unless overridden. Is this an incorrect assumption?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See bash set -u

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you! 🙇🏽‍♀️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

framework Has a suricata-verify framework change

Development

Successfully merging this pull request may close these issues.

2 participants