diff --git a/.github/workflows/bazel_test.yml b/.github/workflows/bazel_test.yml index 617502c..6a51268 100644 --- a/.github/workflows/bazel_test.yml +++ b/.github/workflows/bazel_test.yml @@ -47,8 +47,27 @@ jobs: echo "targets=$(cat affected_targets.txt | tr '\n' ' ')" >> $GITHUB_ENV shell: bash - - name: Setup bazel cache + - name: Find affected Bazel test targets + id: bazel_test_targets if: env.targets != '' + run: | + > affected_test_targets.txt + + while read target; do + echo "Finding test targets for: $target" + test_targets=$(bazelisk query "kind('cc_test', '$target')" || true) + echo "$test_targets" >> affected_test_targets.txt + done < affected_targets.txt + + sort -u affected_test_targets.txt -o affected_test_targets.txt + echo "Affected test targets:" + cat affected_test_targets.txt + + echo "test_targets=$(cat affected_test_targets.txt | tr '\n' ' ')" >> $GITHUB_ENV + shell: bash + + - name: Setup bazel cache + if: ${{ env.test_targets && env.test_targets != '' }} uses: actions/cache@v4 env: cache-name: bazel-cache @@ -61,11 +80,12 @@ jobs: ${{ runner.os }}-${{ env.cache-name }}-development - name: Test affected targets - if: env.targets != '' + if: ${{ env.test_targets && env.test_targets != '' }} run: | - echo "Building targets: $targets" - bazelisk test ${targets} + echo "Running test targets: $test_targets" + bazelisk test $test_targets + shell: bash - name: No targets to test - if: env.targets == '' - run: echo "No affected Bazel targets found. Skipping test." + if: ${{ env.targets == '' || env.test_targets && env.test_targets == '' }} + run: echo "No affected Bazel test targets found. Skipping test."