Skip to content

Commit

Permalink
ci: bazel test github action queries affected targets for cc_test
Browse files Browse the repository at this point in the history
  • Loading branch information
danctorres committed Jan 5, 2025
1 parent 626b26b commit b8f254d
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions .github/workflows/bazel_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 != ''
uses: actions/cache@v4
env:
cache-name: bazel-cache
Expand All @@ -61,11 +80,11 @@ jobs:
${{ runner.os }}-${{ env.cache-name }}-development
- name: Test affected targets
if: env.targets != ''
if: env.test_targets != ''
run: |
echo "Building targets: $targets"
bazelisk test ${targets}
echo "Running test targets: $test_targets"
bazelisk test ${test_targets}
- name: No targets to test
if: env.targets == ''
run: echo "No affected Bazel targets found. Skipping test."
if: env.test_targets == ''
run: echo "No affected Bazel test targets found. Skipping test."

0 comments on commit b8f254d

Please sign in to comment.