diff --git a/.github/workflows/bazel_test.yml b/.github/workflows/bazel_test.yml index cbb0f585f4..c221371b26 100644 --- a/.github/workflows/bazel_test.yml +++ b/.github/workflows/bazel_test.yml @@ -27,9 +27,8 @@ permissions: contents: read jobs: - test: + lint: runs-on: [self-hosted, bazel] - steps: - name: Checkout repository uses: actions/checkout@v4 @@ -37,6 +36,14 @@ jobs: lfs: false - name: Check BUILD.bazel dependencies run: ./scripts/check_build_deps.sh --strict + + test: + runs-on: [self-hosted, bazel] + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + lfs: false - name: Run tests run: bazel test --build_event_json_file=test.json //src/test/... //src/main/go/... - name: Collect failed test logs diff --git a/scripts/check_build_deps.sh b/scripts/check_build_deps.sh index 687b6261cd..f3eafb467a 100755 --- a/scripts/check_build_deps.sh +++ b/scripts/check_build_deps.sh @@ -22,11 +22,31 @@ NC='\033[0m' # No Color MODE="${1:-check}" EXIT_CODE=0 +# Cache for expensive bazel query results +LIBRARY_DEPS_CACHE="" +MAIN_DEPS_CACHE="" + +# Get deps of library/ (cached) +get_library_deps() { + if [ -z "$LIBRARY_DEPS_CACHE" ]; then + LIBRARY_DEPS_CACHE=$(bazel query 'deps(//src/main/scala/net/eagle0/eagle/library/...)' 2>/dev/null || true) + fi + echo "$LIBRARY_DEPS_CACHE" +} + +# Get deps of src/main (cached) +get_main_deps() { + if [ -z "$MAIN_DEPS_CACHE" ]; then + MAIN_DEPS_CACHE=$(bazel query 'deps(//src/main/...)' 2>/dev/null || true) + fi + echo "$MAIN_DEPS_CACHE" +} + # Rule 1: src/main should not depend on src/test check_main_depends_on_test() { echo -e "${YELLOW}Checking: src/main should not depend on src/test...${NC}" - violations=$(bazel query 'deps(//src/main/...) intersect //src/test/...' 2>/dev/null || true) + violations=$(get_main_deps | grep "^//src/test/" || true) if [ -n "$violations" ]; then echo -e "${RED}VIOLATION: src/main depends on src/test:${NC}" @@ -43,7 +63,7 @@ check_main_depends_on_test() { check_library_depends_on_scala_proto() { echo -e "${YELLOW}Checking: library/ should not depend on Scala proto types...${NC}" - violations=$(bazel query 'deps(//src/main/scala/net/eagle0/eagle/library/...) intersect //src/main/protobuf/...' 2>/dev/null | grep "_scala_proto" || true) + violations=$(get_library_deps | grep "^//src/main/protobuf/.*_scala_proto$" || true) if [ -z "$violations" ]; then count=0 else @@ -65,7 +85,7 @@ check_library_depends_on_scala_proto() { check_library_depends_on_proto_converters() { echo -e "${YELLOW}Checking: library/ should not depend on proto_converters...${NC}" - violations=$(bazel query 'deps(//src/main/scala/net/eagle0/eagle/library/...) intersect //src/main/scala/net/eagle0/eagle/model/proto_converters/...' 2>/dev/null | grep "^//" || true) + violations=$(get_library_deps | grep "^//src/main/scala/net/eagle0/eagle/model/proto_converters/" || true) if [ -n "$violations" ]; then count=$(echo "$violations" | wc -l | tr -d ' ') @@ -85,7 +105,8 @@ check_library_depends_on_proto_converters() { count_proto_deps() { echo -e "${YELLOW}=== Proto dependency counts ===${NC}" - scala_proto_results=$(bazel query 'deps(//src/main/scala/net/eagle0/eagle/library/...) intersect //src/main/protobuf/...' 2>/dev/null | grep "_scala_proto" || true) + library_deps=$(get_library_deps) + scala_proto_results=$(echo "$library_deps" | grep "^//src/main/protobuf/.*_scala_proto$" || true) if [ -z "$scala_proto_results" ]; then scala_proto_count=0 else @@ -94,7 +115,7 @@ count_proto_deps() { echo "library/ Scala proto deps: $scala_proto_count" # C++/Go proto deps are expected (map generation tools) - all_proto_count=$(bazel query 'deps(//src/main/scala/net/eagle0/eagle/library/...) intersect //src/main/protobuf/...' 2>/dev/null | wc -l | tr -d ' ') + all_proto_count=$(echo "$library_deps" | grep -c "^//src/main/protobuf/" || echo "0") echo "library/ all proto deps (includes C++/Go build tools): $all_proto_count" }