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 2c13e54
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 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 && env.test_targets != '' }}
uses: actions/cache@v4
env:
cache-name: bazel-cache
Expand All @@ -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."

0 comments on commit 2c13e54

Please sign in to comment.