forked from SEAME-pt/SEAME-Course-24-25
-
Notifications
You must be signed in to change notification settings - Fork 0
90 lines (75 loc) · 2.96 KB
/
bazel_test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# yamllint disable rule:line-length
---
name: Bazel
on: # yamllint disable-line rule:truthy
pull_request:
branches: ['*']
jobs:
test:
runs-on: ubuntu-latest
container:
image: dtors/base-cpp:latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Configure Git Safe Directory
run: |
git config --global --add safe.directory $(pwd)
- name: Find affected files
id: affected_files
run: |
git fetch origin ${{ github.base_ref }} --depth=1
git diff --diff-filter=ACM --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 [[ "$file" == *.c || "$file" == *.cc || "$file" == *.cpp || "$file" == *.cxx || "$file" == *.h || "$file" == *.hpp || "$file" == *.hxx ]]; then
echo "Finding targets for: $file"
targets=$(bazelisk query --output=package "$file")/...
echo "$targets" >> affected_targets.txt
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 -s '\n' ' ' | sed 's/^[ \t]*//;s/[ \t]*$//')" >> $GITHUB_ENV
shell: bash
- name: Find affected Bazel test targets
id: bazel_test_targets
run: |
> affected_test_targets.txt
while read target; do
echo "Finding test targets for: $target"
test_targets=$(bazelisk query "kind('cc_test', '$target')")
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 -s '\n' ' ' | sed 's/^[ \t]*//;s/[ \t]*$//')" >> $GITHUB_ENV
shell: bash
- name: Setup bazel cache
if: ${{ env.test_targets && env.test_targets != '' }}
uses: actions/cache@v4
env:
cache-name: bazel-cache
with:
path: |
~/.cache/bazelisk
~/.cache/bazel
key: ${{ runner.os }}-${{ env.cache-name }}-${{ github.ref }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-development
- name: Test affected targets
if: ${{ env.test_targets && env.test_targets != '' }}
run: |
echo "Running test targets: $test_targets"
bazelisk test $test_targets
shell: bash
- name: No targets to test
if: ${{ env.targets == '' || env.test_targets == '' }}
run: echo "No affected Bazel test targets found. Skipping test."