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 3933154
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions .github/workflows/bazel_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,28 @@ 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"
bazelisk query 'attr("tags", "test", //path/to: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 +81,11 @@ jobs:
${{ runner.os }}-${{ env.cache-name }}-development
- name: Test affected targets
if: env.targets != ''
if: env.test_targets != ''
run: |
echo "Building targets: $targets"
echo "Running test targets: $test_targets"
bazelisk 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 3933154

Please sign in to comment.