Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions scripts/github-actions/check-bazel-targets.sh
Original file line number Diff line number Diff line change
@@ -1,35 +1,44 @@
#!/usr/bin/env bash
# Print commands
# set -x
# Extracted from https://github.com/bazelbuild/bazel/blob/master/scripts/ci/ci.sh

COMMIT_RANGE=${COMMIT_RANGE:-"HEAD^..HEAD"}
set -euo pipefail

COMMIT_RANGE=${COMMIT_RANGE:-"HEAD^..HEAD"}
echo "${COMMIT_RANGE}"

# Go to the root of the repo
cd "$(git rev-parse --show-toplevel)" || true
cd "$(git rev-parse --show-toplevel)"

# Get list of affected files by the diff
affected_files=$(git diff --name-only "${COMMIT_RANGE}")

# Get a list of the current targets in package form by querying Bazel.
# Map changed files to target labels
bazel_targets=()
for bazel_target in $affected_files ; do
bazel_targets+=($(bazel query "$bazel_target"))
for file in $affected_files; do
if query_output=$(bazel query --keep_going --noshow_progress "file(${file})" 2>/dev/null); then
bazel_targets+=(${query_output})
fi
done

if (( ${#bazel_targets[@]} == 0 )); then
echo "No bazel targets found after checking the diff."
exit 0
fi

# Now check if we need to run some tests based on this change
# E.g. A change in Grid needs to trigger remote tests in other bindings
echo "Checking test targets..."
bazel_targets+=($(bazel query \
--keep_going \
--noshow_progress \
"kind(test, rdeps(//..., set(${bazel_targets[*]})))"))
# Only consider test targets under the binding roots
BINDINGS_UNIVERSE="set(//java/... //py/... //rb/... //dotnet/... //javascript/selenium-webdriver/...)"

# Get test targets based on the changes
echo "Getting test targets..."
if query_output=$(bazel query \
--keep_going \
--noshow_progress \
"kind(test, rdeps(${BINDINGS_UNIVERSE}, set(${bazel_targets[@]}))) \
except attr('tags','manual', ${BINDINGS_UNIVERSE})" 2>/dev/null); then
bazel_targets+=(${query_output})
fi

# Return unique set
mapfile -t bazel_targets < <(printf '%s\n' "${bazel_targets[@]}" | sort -u)

echo "bazel-targets='${bazel_targets[*]}'" | tee -a "$GITHUB_OUTPUT"