Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# spawn strategy here.
common --enable_bzlmod

# Shared disk cache: pass --disk_cache=<path> via CI or user rc.
# The imported .bazelrc.cache bounds long-lived local cache growth.
import %workspace%/.bazelrc.cache

# Shared Android flags; each nested module imports this file and opts in locally.
Expand Down
14 changes: 9 additions & 5 deletions .bazelrc.cache
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Shared disk cache configuration for long-lived local caches.
# The path is deliberately unset; CI or a user rc supplies it.
# GC bounds limit local growth; the 5m idle collector cannot cap CI uploads.
build --remote_timeout=30

build --experimental_disk_cache_gc_max_size=4G
build --experimental_disk_cache_gc_max_age=7d
# Consume cached actions, publish nothing.
build:cache-read --remote_upload_local_results=false

# Also publish. For CI only, which builds in a pinned environment.
build:cache-write --remote_upload_local_results=true

# Machine-local endpoint and token. Never committed.
try-import %workspace%/.bazelrc.local
42 changes: 37 additions & 5 deletions .github/actions/flutter-bazel/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,23 @@ inputs:
default: >-
examples/demo_app examples/no_plugins examples/pub_plugins
examples/local_plugin/packages/host_app
disk-cache:
description: Optional disk cache path; passed as --disk_cache to Bazel.
cache-mode:
description: >-
Remote cache mode: `read`, `write`, or empty to disable.
required: false
default: ''
cache-host:
description: Remote cache host, without a scheme.
required: false
default: ''
cache-project-id:
description: Remote cache project id, used to build the instance name.
required: false
default: ''
cache-token:
description: >-
Cache token whose scope matches `cache-mode`. Any empty cache input
disables the cache, which is what fork pull requests get.
required: false
default: ''

Expand Down Expand Up @@ -79,11 +94,28 @@ runs:
test --test_output=errors
RC

- name: Bazel disk cache
if: inputs.disk-cache != ''
- name: Remote cache
if: >-
inputs.cache-mode != '' && inputs.cache-token != ''
&& inputs.cache-host != '' && inputs.cache-project-id != ''
shell: bash
env:
CACHE_MODE: ${{ inputs.cache-mode }}
BAZEL_CACHE_BAZEL_REMOTE_CACHE_HOST: ${{ inputs.cache-host }}
BAZEL_CACHE_BAZEL_PROJECT_ID: ${{ inputs.cache-project-id }}
BAZEL_CACHE_BAZEL_REMOTE_CACHE_TOKEN: ${{ inputs.cache-token }}
run: |
echo "build --disk_cache=${{ inputs.disk-cache }}" >> "$HOME/.bazelrc"
set -euo pipefail
case "$CACHE_MODE" in
read|write) ;;
*) echo "unknown cache-mode: $CACHE_MODE" >&2; exit 1 ;;
esac
cat >> "$HOME/.bazelrc" <<RC
build --config=cache-$CACHE_MODE
build --remote_cache=grpcs://${BAZEL_CACHE_BAZEL_REMOTE_CACHE_HOST}
build --remote_instance_name=${BAZEL_CACHE_BAZEL_PROJECT_ID}
build --remote_cache_header='Authorization=Bearer ${BAZEL_CACHE_BAZEL_REMOTE_CACHE_TOKEN}'
RC

# NDK 28+ avoids 4 KB-aligned .so segments that fail on 16 KB-page devices.
- name: Select the NDK
Expand Down
50 changes: 8 additions & 42 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ env:
# Bazelisk release assets are mutable; verify their bytes before execution.
BAZELISK_SHA256_LINUX_AMD64: 5a408715e932c0250d28bd84555f12edbf70117de42f9181691c736eacc4a992
BAZELISK_SHA256_DARWIN_ARM64: cee851f726789227d5561004e9904a52be45c3efb56f8b38b6993d6adbaa0409
BAZEL_CACHE_KEY: bazel-cache-macos-arm64
BAZEL_CACHE_MODE: ${{ github.event_name == 'pull_request' && 'write' || '' }}

jobs:
lint:
Expand Down Expand Up @@ -54,27 +54,13 @@ jobs:
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Shared disk cache path
shell: bash
run: echo "BAZEL_CACHE_DIR=$RUNNER_TEMP/bazel_disk_cache" >> "$GITHUB_ENV"

- name: Restore shared disk cache
if: github.event_name == 'pull_request'
id: restore
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # actions/cache v6.1.0
with:
path: ${{ env.BAZEL_CACHE_DIR }}
key: ${{ env.BAZEL_CACHE_KEY }}-${{ github.run_id }}-${{ github.run_attempt }}
restore-keys: ${{ env.BAZEL_CACHE_KEY }}-

