From 822d936690abbb7bc75b213271a4db30212be4a6 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Tue, 9 Nov 2021 18:58:41 -0800 Subject: [PATCH] bazel: add bazelw wrapper This wrapper allows developers to quickly get off the ground without having to install bazel or bazelisk manually. Signed-off-by: Keith Smiley --- .github/workflows/android_build.yml | 10 ++++---- .github/workflows/android_tests.yml | 6 ++--- .github/workflows/artifacts.yml | 4 +-- .github/workflows/asan.yml | 2 +- .github/workflows/cc_tests.yml | 2 +- .github/workflows/core.yml | 2 +- .github/workflows/format.yml | 4 +-- .github/workflows/ios_build.yml | 12 ++++----- .github/workflows/ios_tests.yml | 2 +- .github/workflows/perf.yml | 4 +-- .github/workflows/python_tests.yml | 2 +- .github/workflows/tsan.yml | 2 +- bazelw | 38 +++++++++++++++++++++++++++++ 13 files changed, 64 insertions(+), 26 deletions(-) create mode 100755 bazelw diff --git a/.github/workflows/android_build.yml b/.github/workflows/android_build.yml index bcf21186ca..edfadb63c2 100644 --- a/.github/workflows/android_build.yml +++ b/.github/workflows/android_build.yml @@ -38,7 +38,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - bazelisk build \ + ./bazelw build \ --config=remote-ci-macos \ --remote_header="Authorization=Bearer $GITHUB_TOKEN" \ --fat_apk_cpu=x86 \ @@ -70,13 +70,13 @@ jobs: - name: 'Start simulator' run: ./ci/mac_start_emulator.sh # Return to using: - # bazelisk mobile-install --fat_apk_cpu=x86 --start_app //examples/java/hello_world:hello_envoy + # ./bazelw mobile-install --fat_apk_cpu=x86 --start_app //examples/java/hello_world:hello_envoy # When https://github.com/lyft/envoy-mobile/issues/853 is fixed. - name: 'Start java app' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - bazelisk build \ + ./bazelw build \ --config=remote-ci-macos \ --remote_header="Authorization=Bearer $GITHUB_TOKEN" \ --fat_apk_cpu=x86 \ @@ -113,13 +113,13 @@ jobs: - name: 'Start simulator' run: ./ci/mac_start_emulator.sh # Return to using: - # bazelisk mobile-install --fat_apk_cpu=x86 --start_app //examples/kotlin/hello_world:hello_envoy_kt + # ./bazelw mobile-install --fat_apk_cpu=x86 --start_app //examples/kotlin/hello_world:hello_envoy_kt # When https://github.com/lyft/envoy-mobile/issues/853 is fixed. - name: 'Start kotlin app' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - bazelisk build \ + ./bazelw build \ --config=remote-ci-macos \ --remote_header="Authorization=Bearer $GITHUB_TOKEN" \ --fat_apk_cpu=x86 \ diff --git a/.github/workflows/android_tests.yml b/.github/workflows/android_tests.yml index 7bef820774..6b16e0e5af 100644 --- a/.github/workflows/android_tests.yml +++ b/.github/workflows/android_tests.yml @@ -42,7 +42,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - bazel test \ + ./bazelw test \ --test_output=all \ --build_tests_only \ --config=remote-ci-macos \ @@ -81,7 +81,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - bazel test \ + ./bazelw test \ --test_output=all \ --build_tests_only \ --config=remote-ci-macos \ @@ -125,7 +125,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - bazel test \ + ./bazelw test \ --test_output=all \ --build_tests_only \ --config=remote-ci-linux-clang \ diff --git a/.github/workflows/artifacts.yml b/.github/workflows/artifacts.yml index 15a34932cd..c402b338d3 100644 --- a/.github/workflows/artifacts.yml +++ b/.github/workflows/artifacts.yml @@ -26,7 +26,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | current_release_version=$(git describe --tag --abbrev=0) - bazelisk build \ + ./bazelw build \ --config=release-android \ --fat_apk_cpu=x86 \ --define=pom_version=$current_release_version \ @@ -114,7 +114,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - bazelisk build \ + ./bazelw build \ --config=release-ios \ --ios_multi_cpus=i386,x86_64,armv7,arm64 \ --config=remote-ci-macos \ diff --git a/.github/workflows/asan.yml b/.github/workflows/asan.yml index 67dca42db6..417a0ee86e 100644 --- a/.github/workflows/asan.yml +++ b/.github/workflows/asan.yml @@ -41,7 +41,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} if: steps.check_context.outputs.run_tests == 'true' run: | - bazel test --test_output=all \ + ./bazelw test --test_output=all \ --test_env=ENVOY_IP_TEST_VERSIONS=v4only \ --remote_header="Authorization=Bearer $GITHUB_TOKEN" \ --config=remote-ci-linux-asan \ diff --git a/.github/workflows/cc_tests.yml b/.github/workflows/cc_tests.yml index 214506078b..76f4318675 100644 --- a/.github/workflows/cc_tests.yml +++ b/.github/workflows/cc_tests.yml @@ -20,4 +20,4 @@ jobs: - env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} name: 'Run tests' - run: bazel test --action_env=LD_LIBRARY_PATH --test_output=all --config=remote-ci-linux --remote_header="Authorization=Bearer $GITHUB_TOKEN" //test/cc/... + run: ./bazelw test --action_env=LD_LIBRARY_PATH --test_output=all --config=remote-ci-linux --remote_header="Authorization=Bearer $GITHUB_TOKEN" //test/cc/... diff --git a/.github/workflows/core.yml b/.github/workflows/core.yml index f8adc66b5d..ae4dfe384a 100644 --- a/.github/workflows/core.yml +++ b/.github/workflows/core.yml @@ -20,4 +20,4 @@ jobs: - name: 'Run tests' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: bazelisk test --test_output=all --config=remote-ci-macos --remote_header="Authorization=Bearer $GITHUB_TOKEN" //test/common/... + run: ./bazelw test --test_output=all --config=remote-ci-macos --remote_header="Authorization=Bearer $GITHUB_TOKEN" //test/common/... diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 123d4ef465..f23f31eec8 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -63,10 +63,10 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - bazel build \ + ./bazelw build \ --config=remote-ci-macos --remote_header="Authorization=Bearer $GITHUB_TOKEN" \ //library/kotlin/io/envoyproxy/envoymobile:envoy_lib_lint \ //examples/kotlin/hello_world:hello_envoy_kt_lint - name: 'Run Kotlin Formatter (ktlint)' run: | - bazel build kotlin_format + ./bazelw build kotlin_format diff --git a/.github/workflows/ios_build.yml b/.github/workflows/ios_build.yml index fb12cfc9c6..fd56feca70 100644 --- a/.github/workflows/ios_build.yml +++ b/.github/workflows/ios_build.yml @@ -30,8 +30,8 @@ jobs: - env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - bazelisk shutdown - bazelisk build --config=ios --config=remote-ci-macos --remote_header="Authorization=Bearer $GITHUB_TOKEN" //:ios_dist + ./bazelw shutdown + ./bazelw build --config=ios --config=remote-ci-macos --remote_header="Authorization=Bearer $GITHUB_TOKEN" //:ios_dist if: steps.check-cache.outputs.cache-hit != 'true' name: 'Build Envoy.framework distributable' swifthelloworld: @@ -56,12 +56,12 @@ jobs: name: 'Short-circuit' - env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: bazelisk build --config=ios --config=remote-ci-macos --remote_header="Authorization=Bearer $GITHUB_TOKEN" //examples/swift/hello_world:app + run: ./bazelw build --config=ios --config=remote-ci-macos --remote_header="Authorization=Bearer $GITHUB_TOKEN" //examples/swift/hello_world:app name: 'Build swift app' # Run the app in the background and redirect logs. - env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: bazelisk run --config=ios --config=remote-ci-macos --remote_header="Authorization=Bearer $GITHUB_TOKEN" //examples/swift/hello_world:app &> /tmp/envoy.log & + run: ./bazelw run --config=ios --config=remote-ci-macos --remote_header="Authorization=Bearer $GITHUB_TOKEN" //examples/swift/hello_world:app &> /tmp/envoy.log & name: 'Run swift app' - run: sed '/received headers with status 200/q' <(touch /tmp/envoy.log && tail -F /tmp/envoy.log) name: 'Check connectivity' @@ -90,12 +90,12 @@ jobs: name: 'Short-circuit' - env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: bazelisk build --config=ios --config=remote-ci-macos --remote_header="Authorization=Bearer $GITHUB_TOKEN" //examples/objective-c/hello_world:app + run: ./bazelw build --config=ios --config=remote-ci-macos --remote_header="Authorization=Bearer $GITHUB_TOKEN" //examples/objective-c/hello_world:app name: 'Build objective-c app' # Run the app in the background and redirect logs. - env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: bazelisk run --config=ios --config=remote-ci-macos --remote_header="Authorization=Bearer $GITHUB_TOKEN" //examples/objective-c/hello_world:app &> /tmp/envoy.log & + run: ./bazelw run --config=ios --config=remote-ci-macos --remote_header="Authorization=Bearer $GITHUB_TOKEN" //examples/objective-c/hello_world:app &> /tmp/envoy.log & name: 'Run objective-c app' - run: sed '/received headers with status 200/q' <(touch /tmp/envoy.log && tail -F /tmp/envoy.log) name: 'Check connectivity' diff --git a/.github/workflows/ios_tests.yml b/.github/workflows/ios_tests.yml index 1930cf27c3..d13aaba7a5 100644 --- a/.github/workflows/ios_tests.yml +++ b/.github/workflows/ios_tests.yml @@ -31,4 +31,4 @@ jobs: if: steps.check_context.outputs.run_tests == 'true' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: bazelisk test --test_output=all --config=ios --build_tests_only --config=remote-ci-macos --remote_header="Authorization=Bearer $GITHUB_TOKEN" //test/swift/... + run: ./bazelw test --test_output=all --config=ios --build_tests_only --config=remote-ci-macos --remote_header="Authorization=Bearer $GITHUB_TOKEN" //test/swift/... diff --git a/.github/workflows/perf.yml b/.github/workflows/perf.yml index 72e6915518..2acafe9e6c 100644 --- a/.github/workflows/perf.yml +++ b/.github/workflows/perf.yml @@ -24,7 +24,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - bazel build \ + ./bazelw build \ --config=sizeopt \ --config=remote-ci-linux-clang \ --remote_header="Authorization=Bearer $GITHUB_TOKEN" \ @@ -51,7 +51,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | git checkout main && git pull origin main && git submodule update - bazel build \ + ./bazelw build \ --config=sizeopt \ --config=remote-ci-linux-clang \ --remote_header="Authorization=Bearer $GITHUB_TOKEN" \ diff --git a/.github/workflows/python_tests.yml b/.github/workflows/python_tests.yml index 9c2b09380e..1c7ce932db 100644 --- a/.github/workflows/python_tests.yml +++ b/.github/workflows/python_tests.yml @@ -32,7 +32,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - bazel test \ + ./bazelw test \ --action_env=LD_LIBRARY_PATH \ --test_output=all \ --config=remote-ci-linux \ diff --git a/.github/workflows/tsan.yml b/.github/workflows/tsan.yml index c7d1a75e78..d305c7801b 100644 --- a/.github/workflows/tsan.yml +++ b/.github/workflows/tsan.yml @@ -41,7 +41,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} if: steps.check_context.outputs.run_tests == 'true' run: | - bazel test --test_output=all \ + ./bazelw test --test_output=all \ --test_env=ENVOY_IP_TEST_VERSIONS=v4only \ --remote_header="Authorization=Bearer $GITHUB_TOKEN" \ --config=remote-ci-linux-tsan \ diff --git a/bazelw b/bazelw new file mode 100755 index 0000000000..e9e44c76fd --- /dev/null +++ b/bazelw @@ -0,0 +1,38 @@ +#!/bin/bash + +set -euo pipefail + +readonly bazelisk_version="1.10.1" +if [[ $OSTYPE == darwin* ]]; then + # TODO: Support M1 once https://github.com/envoyproxy/envoy/issues/16482 + readonly bazel_platform="darwin-amd64" + readonly bazel_version_sha="e485bbf84532d02a60b0eb23c702610b5408df3a199087a4f2b5e0995bbf2d5a" +else + readonly bazel_platform="linux-amd64" + readonly bazel_version_sha="4cb534c52cdd47a6223d4596d530e7c9c785438ab3b0a49ff347e991c210b2cd" +fi + +readonly bazel_version_url="https://github.com/bazelbuild/bazelisk/releases/download/v$bazelisk_version/bazelisk-$bazel_platform" +script_root="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +readonly bazelisk="$script_root/tmp/bazel/versions/bazelisk-$bazelisk_version-$bazel_platform" + +if [[ ! -x "$bazelisk" ]]; then + echo "Installing bazelisk..." >&2 + mkdir -p "$(dirname "$bazelisk")" + + download_bazelisk() { + curl --fail -L --retry 5 --retry-connrefused --silent --progress-bar \ + --output "$bazelisk" "$bazel_version_url" + } + + download_bazelisk || download_bazelisk + if echo "$bazel_version_sha $bazelisk" | shasum --check --status; then + chmod +x "$bazelisk" + else + echo "Bazelisk sha mismatch" >&2 + rm -f "$bazelisk" + exit 1 + fi +fi + +exec "$bazelisk" "$@"