Skip to content
Latchkey

Bazel Tests workflow (google/differential-privacy)

The Bazel Tests workflow from google/differential-privacy, explained and optimized by Latchkey.

C

CI health: C - fair

Point runs-on at Latchkey and get caching, run de-duplication, self-healing for flaky steps, and up to 58% lower cost, applied automatically.

Grade your own workflow free or run it on Latchkey →
Source: google/differential-privacy.github/workflows/bazel.ymlLicense Apache-2.0View source

What it does

This is the Bazel Tests workflow from the google/differential-privacy repository, a real project running GitHub Actions. It is shown here with attribution under its Apache-2.0 license.

Below, Latchkey shows a faster, safer version produced by its optimization engine.

The workflow

workflow (.yml)
name: Bazel Tests

on: [push, pull_request, workflow_dispatch]

jobs:
  cc-tests:
    name: C++ Bazel Tests
    runs-on: ubuntu-latest
    timeout-minutes: 60
    steps:
      - uses: actions/checkout@v6
      - name: Mount Cache
        uses: actions/cache@v5
        with:
          path: ~/.cache/bazel/
          key: bazel-cc-cache
      - name: Install packages for the PostgreSQL extension
        run: sudo apt-get install -y make libreadline-dev bison flex
      - name: Ensure bazelisk is installed
        run: bazelisk --version
      - name: Build C++ Workspace
        working-directory: cc
        run: bazelisk build ...
      - name: Test C++ Workspace (without long and eternal tests)
        working-directory: cc
        run: bazelisk test --test_output=errors --test_timeout_filters=-long,-eternal --test_verbose_timeout_warnings ...
      - name: Build C++ Examples
        working-directory: examples/cc
        run: bazelisk build ...
      - name: Test C++ Examples
        working-directory: examples/cc
        run: bazelisk test --test_output=errors --test_verbose_timeout_warnings ...

  java-tests:
    name: Java Bazel Tests
    runs-on: ubuntu-latest
    timeout-minutes: 60
    steps:
      - uses: actions/checkout@v6
      - name: Mount Cache
        uses: actions/cache@v5
        with:
          path: ~/.cache/bazel/
          key: bazel-java-cache
      - name: Ensure bazelisk is installed
        run: bazelisk --version
      - name: Build Java Workspace
        working-directory: java
        run: bazelisk build ...
      - name: Test Java Workspace (without long and eternal tests)
        working-directory: java
        run: bazelisk test --test_output=errors --test_timeout_filters=-long,-eternal --test_verbose_timeout_warnings ...
      - name: Build Java Examples
        working-directory: examples/java
        run: bazelisk build ...

  pipelinedp4j-tests:
    name: PipelineDP4J Bazel Tests
    runs-on: ubuntu-latest
    timeout-minutes: 60
    steps:
      - uses: actions/checkout@v6
      - name: Mount Cache
        uses: actions/cache@v5
        with:
          path: ~/.cache/bazel/
          key: bazel-pipelinedp4j-cache
      - name: Ensure bazelisk is installed
        run: bazelisk --version
      - name: Build PipelineDP4J Workspace
        working-directory: pipelinedp4j
        run: bazelisk build ...
      - name: Test PipelineDP4J Workspace (without long and eternal tests)
        working-directory: pipelinedp4j
        run: bazelisk test --test_output=errors --test_timeout_filters=-long,-eternal --test_verbose_timeout_warnings ...
      - name: Create dummy input file for examples
        working-directory: examples/pipelinedp4j
        run: |
          cat << EOF > input.csv
          4505,573364,5,2004-13-29
          4501,2532865,4,2005-11-06
          4501,573364,2,2005-02-25
          4500,2532865,2,2004-12-12
          4505,1265574,4,2003-05-05
          4505,2532865,1,2004-12-12
          EOF
      - name: Run Beam Example
        working-directory: examples/pipelinedp4j
        run: bazelisk run beam/src/main/java/com/google/privacy/differentialprivacy/pipelinedp4j/examples:BeamExample -- --inputFilePath="$(pwd)/input.csv" --outputFilePath="$(pwd)/output.txt"
      - name: Run Spark Example
        working-directory: examples/pipelinedp4j
        run: bazelisk run spark/src/main/java/com/google/privacy/differentialprivacy/pipelinedp4j/examples:SparkExample -- --inputFilePath="$(pwd)/input.csv" --outputFolder="$(pwd)/output"
      - name: Run Spark DataFrame Example
        working-directory: examples/pipelinedp4j
        run: bazelisk run spark/src/main/java/com/google/privacy/differentialprivacy/pipelinedp4j/examples:SparkDataFrameExample -- --inputFilePath="$(pwd)/input.csv" --outputFolder="$(pwd)/output"

  zetasql-build:
    name: ZetaSQL Examples Build Test
    runs-on: ubuntu-latest
    timeout-minutes: 60
    steps:
      - uses: actions/checkout@v6
      - name: Mount Cache
        uses: actions/cache@v5
        with:
          path: ~/.cache/bazel/
          key: bazel-zetasql-examples-cache
      - name: Ensure bazelisk is installed
        run: bazelisk --version
      - name: Build ZetaSQL Examples
        working-directory: examples/zetasql
        run: bazelisk build ...

  python-tests:
    name: Python Tests
    runs-on: ubuntu-latest
    timeout-minutes: 60
    steps:
      - uses: actions/checkout@v6
      - name: Set up Python 3.10
        uses: actions/setup-python@v6
        with:
          python-version: '3.10'
      - name: Install Python dependencies
        run: |
          python -m pip install --upgrade pip
          python -m pip install --upgrade setuptools
      - name: Mount Cache
        uses: actions/cache@v5
        with:
          path: ~/.cache/bazel/
          key: bazel-python-cache
      - name: Ensure bazelisk is installed
        run: bazelisk --version
      # TODO: Remove the --use-pep517 flag when migrating to Python Wheel.
      # `pip check` is required since `pip install` always terminates successfully, even on errors.
      - name: Build and Test dp_accounting
        working-directory: python/dp_accounting
        run: |
          bazelisk build ...
          bazelisk test --test_output=errors --test_timeout_filters=-long,-eternal --test_verbose_timeout_warnings ...
          python3 -m venv ./venv
          ./venv/bin/python3 -m pip install --use-pep517 .
          ./venv/bin/python3 -m pip check .
          ./venv/bin/python3 -m unittest discover -p '*_test.py'
          rm -rf ./venv
      - name: Build and Test dp_auditorium
        working-directory: python/dp_auditorium
        run: |
          bazelisk build ...
          bazelisk test --test_output=errors --test_timeout_filters=-long,-eternal --test_verbose_timeout_warnings ...
          python3 -m venv ./venv
          ./venv/bin/python3 -m pip install --use-pep517 .
          ./venv/bin/python3 -m pip check .
          ./venv/bin/python3 -m unittest discover -p '*_test.py'
          rm -rf ./venv
      - name: Build and Test learning
        working-directory: learning
        run: |
          bazelisk build ...
          bazelisk test --test_output=errors --test_timeout_filters=-eternal --test_tag_filters=-nokokoro --test_verbose_timeout_warnings ...
          python3 -m venv ./venv
          ./venv/bin/python3 -m pip install --use-pep517 .
          ./venv/bin/python3 -m pip check .
          ./venv/bin/python3 -m unittest discover -p '*_test.py'
          rm -rf ./venv

