From 93c43e908ec7b915bacd31abf9cb45d3f3b14984 Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Wed, 26 Oct 2022 15:05:27 -0700 Subject: [PATCH] chore: upgrade to Bazel 6.0.0rc1 but continue to also test Bazel 5.3.2 on CI (#266) --- .bazelversion | 2 +- .github/workflows/ci.bazelrc | 2 +- .github/workflows/ci.yaml | 62 +++++++++++++++++++++++++++++------- e2e/bzlmod/BUILD.bazel | 11 ++++--- e2e/bzlmod/MODULE.bazel | 3 +- lib/private/host_repo.bzl | 3 ++ 6 files changed, 64 insertions(+), 19 deletions(-) diff --git a/.bazelversion b/.bazelversion index 4453eff..ee5e98b 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1,4 +1,4 @@ -5.3.2 +6.0.0rc1 # The first line of this file is used by Bazelisk and Bazel to be sure # the right version of Bazel is used to build and test this repo. # This also defines which version is used on CI. diff --git a/.github/workflows/ci.bazelrc b/.github/workflows/ci.bazelrc index ecc70c6..5f326b2 100644 --- a/.github/workflows/ci.bazelrc +++ b/.github/workflows/ci.bazelrc @@ -10,7 +10,7 @@ build:local --disk_cache=~/.cache/bazel # Generic remote cache build --remote_local_fallback -build --remote_download_toplevel +# build --remote_download_toplevel # BREAKS BUILD in Bazel 6.0.0rc1 build --remote_timeout=3600 build --remote_upload_local_results ## Fixes builds hanging on CI that get the TCP connection closed without sending RST packets. diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c7ada05..86f72a6 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -12,46 +12,75 @@ on: workflow_dispatch: jobs: - # Dynamically generate a bit of JSON depending on whether our action has access to repository secrets. - # When running on a pull_request from a fork, the author is untrusted so the secret will be absent. - # Insanely complex for how simple this requirement is... inspired from + # matrix-prep-* steps dynamically generate a bit of JSON depending on whether our action has + # access to repository secrets. When running on a pull_request from a fork, the author is + # untrusted so the secret will be absent. Insanely complex for how simple this requirement is... + # inspired from # https://stackoverflow.com/questions/65384420/how-to-make-a-github-action-matrix-element-conditional - matrix-prep: + + matrix-prep-config: + # Prepares the 'config' axis of the test matrix runs-on: ubuntu-latest env: ENGFLOW_PRIVATE_KEY: ${{ secrets.ENGFLOW_PRIVATE_KEY }} steps: - id: local run: echo "::set-output name=config::local" - - id: maybe-rbe - if: ${{ env.ENGFLOW_PRIVATE_KEY != '' }} + - id: rbe run: echo "::set-output name=config::rbe" + # Don't run RBE if there are no EngFlow creds which is the case on forks + if: ${{ env.ENGFLOW_PRIVATE_KEY != '' }} outputs: # Will look like '["local", "rbe"]' configs: ${{ toJSON(steps.*.outputs.config) }} + matrix-prep-bazelversion: + # Prepares the 'bazelversion' axis of the test matrix + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - id: bazel_6 + run: echo "::set-output name=bazelversion::$(head -n 1 .bazelversion)" + - id: bazel_5 + run: echo "::set-output name=bazelversion::5.3.2" + outputs: + # Will look like '["6.0.0rc1", "5.3.2"]' + bazelversions: ${{ toJSON(steps.*.outputs.bazelversion) }} + test: # The type of runner that the job will run on runs-on: ubuntu-latest - needs: matrix-prep + + needs: + - matrix-prep-config + - matrix-prep-bazelversion strategy: fail-fast: false matrix: - config: ${{ fromJSON(needs.matrix-prep.outputs.configs) }} + config: ${{ fromJSON(needs.matrix-prep-config.outputs.configs) }} + bazelversion: ${{ fromJSON(needs.matrix-prep-bazelversion.outputs.bazelversions) }} folder: - "." - "e2e/bzlmod" - "e2e/copy_to_directory" exclude: - # bzlmod broken at 5.3.0 which the RBE bazel fork is bazed on + # bzlmod broken at 5.3.2 which the RBE: + # ``` + # ERROR: /home/runner/work/bazel-lib/bazel-lib/e2e/bzlmod/BUILD.bazel:37:10: While resolving + # toolchains for target //:test: com.google.devtools.build.lib.packages.BuildFileNotFoundException: + # no such package '@aspect_bazel_lib//platforms': The repository '@aspect_bazel_lib' could not be + # resolved: Repository '@aspect_bazel_lib' is not defined + # ``` - config: rbe + bazelversion: 5.3.2 folder: e2e/bzlmod # Steps represent a sequence of tasks that will be executed as part of the job steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v3 + - name: Mount bazel caches uses: actions/cache@v3 with: @@ -60,6 +89,11 @@ jobs: ~/.cache/bazel-repo key: bazel-cache-${{ hashFiles('**/BUILD.bazel', '**/*.bzl', 'WORKSPACE') }} restore-keys: bazel-cache- + + - name: Configure Bazel version + working-directory: ${{ matrix.folder }} + run: echo "USE_BAZEL_VERSION=${{ matrix.bazelversion }}" >> $GITHUB_ENV + - name: Write engflow credentials if: ${{ matrix.config == 'rbe' }} working-directory: ${{ matrix.folder }} @@ -71,12 +105,18 @@ jobs: env: ENGFLOW_CLIENT_CRT: ${{ secrets.ENGFLOW_CLIENT_CRT }} ENGFLOW_PRIVATE_KEY: ${{ secrets.ENGFLOW_PRIVATE_KEY }} + - name: bazel test //... + working-directory: ${{ matrix.folder }} + # NB: we need to write the bazel version from the matrix to .bazelversion since + # the //:bazel_version_test uses it and it needs to match the Bazel version being run + run: | + echo "${{ matrix.bazelversion }}" > .bazelversion + bazel --bazelrc=$GITHUB_WORKSPACE/.github/workflows/ci.bazelrc --bazelrc=.bazelrc test --config=${{ matrix.config }} //... env: # Bazelisk will download bazel to here XDG_CACHE_HOME: ~/.cache/bazel-repo - working-directory: ${{ matrix.folder }} - run: bazel --bazelrc=$GITHUB_WORKSPACE/.github/workflows/ci.bazelrc --bazelrc=.bazelrc test --config=${{ matrix.config }} //... + - name: integration tests if: ${{ matrix.folder == '.' }} # Find all shell scripts within e2e, echo the filename, execute, fail on error diff --git a/e2e/bzlmod/BUILD.bazel b/e2e/bzlmod/BUILD.bazel index 0802058..99d097f 100644 --- a/e2e/bzlmod/BUILD.bazel +++ b/e2e/bzlmod/BUILD.bazel @@ -7,7 +7,6 @@ You'll see a aspect_bazel_lib.ext.yq_toolchains repo, but no downloaded yq binar """ load("@aspect_bazel_lib//lib:jq.bzl", "jq") -load("@aspect_bazel_lib//lib:docs.bzl", "stardoc_with_diff_test") load("@aspect_bazel_lib//lib:diff_test.bzl", "diff_test") load("@bazel_skylib//:bzl_library.bzl", "bzl_library") @@ -21,10 +20,12 @@ bzl_library( # https://github.com/bazelbuild/stardoc/issues/117 # This happens to work because we don't reference any external repos # from defs.bzl. -stardoc_with_diff_test( - name = "docs", - bzl_library_target = "//:defs", -) +# TODO: re-enable this once it works +# load("@aspect_bazel_lib//lib:docs.bzl", "stardoc_with_diff_test") +# stardoc_with_diff_test( +# name = "docs", +# bzl_library_target = "//:defs", +# ) # Validate that JQ works and resolves its toolchain jq( diff --git a/e2e/bzlmod/MODULE.bazel b/e2e/bzlmod/MODULE.bazel index 13b87f2..e6d67d8 100644 --- a/e2e/bzlmod/MODULE.bazel +++ b/e2e/bzlmod/MODULE.bazel @@ -4,9 +4,10 @@ module( version = "0.0.0", ) -bazel_dep(name = "aspect_bazel_lib", version = "0.9.8") bazel_dep(name = "bazel_skylib", version = "1.1.1") +bazel_dep(name = "aspect_bazel_lib", version = "0.0.0") + local_path_override( module_name = "aspect_bazel_lib", path = "../..", diff --git a/lib/private/host_repo.bzl b/lib/private/host_repo.bzl index 5f946ef..d15c0a3 100644 --- a/lib/private/host_repo.bzl +++ b/lib/private/host_repo.bzl @@ -36,5 +36,8 @@ host = struct( host_repo = repository_rule( implementation = _host_repo_impl, + # always invalidate this repository since so that the bazel_version is + # always updated on every invocation of bazel + local = True, doc = "Exposes information about the host platform", )