This is an automated email from the ASF dual-hosted git repository.

chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fory.git


The following commit(s) were added to refs/heads/main by this push:
     new 91fa14d0c feat(ci): cache Bazel binary in Python CI workflow (#2745)
91fa14d0c is described below

commit 91fa14d0c2f4cfacae8aa5c976414e99bbfec2c9
Author: Sanyam Suyal <[email protected]>
AuthorDate: Sun Oct 12 20:32:00 2025 +0530

    feat(ci): cache Bazel binary in Python CI workflow (#2745)
    
    ### Problem
    Fixes #2742
    
    Python CI downloads Bazel binary on every run, which:
    - Takes 2-5 seconds per run
    - Can fail due to transient network errors
    - Wastes bandwidth and CI resources
    
    ### Solution
    Implemented GitHub Actions caching for Bazel binary to avoid repeated
    downloads.
    
    ### Changes
    - `.github/workflows/ci.yml`: Added actions/cache@v4 step to cache Bazel
    binary
      - Caches ~/bin/bazel and ~/.local/bin/bazel
      - Cache key includes OS, architecture, and Bazel version hash
      - Invalidates cache when Bazel version changes
    
    - `ci/tasks/common.py`: Updated install_bazel() function
      - Checks if cached Bazel binary exists before downloading
      - Verifies cached binary works by running bazel --version
      - Automatically re-downloads if cached binary is corrupted
      - Skips download entirely when cache is valid
    
    ### Testing
    Tested all scenarios:
    - Fresh install (no cache) - downloads successfully
    - Cache hit (valid binary) - skips download, saves time
    - Corrupted cache - detects corruption and recovers automatically
    - All Python syntax and YAML validation passed
    
    ### Benefits
    - Faster builds: Saves 2-5 seconds per CI run when cache hits
    - More reliable: Reduces dependency on network availability
    - Cost savings: Less bandwidth usage and shorter CI runtime
    
    ### Related
    Follow-up to #2733 (retry logic for Bazel downloads)
    
    Fixes #2742
---
 .github/workflows/ci.yml |  9 +++++++++
 ci/tasks/common.py       | 26 ++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 3bcf1a32e..aebf651b6 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -283,6 +283,15 @@ jobs:
         uses: actions/setup-python@v5
         with:
           python-version: ${{ matrix.python-version }}
+      - name: Cache Bazel binary
+        uses: actions/cache@v4
+        with:
+          path: |
+            ~/bin/bazel
+            ~/.local/bin/bazel
+          key: bazel-${{ runner.os }}-${{ runner.arch }}-${{ 
hashFiles('.bazelversion') }}
+          restore-keys: |
+            bazel-${{ runner.os }}-${{ runner.arch }}-
       - name: Install bazel (Unix)
         if: runner.os != 'Windows'
         shell: bash
diff --git a/ci/tasks/common.py b/ci/tasks/common.py
index c1393ce86..65ba8b488 100644
--- a/ci/tasks/common.py
+++ b/ci/tasks/common.py
@@ -144,6 +144,32 @@ def update_shell_profile():
 
 def install_bazel():
     """Download and install bazel."""
+    # Check if bazel is already cached (from GitHub Actions cache)
+    if not is_windows():
+        home_bin = os.path.expanduser("~/bin")
+        bazel_path = os.path.join(home_bin, "bazel")
+
+        # Also check ~/.local/bin for some systems
+        alt_bin = os.path.expanduser("~/.local/bin")
+        alt_bazel_path = os.path.join(alt_bin, "bazel")
+
+        for path in [bazel_path, alt_bazel_path]:
+            if os.path.exists(path) and os.access(path, os.X_OK):
+                logging.info(f"Bazel already exists at {path}, verifying...")
+                try:
+                    # Verify it works
+                    result = exec_cmd(f"{path} --version")
+                    logging.info(f"Cached Bazel binary is valid: 
{result.strip()}")
+                    logging.info("Skipping Bazel download, using cached 
binary")
+                    return
+                except Exception as e:
+                    logging.warning(f"Cached Bazel binary at {path} is 
invalid: {e}")
+                    logging.info("Re-downloading Bazel...")
+                    try:
+                        os.remove(path)
+                    except Exception:
+                        pass
+
     bazel_download_url = get_bazel_download_url()
     logging.info(f"Downloading bazel from: {bazel_download_url}")
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to