- uses: ./.github/actions/flutter-bazel
with:
flutter-version: ${{ env.FLUTTER_VERSION }}
flutter-sha256: ${{ env.FLUTTER_SHA256 }}
bazelisk-version: ${{ env.BAZELISK_VERSION }}
bazelisk-sha256: ${{ env.BAZELISK_SHA256_DARWIN_ARM64 }}
pub-get: ''
disk-cache: ${{ env.BAZEL_CACHE_DIR }}

- name: bazel test //...
run: |
Expand Down Expand Up @@ -121,19 +107,6 @@ jobs:
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Shared disk cache path
shell: bash
run: echo "BAZEL_CACHE_DIR=$RUNNER_TEMP/bazel_disk_cache" >> "$GITHUB_ENV"

- name: Restore shared disk cache
if: github.event_name == 'pull_request'
id: restore
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # actions/cache v6.1.0
with:
path: ${{ env.BAZEL_CACHE_DIR }}
key: ${{ env.BAZEL_CACHE_KEY }}-${{ github.run_id }}-${{ github.run_attempt }}
restore-keys: ${{ env.BAZEL_CACHE_KEY }}-

- uses: ./.github/actions/flutter-bazel
with:
flutter-version: ${{ env.FLUTTER_VERSION }}
Expand All @@ -142,7 +115,10 @@ jobs:
bazelisk-sha256: ${{ env.BAZELISK_SHA256_DARWIN_ARM64 }}
# Only this example's app module; local_plugin's lives in a subdirectory.
pub-get: ${{ matrix.name == 'local_plugin' && 'examples/local_plugin/packages/host_app' || matrix.directory }}
disk-cache: ${{ env.BAZEL_CACHE_DIR }}
cache-mode: ${{ matrix.name == 'demo_app' && env.BAZEL_CACHE_MODE || '' }}
cache-host: ${{ matrix.name == 'demo_app' && secrets.BAZEL_CACHE_HOST || '' }}
cache-project-id: ${{ matrix.name == 'demo_app' && secrets.BAZEL_CACHE_PROJECT_ID || '' }}
cache-token: ${{ matrix.name == 'demo_app' && secrets.BAZEL_CACHE_TOKEN_RW || '' }}

# Hash gate builds the APKs below; tests run their target guards.
- name: bazel test //...
Expand All @@ -169,20 +145,10 @@ jobs:

- name: Report cache statistics
if: always()
env:
REQUIRE_CACHE_HITS: ${{ matrix.name == 'demo_app' && steps.restore.outputs.cache-matched-key != '' }}
run: |
args=(bazel_example_test_${{ matrix.name }}.log bazel_example_hash_${{ matrix.name }}.log)
if [[ "$REQUIRE_CACHE_HITS" == "true" ]]; then args+=(--require-hits); fi
python3 tools/ci/cache_stats.py "${args[@]}"

# GitHub eviction and one saver enforce quota; keep main cold so the hash gate proves reproducibility.
- name: Save shared disk cache
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && matrix.name == 'demo_app'
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # actions/cache v6.1.0
with:
path: ${{ env.BAZEL_CACHE_DIR }}
key: ${{ env.BAZEL_CACHE_KEY }}-${{ github.run_id }}-${{ github.run_attempt }}
python3 tools/ci/cache_stats.py \
bazel_example_test_${{ matrix.name }}.log \
bazel_example_hash_${{ matrix.name }}.log

gate:
name: Hash table fully claimed
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# Smooth app fixture clone. See docs/package-recipes.md.
/third_party/

.bazelrc.local

.DS_Store

# Gradle caches in nested projects.
Expand Down
1 change: 0 additions & 1 deletion examples/demo_app/.bazelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
common --enable_bzlmod

# Shared cache settings for long-lived local cache growth.
import %workspace%/../../.bazelrc.cache
# Shared Android configuration.
import %workspace%/../../.bazelrc.android
Expand Down
1 change: 0 additions & 1 deletion examples/local_plugin/.bazelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
common --enable_bzlmod

# Shared cache settings for long-lived local cache growth.
import %workspace%/../../.bazelrc.cache
# Shared Android configuration.
import %workspace%/../../.bazelrc.android
Expand Down
1 change: 0 additions & 1 deletion examples/no_plugins/.bazelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
common --enable_bzlmod

# Shared cache settings for long-lived local cache growth.
import %workspace%/../../.bazelrc.cache
# Shared Android configuration.
import %workspace%/../../.bazelrc.android
Expand Down
1 change: 0 additions & 1 deletion examples/pub_plugins/.bazelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
common --enable_bzlmod

# Shared cache settings for long-lived local cache growth.
import %workspace%/../../.bazelrc.cache
# Shared Android configuration.
import %workspace%/../../.bazelrc.android
Expand Down
1 change: 0 additions & 1 deletion tests/consumer/.bazelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
common --enable_bzlmod

# Shared cache settings for long-lived local cache growth.
import %workspace%/../../.bazelrc.cache

# This consumer fixture requires JDK 17 and does not inherit the root Android
Expand Down
Loading