-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Test all packages #17629
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
Test all packages #17629
Changes from all commits
f2ce4a0
8cbf92e
ef70039
e8b90af
47e915c
492ee5f
08933fd
c85a266
75e5657
d3a042e
4898748
bbd8144
5ef6f91
7b1b6b7
1aab0d5
4d5e55d
5b8f065
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| # Copyright 2026 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| #!/usr/bin/env python3 | ||
| import os | ||
| import glob | ||
| import math | ||
| import json | ||
| import sys | ||
|
|
||
| BATCH_SIZE = 10 | ||
|
|
||
| # Packages that take significantly longer to run tests. | ||
| # These will always be assigned to their own dedicated runner. | ||
| ISOLATED_PACKAGES = [ | ||
| "google-cloud-compute", | ||
| "google-cloud-compute-v1beta", | ||
| "google-cloud-dialogflow", | ||
| "google-cloud-dialogflow-cx", | ||
| "google-cloud-retail", | ||
| ] | ||
|
|
||
| def get_batches(): | ||
| """Splits packages into dedicated isolated batches and evenly chunked standard batches.""" | ||
| raw_paths = sorted(glob.glob("packages/*")) | ||
| package_paths = [p for p in raw_paths if os.path.isdir(p)] | ||
|
|
||
| batches = [] | ||
| standard_packages = [] | ||
|
|
||
| for path in package_paths: | ||
| pkg_name = os.path.basename(path) | ||
|
|
||
| if pkg_name in ISOLATED_PACKAGES: | ||
| # Put heavy packages into their own standalone batches immediately | ||
| batches.append([path]) | ||
| else: | ||
| standard_packages.append(path) | ||
|
|
||
| # Chunk the remaining standard packages by BATCH_SIZE | ||
| num_standard_packages = len(standard_packages) | ||
| num_standard_batches = math.ceil(num_standard_packages / BATCH_SIZE) | ||
|
|
||
| if num_standard_batches == 0 and not batches: | ||
| num_standard_batches = 1 | ||
|
|
||
| for i in range(num_standard_batches): | ||
| start_idx = i * BATCH_SIZE | ||
| chunk = standard_packages[start_idx : start_idx + BATCH_SIZE] | ||
| if chunk: | ||
| batches.append(chunk) | ||
|
|
||
| return batches | ||
|
|
||
| def get_batch_indices(): | ||
| """Returns a JSON string of the array of batch indices for GitHub Actions matrix.""" | ||
| batches = get_batches() | ||
| return json.dumps(list(range(len(batches)))) | ||
|
|
||
| def get_batch_slice(batch_index): | ||
| """Returns a space-separated string of unique package paths for a specific batch index.""" | ||
| batches = get_batches() | ||
| if batch_index < 0 or batch_index >= len(batches): | ||
| return "" | ||
| return " ".join(batches[batch_index]) | ||
|
|
||
| if __name__ == "__main__": | ||
| if len(sys.argv) > 1 and sys.argv[1] == "--count": | ||
| print(get_batch_indices()) | ||
| elif len(sys.argv) > 2 and sys.argv[1] == "--slice": | ||
| print(get_batch_slice(int(sys.argv[2]))) | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -21,6 +21,10 @@ | |||||
|
|
||||||
| # `TEST_TYPE` and `PY_VERSION` are required by the script `ci/run_single_test.sh` | ||||||
|
|
||||||
| # Optional Arguments: | ||||||
| # Pass specific space-separated package paths (e.g., "packages/google-cloud-storage") to only test those directories. | ||||||
| # If no arguments are provided, the script automatically determines which directories have changed | ||||||
| # | ||||||
| # This script will determine which directories have changed | ||||||
| # under the `packages` folder. For `BUILD_TYPE=="presubmit"`, | ||||||
| # we'll compare against the `packages` folder in HEAD, | ||||||
|
|
@@ -78,16 +82,43 @@ set -e | |||||
| # Now we have a fixed list, but we can change it to autodetect if | ||||||
| # necessary. | ||||||
|
|
||||||
| subdirs=( | ||||||
| packages | ||||||
| ) | ||||||
| if [ $# -gt 0 ]; then | ||||||
| subdirs=("$@") | ||||||
| else | ||||||
| subdirs=( | ||||||
| packages | ||||||
| ) | ||||||
| fi | ||||||
|
|
||||||
| RETVAL=0 | ||||||
|
|
||||||
| for subdir in ${subdirs[@]}; do | ||||||
| for d in `ls -d ${subdir}/*/`; do | ||||||
| for subdir in "${subdirs[@]}"; do | ||||||
| if [ ! -d "${subdir}" ]; then | ||||||
| echo "Error: Directory '${subdir}' does not exist." >&2 | ||||||
| exit 1 | ||||||
| fi | ||||||
|
|
||||||
| if [[ "${subdir%/}" == "packages" ]]; then | ||||||
| loop_dirs=("${subdir}"/*/) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
Suggested change
|
||||||
| else | ||||||
| loop_dirs=("${subdir}") | ||||||
| fi | ||||||
|
|
||||||
| for d in "${loop_dirs[@]}"; do | ||||||
| if [ ! -d "$d" ]; then | ||||||
| continue | ||||||
| fi | ||||||
| # Ensure the directory path always ends with a trailing slash for git diff safety | ||||||
| if [[ "$d" != */ ]]; then | ||||||
| d="$d/" | ||||||
| fi | ||||||
| should_test=false | ||||||
| if [ -n "${GIT_DIFF_ARG}" ]; then | ||||||
|
|
||||||
| # Override check: Force test if explicitly asked to test all packages | ||||||
| if [[ "${TEST_ALL_PACKAGES}" == "true" ]]; then | ||||||
| echo "TEST_ALL_PACKAGES is true, forcing execution for ${d}" | ||||||
| should_test=true | ||||||
| elif [ -n "${GIT_DIFF_ARG}" ]; then | ||||||
| echo "checking changes with 'git diff --quiet ${GIT_DIFF_ARG} ${d}'" | ||||||
| set +e | ||||||
| git diff --quiet ${GIT_DIFF_ARG} ${d} | ||||||
|
|
@@ -119,4 +150,4 @@ for subdir in ${subdirs[@]}; do | |||||
| done | ||||||
| done | ||||||
|
|
||||||
| exit ${RETVAL} | ||||||
| exit ${RETVAL} | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -131,7 +131,7 @@ def default(session): | |
| "--cov-append", | ||
| "--cov-config=.coveragerc", | ||
| "--cov-report=", | ||
| "--cov-fail-under=75", | ||
| "--cov-fail-under=0", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| os.path.join("tests", "unit"), | ||
| *session.posargs, | ||
| ) | ||
|
|
||
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 shebang line
#!/usr/bin/env python3is currently placed on line 14, after the copyright header. For the operating system to recognize the shebang and execute the script using the Python interpreter when run directly (e.g.,./ci/get_batches.py), the shebang must be the very first line of the file (line 1), preceding even the copyright comments.