-
-
Notifications
You must be signed in to change notification settings - Fork 8k
/
should-workflow-run.sh
executable file
·49 lines (39 loc) · 1.41 KB
/
should-workflow-run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/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"}
BAZEL_TARGET_PREFIX=${BAZEL_TARGET_PREFIX:-""}
echo ${COMMIT_RANGE}
# Go to the root of the repo
cd "$(git rev-parse --show-toplevel)" || true
# 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.
bazel_targets=()
for bazel_target in $affected_files ; do
bazel_targets+=($(bazel query "$bazel_target"))
bazel query "$bazel_target"
done
echo "{bazel-targets}=${bazel_targets[*]}" >> $GITHUB_OUTPUT
echo "{run-workflow}=false" >> $GITHUB_OUTPUT
if (( ${#bazel_targets[@]} == 0 )); then
echo "No bazel targets found after checking the diff."
exit 0
fi
if [[ " ${bazel_targets[*]} " == *"$BAZEL_TARGET_PREFIX"* ]]; then
echo "{run-workflow}=true" >> $GITHUB_OUTPUT
echo "Bazel targets found: ${bazel_targets[*]}"
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
tests=$(bazel query \
--keep_going \
--noshow_progress \
"kind(test, rdeps(//..., set(${bazel_targets[*]})))")
if [[ " ${tests[*]} " == *"$BAZEL_TARGET_PREFIX"* ]]; then
echo "{run-workflow}=true" >> $GITHUB_OUTPUT
echo "Test targets found: ${tests[*]}"
exit 0
fi