From 1ecb88d5fde33f4e1d837fa286f722eef045ea5f Mon Sep 17 00:00:00 2001 From: Andreas Herrmann Date: Wed, 18 Dec 2024 11:28:12 +0100 Subject: [PATCH] Avoid remote caching of remote persistent worker demo The test wants to make sure that the actions are executed correct using either the remote persistent worker or running as individual actions on the remote execution system. Caching interferes with this test. This injects a cache-silo-key that changes each time to force a re-run of the action. --- examples/persistent_worker/defs.bzl | 7 +++++++ examples/persistent_worker/test.sh | 22 ++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/examples/persistent_worker/defs.bzl b/examples/persistent_worker/defs.bzl index d1b347233aac..32f976b7154e 100644 --- a/examples/persistent_worker/defs.bzl +++ b/examples/persistent_worker/defs.bzl @@ -34,6 +34,13 @@ def _demo_impl(ctx: AnalysisContext) -> list[Provider]: ctx.actions.run( cmd_args(argfile), category = "demo", + env = { + # modify this value to force an action rerun even if caching is enabled. + # `--no-remote-cache` does not have the desired effect, because it also causes + # the action to be omitted from `buck2 log what-ran`, which interferes with the + # test setup. + "CACHE_SILO_KEY": read_root_config("build", "cache_silo_key", "0"), + }, exe = WorkerRunInfo( worker = ctx.attrs._worker[WorkerInfo], exe = ctx.attrs._one_shot[RunInfo].args, diff --git a/examples/persistent_worker/test.sh b/examples/persistent_worker/test.sh index 127a5bfd4787..06d77fbd814e 100755 --- a/examples/persistent_worker/test.sh +++ b/examples/persistent_worker/test.sh @@ -9,7 +9,9 @@ set -euo pipefail echo "::group::Local build without persistent worker" >&2 -echo '' > .buckconfig.local +cat >.buckconfig.local < +EOF buck2 clean; buck2 build : -vstderr echo "# Verifying Buck2 log" >&2 buck2 log what-ran --show-std-err --format json \ @@ -33,7 +35,9 @@ buck2 log what-ran --show-std-err --format json \ echo "::endgroup::" >&2 echo "::group::Local build with persistent worker" >&2 -echo '' > .buckconfig.local +cat >.buckconfig.local < +EOF buck2 clean; buck2 build : -vstderr echo "# Verifying Buck2 log" >&2 buck2 log what-ran --show-std-err --format json \ @@ -60,7 +64,12 @@ echo "::group::Remote build without persistent worker" >&2 if [[ -z ${BUILDBUDDY_API_KEY:+x} ]]; then echo "::notice file=$(realpath --relative-to=../.. ${BASH_SOURCE[0]}),line=${LINENO}::SKIPPED Missing BuildBuddy token. See examples/persistent_worker/README.md" >&2 else - echo '' > .buckconfig.local + cat >.buckconfig.local < + +[build] +cache_silo_key=$(date +%s.%N).${GITHUB_RUN_ID-0} +EOF buck2 clean; buck2 build : -vstderr echo "# Verifying Buck2 log" >&2 buck2 log what-ran --show-std-err --format json \ @@ -88,7 +97,12 @@ echo "::group::Remote build with persistent worker" >&2 if [[ -z ${BUILDBUDDY_API_KEY:+x} ]]; then echo "::notice file=$(realpath --relative-to=../.. ${BASH_SOURCE[0]}),line=${LINENO}::SKIPPED Missing BuildBuddy token. See examples/persistent_worker/README.md" >&2 else - echo '' > .buckconfig.local + cat >.buckconfig.local < + +[build] +cache_silo_key=$(date +%s.%N).${GITHUB_RUN_ID-0} +EOF buck2 clean; buck2 build : -vstderr echo "# Verifying Buck2 log" >&2 buck2 log what-ran --show-std-err --format json \