-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(testing): run tests in modified packages only #4214
base: main
Are you sure you want to change the base?
Conversation
current testing logic also ensures modules *under* these packages are also tested.
GO_CHANGED_MODULES=${GO_CHANGED_MODULES:-./go.mod} | ||
# Exclude the root module, if present, from the list of sub-modules. | ||
GO_CHANGED_SUBMODULES=${GO_CHANGED_MODULES#./go.mod} | ||
GO_CHANGED_MODULES="$(find ${GO_CHANGED_PKGS:-.} -name go.mod | xargs --no-run-if-empty dirname)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to execute the steps but encountered these problems:
GO_CHANGED_PKGS
would contain a list of go files, not a list of foldersGO_CHANGED_MODULES
does not contain the modified modules
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe dirname
could help:
$ dirname vertexai/chat/chat.go
vertexai/chat
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking a look at this!
I've added dirname to this pipeline, and to make future changes easier, i've allowed us to set $GIT_CHANGES locally to enable better testability here.
So running GIT_CHANGES="functions/functionsv2/firebase/hellofirestore/go.mod compute/instances/foo.go" sh testing/kokoro/system_tests.sh
will show (among other things): GO_CHANGED_PKGS='compute/instances functions/functionsv2/firebase/hellofirestore'
the script stops when it tries to read the nonexistant kokoro credentials, but this is still an improvement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Now the value of GO_CHANGED_MODULES
looks good, but I can't see it used anywhere in the script?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's correct. the module-based approach was never fully implemented, so these variables are informational only.
also enables local debugging by setting $GIT_CHANGES
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this looks good to me. I wasn't able to get some of the specific script elements working locally on Mac but it makes sense.
# CHANGED_DIRS is the list of significant top-level directories that changed, | ||
# but weren't deleted by the current PR. | ||
# CHANGED_DIRS will be empty when run on main. | ||
CHANGED_DIRS=$(echo "$SIGNIFICANT_CHANGES" | tr ' ' '\n' | grep "/" | cut -d/ -f1 | sort -u | tr '\n' ' ' | xargs --no-run-if-empty ls -d 2>/dev/null || true) | ||
GO_CHANGED_PKGS=$(echo "$SIGNIFICANT_CHANGES" | tr ' ' '\n' | grep "/" | tr '\n' ' ' | xargs --no-run-if-empty dirname | xargs --no-run-if-empty ls -d 2>/dev/null || true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: Not recognizing the logic indicating these directories are necessarily Go packages. What am I missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A Package is just a directory that contains go code. a Module is a grouping of packages (see https://go.dev/ref/mod#modules-overview).
We are not looking for the module that contains the modified packages, we are just testing the modified packages themselves. We believe this is safe due to the rarity of inter-package dependencies, and the use of exhaustive nightly testing.
if we do experience breakage, we can move toward a "find the containing module" approach, but that would be more complex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marc, I tested the modified changes in bash (macOS) and now I can confirm the env var values look good 👍
Before LGTM, I'd want to understand if GO_CHANGED_MODULES
is supposed to be used at all?
@@ -44,25 +44,27 @@ export GOLANG_SAMPLES_E2E_TEST="" | |||
# allow files to be owned by a different user than our current uid. | |||
# Kokoro runs a double-nested container, and UIDs may not match. | |||
git config --global --add safe.directory $(pwd) | |||
GIT_CHANGES=$(git --no-pager diff --name-only main..HEAD) | |||
# Allow $GIT_CHANGES to be set in the env, enabling local testing of the change detection below. | |||
GIT_CHANGES=${GIT_CHANGES:-$(git --no-pager diff --name-only main..HEAD)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The git changes between HEAD
and main
includes the current changes, but they also includes any very recent changes of main
, unrelated to the current changes. Is this intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
main
here is using the current status of the main
branch in your checkout - which is likely missing some of the newest changes to origin/main
. you can make those changes disappear by doing a git pull
on your main
branch, then switching back to the PR branch (and ensuring the PR branch is up to date with main
).
This is not a problem in CI, where we're using a fresh clone of the repo.
We may be able to address this by using origin/main
instead of main
, but that's probably unnecessary for our usage, and i'd like to minimize the behavior change in this PR. If you think this is an important change, you're welcome to file an issue for it.
if [[ -z $GIT_CHANGES && $KOKORO_JOB_NAME != *"system-tests"* ]]; then | ||
echo "No diffs detected. This is unexpected - check above for additional error messages." | ||
exit 2 | ||
fi | ||
SIGNIFICANT_CHANGES=$(git --no-pager diff --name-only main..HEAD | grep -Ev '(\.md$|^\.github)' || true ) | ||
SIGNIFICANT_CHANGES=$(echo $GIT_CHANGES | grep -Ev '(\.md$|^\.github)' || true ) | ||
# CHANGED_DIRS is the list of significant top-level directories that changed, | ||
# but weren't deleted by the current PR. | ||
# CHANGED_DIRS will be empty when run on main. | ||
CHANGED_DIRS=$(echo "$SIGNIFICANT_CHANGES" | tr ' ' '\n' | grep "/" | cut -d/ -f1 | sort -u | tr '\n' ' ' | xargs --no-run-if-empty ls -d 2>/dev/null || true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CHANGED_DIRS
includes new dirs added in the current change, but not the new dirs very recently added in main
. Is this intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand how that's possible, since the git command is the same, and i was not able to reproduce this behavior.
The presence of non-PR changes is dependent on the git clone's current state- could that have changed for you between these commands?
GO_CHANGED_MODULES=${GO_CHANGED_MODULES:-./go.mod} | ||
# Exclude the root module, if present, from the list of sub-modules. | ||
GO_CHANGED_SUBMODULES=${GO_CHANGED_MODULES#./go.mod} | ||
GO_CHANGED_MODULES="$(find ${GO_CHANGED_PKGS:-.} -name go.mod | xargs --no-run-if-empty dirname)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Now the value of GO_CHANGED_MODULES
looks good, but I can't see it used anywhere in the script?
@grayside, @Deleplace Ping. This PR has been awaiting re-review for a week. Could one of you take a look so we can get this speed improvement delivered? |
current testing logic also ensures modules under these packages are
also tested.