Shard Windows MSVC Bazel CI jobs into two shards. Add an optional `shards` matrix dimension to the reusable Bazel workflow that uses `bazel query` and `--target_pattern_file` to partition test targets across shards without manually curating package lists, and split the Windows MSVC 2022 Bazel CI configurations into two shards to halve cold-cache test compilation and execution time. PiperOrigin-RevId: 1007538480
diff --git a/.github/workflows/bazel.yml b/.github/workflows/bazel.yml index 218cd0c..9aaa855 100644 --- a/.github/workflows/bazel.yml +++ b/.github/workflows/bazel.yml
@@ -50,6 +50,11 @@ required: false default: '["opt", "fastbuild"]' type: string + shards: + description: "JSON array of shards to split tests across (e.g. '[\"1/2\", \"2/2\"]')" + required: false + default: '[""]' + type: string permissions: contents: read @@ -57,7 +62,7 @@ jobs: test: runs-on: ${{ inputs.os }} - name: (${{ matrix.std }}, ${{ matrix.compilation_mode }}) + name: (${{ matrix.std }}, ${{ matrix.compilation_mode }}${{ matrix.shard && format(', {0}', matrix.shard) || '' }}) container: image: ${{ inputs.container_image }} options: --cap-add=SYS_PTRACE @@ -70,6 +75,7 @@ matrix: std: ${{ fromJSON(inputs.stds) }} compilation_mode: ${{ fromJSON(inputs.compilation_modes) }} + shard: ${{ fromJSON(inputs.shards) }} defaults: run: shell: bash @@ -98,14 +104,21 @@ external-cache: true repository-cache: true google-credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }} - bazelrc: common --config=${{ inputs.remote_config }} + bazelrc: build --config=${{ inputs.remote_config }} - name: Fetch all external dependencies run: bazel fetch //... + - name: Shard test targets + if: ${{ matrix.shard != '' }} + run: | + IFS=/ read -r shard total <<< "${{ matrix.shard }}" + bazel query 'tests(//...)' | tr -d '\r' | awk "NR % $total == $shard - 1" > targets.txt + - name: Run tests run: > - bazel test ... + bazel test + ${{ matrix.shard && '--target_pattern_file=targets.txt' || '...' }} --config=${{ inputs.toolchain }} --cxxopt=${{ startsWith(inputs.os, 'windows') && '/std:' || '-std=' }}${{ matrix.std }} --host_cxxopt=${{ startsWith(inputs.os, 'windows') && '/std:' || '-std=' }}${{ matrix.std }}
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b8a9423..4a9b6b5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml
@@ -157,11 +157,13 @@ # windows-msvc-2022-cxx{17,20}-{dbg,opt}-bazel.cfg - name: MSVC 2022 toolchain: ci-windows-msvc + shards: '["1/2", "2/2"]' # windows-msvc-2022-alternate-options-cxx{17,20}-dbg-bazel.cfg (dbg only) - name: MSVC 2022 Alternate Options toolchain: ci-windows-msvc alternate_options: true compilation_modes: '["dbg"]' + shards: '["1/2", "2/2"]' # windows-clangcl-cxx17-fastbuild-bazel.cfg - name: ClangCL toolchain: windows-clangcl @@ -176,6 +178,7 @@ alternate_options: ${{ matrix.config.alternate_options || false }} stds: ${{ matrix.config.stds || '["c++17", "c++20"]' }} compilation_modes: ${{ matrix.config.compilation_modes || '["dbg", "opt"]' }} + shards: ${{ matrix.config.shards || '[""]' }} macos: name: macOS ${{ matrix.config.name }} Bazel