The same workflow, on Latchkey

Estimated ~20% faster on cache hits, plus fewer wasted runs and a safer supply chain. Added and changed lines are highlighted.

name: Bazel Tests
 
on: [push, pull_request, workflow_dispatch]
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  cc-tests:
    name: C++ Bazel Tests
    runs-on: latchkey-small
    timeout-minutes: 60
    steps:
      - uses: actions/checkout@v6
      - name: Mount Cache
        uses: actions/cache@v5
        with:
          path: ~/.cache/bazel/
          key: bazel-cc-cache
      - name: Install packages for the PostgreSQL extension
        run: sudo apt-get install -y make libreadline-dev bison flex
      - name: Ensure bazelisk is installed
        run: bazelisk --version
      - name: Build C++ Workspace
        working-directory: cc
        run: bazelisk build ...
      - name: Test C++ Workspace (without long and eternal tests)
        working-directory: cc
        run: bazelisk test --test_output=errors --test_timeout_filters=-long,-eternal --test_verbose_timeout_warnings ...
      - name: Build C++ Examples
        working-directory: examples/cc
        run: bazelisk build ...
      - name: Test C++ Examples
        working-directory: examples/cc
        run: bazelisk test --test_output=errors --test_verbose_timeout_warnings ...
 
  java-tests:
    name: Java Bazel Tests
    runs-on: latchkey-small
    timeout-minutes: 60
    steps:
      - uses: actions/checkout@v6
      - name: Mount Cache
        uses: actions/cache@v5
        with:
          path: ~/.cache/bazel/
          key: bazel-java-cache
      - name: Ensure bazelisk is installed
        run: bazelisk --version
      - name: Build Java Workspace
        working-directory: java
        run: bazelisk build ...
      - name: Test Java Workspace (without long and eternal tests)
        working-directory: java
        run: bazelisk test --test_output=errors --test_timeout_filters=-long,-eternal --test_verbose_timeout_warnings ...
      - name: Build Java Examples
        working-directory: examples/java
        run: bazelisk build ...
 
  pipelinedp4j-tests:
    name: PipelineDP4J Bazel Tests
    runs-on: latchkey-small
    timeout-minutes: 60
    steps:
      - uses: actions/checkout@v6
      - name: Mount Cache
        uses: actions/cache@v5
        with:
          path: ~/.cache/bazel/
          key: bazel-pipelinedp4j-cache
      - name: Ensure bazelisk is installed
        run: bazelisk --version
      - name: Build PipelineDP4J Workspace
        working-directory: pipelinedp4j
        run: bazelisk build ...
      - name: Test PipelineDP4J Workspace (without long and eternal tests)
        working-directory: pipelinedp4j
        run: bazelisk test --test_output=errors --test_timeout_filters=-long,-eternal --test_verbose_timeout_warnings ...
      - name: Create dummy input file for examples
        working-directory: examples/pipelinedp4j
        run: |
          cat << EOF > input.csv
          4505,573364,5,2004-13-29
          4501,2532865,4,2005-11-06
          4501,573364,2,2005-02-25
          4500,2532865,2,2004-12-12
          4505,1265574,4,2003-05-05
          4505,2532865,1,2004-12-12
          EOF
      - name: Run Beam Example
        working-directory: examples/pipelinedp4j
        run: bazelisk run beam/src/main/java/com/google/privacy/differentialprivacy/pipelinedp4j/examples:BeamExample -- --inputFilePath="$(pwd)/input.csv" --outputFilePath="$(pwd)/output.txt"
      - name: Run Spark Example
        working-directory: examples/pipelinedp4j
        run: bazelisk run spark/src/main/java/com/google/privacy/differentialprivacy/pipelinedp4j/examples:SparkExample -- --inputFilePath="$(pwd)/input.csv" --outputFolder="$(pwd)/output"
      - name: Run Spark DataFrame Example
        working-directory: examples/pipelinedp4j
        run: bazelisk run spark/src/main/java/com/google/privacy/differentialprivacy/pipelinedp4j/examples:SparkDataFrameExample -- --inputFilePath="$(pwd)/input.csv" --outputFolder="$(pwd)/output"
 
  zetasql-build:
    name: ZetaSQL Examples Build Test
    runs-on: latchkey-small
    timeout-minutes: 60
    steps:
      - uses: actions/checkout@v6
      - name: Mount Cache
        uses: actions/cache@v5
        with:
          path: ~/.cache/bazel/
          key: bazel-zetasql-examples-cache
      - name: Ensure bazelisk is installed
        run: bazelisk --version
      - name: Build ZetaSQL Examples
        working-directory: examples/zetasql
        run: bazelisk build ...
 
  python-tests:
    name: Python Tests
    runs-on: latchkey-small
    timeout-minutes: 60
    steps:
      - uses: actions/checkout@v6
      - name: Set up Python 3.10
        uses: actions/setup-python@v6
        with:
          cache: 'pip'
          python-version: '3.10'
      - name: Install Python dependencies
        run: |
          python -m pip install --upgrade pip
          python -m pip install --upgrade setuptools
      - name: Mount Cache
        uses: actions/cache@v5
        with:
          path: ~/.cache/bazel/
          key: bazel-python-cache
      - name: Ensure bazelisk is installed
        run: bazelisk --version
      # TODO: Remove the --use-pep517 flag when migrating to Python Wheel.
      # `pip check` is required since `pip install` always terminates successfully, even on errors.
      - name: Build and Test dp_accounting
        working-directory: python/dp_accounting
        run: |
          bazelisk build ...
          bazelisk test --test_output=errors --test_timeout_filters=-long,-eternal --test_verbose_timeout_warnings ...
          python3 -m venv ./venv
          ./venv/bin/python3 -m pip install --use-pep517 .
          ./venv/bin/python3 -m pip check .
          ./venv/bin/python3 -m unittest discover -p '*_test.py'
          rm -rf ./venv
      - name: Build and Test dp_auditorium
        working-directory: python/dp_auditorium
        run: |
          bazelisk build ...
          bazelisk test --test_output=errors --test_timeout_filters=-long,-eternal --test_verbose_timeout_warnings ...
          python3 -m venv ./venv
          ./venv/bin/python3 -m pip install --use-pep517 .
          ./venv/bin/python3 -m pip check .
          ./venv/bin/python3 -m unittest discover -p '*_test.py'
          rm -rf ./venv
      - name: Build and Test learning
        working-directory: learning
        run: |
          bazelisk build ...
          bazelisk test --test_output=errors --test_timeout_filters=-eternal --test_tag_filters=-nokokoro --test_verbose_timeout_warnings ...
          python3 -m venv ./venv
          ./venv/bin/python3 -m pip install --use-pep517 .
          ./venv/bin/python3 -m pip check .
          ./venv/bin/python3 -m unittest discover -p '*_test.py'
          rm -rf ./venv
 

What changed

What Latchkey heals here

This workflow has steps that commonly fail on transient issues (network, registries, flaky browsers). On Latchkey managed runners they are detected, retried, and self-healed instead of failing your build:

This workflow runs 5 jobs per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow