diff --git a/.github/workflows/eagle_build.yml b/.github/workflows/eagle_build.yml index 6751de3b6a..893ddea700 100644 --- a/.github/workflows/eagle_build.yml +++ b/.github/workflows/eagle_build.yml @@ -12,6 +12,7 @@ on: - 'BUILD.bazel' - '.bazelrc' - 'ci/github_actions/ensure_bazel_installed.sh' + - 'scripts/build_eagle_ci.sh' - '.github/workflows/eagle_build.yml' concurrency: @@ -51,4 +52,4 @@ jobs: - name: Ensure Bazel installed run: ./ci/github_actions/ensure_bazel_installed.sh - name: Build Eagle server - run: bazel build //src/main/scala/net/eagle0/eagle:eagle_server + run: ./scripts/build_eagle_ci.sh diff --git a/.github/workflows/shardok_build.yml b/.github/workflows/shardok_build.yml index 633c34c388..2525821d08 100644 --- a/.github/workflows/shardok_build.yml +++ b/.github/workflows/shardok_build.yml @@ -13,6 +13,7 @@ on: - 'BUILD.bazel' - '.bazelrc' - 'ci/github_actions/ensure_bazel_installed.sh' + - 'scripts/build_shardok_ci.sh' - '.github/workflows/shardok_build.yml' concurrency: @@ -52,4 +53,4 @@ jobs: - name: Ensure Bazel installed run: ./ci/github_actions/ensure_bazel_installed.sh - name: Build Shardok server - run: bazel build -c opt //src/main/cpp/net/eagle0/shardok:shardok-server + run: ./scripts/build_shardok_ci.sh diff --git a/AGENTS.md b/AGENTS.md index d2513d6c76..f897f84c91 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -105,14 +105,14 @@ Unity Client ↔ Eagle (gRPC streaming) ↔ Shardok (internal gRPC) ### Building ```bash -# Build Eagle server (Scala strategic layer) -bazel build //src/main/scala/net/eagle0/eagle:eagle_server_deploy.jar +# Build Eagle server using the same target as GitHub Actions +./scripts/build_eagle_ci.sh -# Build Shardok server (C++ tactical layer) -bazel build -c opt //src/main/cpp/net/eagle0/shardok:shardok-server +# Build Shardok server using the same target and flags as GitHub Actions +./scripts/build_shardok_ci.sh -# Shardok server includes both AI algorithms -bazel build //src/main/cpp/net/eagle0/shardok:shardok-server +# Warm the remote cache for the main GitHub Actions Bazel builds +./scripts/hydrate_bazel_remote_cache.sh # Build Unity/C# client ./scripts/build_protos.sh # Protocol buffer generation for Unity @@ -165,6 +165,19 @@ bazel run gazelle # Update Go build files The pre-commit hook runs gazelle but only checks if it succeeds - it does NOT verify the BUILD files are in canonical format. The `gazelle_test` will fail if deps are not alphabetically sorted. **Always run gazelle manually after BUILD file changes.** +### Bazel Cache Hydration + +When making changes that will trigger GitHub Actions Bazel builds, run the matching CI script instead of hand-writing +`bazel build` commands. The scripts keep local cache hydration aligned with CI targets, compilation modes, and flags: + +```bash +./scripts/build_eagle_ci.sh +./scripts/build_shardok_ci.sh +./scripts/hydrate_bazel_remote_cache.sh +``` + +Use direct `bazel build` commands only for targeted debugging where CI cache hydration is not the goal. + ### Code Formatting ```bash @@ -225,7 +238,7 @@ ShardokAIClient client(playerId, isDefender, hexMap, settings, AIAlgorithmType:: ```bash # Build the server (includes both AI algorithms) -bazel build //src/main/cpp/net/eagle0/shardok:shardok-server +./scripts/build_shardok_ci.sh # Test both algorithms bazel test //src/test/cpp/net/eagle0/shardok/ai:ai_iterative_deepening_test diff --git a/scripts/build_eagle_ci.sh b/scripts/build_eagle_ci.sh new file mode 100755 index 0000000000..b8865d8a2e --- /dev/null +++ b/scripts/build_eagle_ci.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -euo pipefail + +bazel build //src/main/scala/net/eagle0/eagle:eagle_server diff --git a/scripts/build_shardok_ci.sh b/scripts/build_shardok_ci.sh new file mode 100755 index 0000000000..d68d0931e4 --- /dev/null +++ b/scripts/build_shardok_ci.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -euo pipefail + +bazel build -c opt //src/main/cpp/net/eagle0/shardok:shardok-server diff --git a/scripts/check_bazel_remote_cache_parity.sh b/scripts/check_bazel_remote_cache_parity.sh index e18cf2986f..3e91a66608 100755 --- a/scripts/check_bazel_remote_cache_parity.sh +++ b/scripts/check_bazel_remote_cache_parity.sh @@ -26,35 +26,38 @@ case "$mode" in ;; esac -targets=("$@") -if [ "${#targets[@]}" -eq 0 ]; then - targets=( - "//src/main/cpp/net/eagle0/shardok/library:engine" - "//src/main/scala/net/eagle0/eagle:eagle_server" - ) -fi - tmp_root="${RUNNER_TEMP:-/private/tmp}" run_id="${GITHUB_RUN_ID:-local}-$$" output_base="${tmp_root%/}/eagle0-cache-parity-${mode}-${run_id}" echo "Mode: $mode" echo "Output base: $output_base" -echo "Targets:" -printf ' %s\n' "${targets[@]}" -bazel_args=( - "--output_base=$output_base" - "build" - "--remote_download_all" -) +run_bazel() { + echo "Bazel args:" + printf ' %s\n' "$@" -if [ "$mode" = "verify" ]; then - bazel_args+=( - "--remote_upload_local_results=false" - "--experimental_remote_require_cached" - "--disk_cache=" + local bazel_args=( + "--output_base=$output_base" + "build" + "--remote_download_all" ) + + if [ "$mode" = "verify" ]; then + bazel_args+=( + "--remote_upload_local_results=false" + "--experimental_remote_require_cached" + "--disk_cache=" + ) + fi + + bazel "${bazel_args[@]}" "$@" +} + +if [ "$#" -gt 0 ]; then + run_bazel "$@" + exit 0 fi -bazel "${bazel_args[@]}" "${targets[@]}" +run_bazel //src/main/scala/net/eagle0/eagle:eagle_server +run_bazel -c opt //src/main/cpp/net/eagle0/shardok:shardok-server diff --git a/scripts/hydrate_bazel_remote_cache.sh b/scripts/hydrate_bazel_remote_cache.sh new file mode 100755 index 0000000000..2c3e2c0d6b --- /dev/null +++ b/scripts/hydrate_bazel_remote_cache.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -euo pipefail + +scripts/build_eagle_ci.sh +scripts/build_shardok_ci.sh