Skip to content

Commit

Permalink
ci: make bazel test incremental
Browse files Browse the repository at this point in the history
  • Loading branch information
danctorres committed Dec 8, 2024
1 parent d58a748 commit b7ee2ae
Showing 1 changed file with 46 additions and 7 deletions.
53 changes: 46 additions & 7 deletions .github/workflows/bazel_test.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# yamllint disable rule:line-length
---
name: Bazel Test
on: # yamllint disable-line rule:truthy
Expand All @@ -7,8 +8,41 @@ jobs:
bazel_test:
runs-on: ubuntu-latest
steps:
- name: Cache bazel
uses: actions/cache@v2
- name: Checkout code
uses: actions/checkout@v3

- name: Find affected files
id: affected_files
run: |
git fetch origin ${{ github.base_ref }} --depth=1
git diff --name-only origin/${{ github.base_ref }} > affected_files.txt
echo "Affected files:"
cat affected_files.txt
- name: Find affected Bazel targets
id: bazel_targets
run: |
> affected_targets.txt
while read file; do
if [[ -f $file ]]; then
if [[ "$file" == *.cpp || "$file" == *.h || "$file" == *.hpp || "$file" == *.cc || "$file" == *.cxx || "$file" == *.hxx ]]; then
echo "Finding targets for: $file"
targets=$(bazel query --output=package "$file" || true)/...
echo "$targets" >> affected_targets.txt
fi
fi
done < affected_files.txt
sort -u affected_targets.txt -o affected_targets.txt
echo "Affected targets:"
cat affected_targets.txt
echo "targets=$(cat affected_targets.txt | tr '\n' ' ')" >> $GITHUB_ENV
- name: Setup bazel cache
if: env.targets != ''
uses: actions/cache@v3
env:
cache-name: bazel-cache
with:
Expand All @@ -18,8 +52,13 @@ jobs:
key: ${{ runner.os }}-${{ env.cache-name }}-${{ github.ref }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-development
- name: Checkout code
uses: actions/checkout@v3
- name: Run Bazel test
run: |-
bazel test //...
- name: Test affected targets
if: env.targets != ''
run: |
echo "Building targets: $targets"
bazel test ${targets}
- name: No targets to test
if: env.targets == ''
run: echo "No affected Bazel targets found. Skipping test."

0 comments on commit b7ee2ae

Please sign in to comment.