Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add sanitizers github action #89

Merged
merged 5 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/arduino_lint.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# yamllint disable rule:line-length
---
name: Arduino Lint
name: Lint
on: # yamllint disable-line rule:truthy
pull_request:
branches: ['*']

jobs:
arduino-lint:
arduino:
runs-on: ubuntu-latest
container:
image: dtors/base-cpp:latest
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/bazel_build.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# yamllint disable rule:line-length
---
name: Bazel Build
name: Bazel
on: # yamllint disable-line rule:truthy
pull_request:
branches: ['*']

jobs:
bazel_build:
build:
runs-on: ubuntu-latest
container:
image: dtors/base-cpp:latest
Expand All @@ -33,9 +33,9 @@ jobs:
> affected_targets.txt

while read file; do
if [[ "$file" == *.cpp || "$file" == *.h || "$file" == *.hpp || "$file" == *.cc || "$file" == *.cxx || "$file" == *.hxx ]]; then
if [[ "$file" == *.c || "$file" == *.cc || "$file" == *.cpp || "$file" == *.cxx || "$file" == *.h || "$file" == *.hpp || "$file" == *.hxx ]]; then
echo "Finding targets for: $file"
targets=$(bazel query --output=package "$file" || true)/...
targets=$(bazelisk query --output=package "$file" || true)/...
echo "$targets" >> affected_targets.txt
fi
done < affected_files.txt
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/bazel_buildifier.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# yamllint disable rule:line-length
---
name: Bazel Buildifier
name: Lint
on: # yamllint disable-line rule:truthy
pull_request:
branches: ['*']

jobs:
bazel_buildifier:
bazel:
runs-on: ubuntu-latest
container:
image: dtors/base-cpp:latest
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/bazel_test.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# yamllint disable rule:line-length
---
name: Bazel Test
name: Bazel
on: # yamllint disable-line rule:truthy
pull_request:
branches: ['*']

jobs:
bazel_test:
test:
runs-on: ubuntu-latest
container:
image: dtors/base-cpp:latest
Expand All @@ -33,9 +33,9 @@ jobs:
> affected_targets.txt

while read file; do
if [[ "$file" == *.cpp || "$file" == *.h || "$file" == *.hpp || "$file" == *.cc || "$file" == *.cxx || "$file" == *.hxx ]]; then
if [[ "$file" == *.c || "$file" == *.cc || "$file" == *.cpp || "$file" == *.cxx || "$file" == *.h || "$file" == *.hpp || "$file" == *.hxx ]]; then
echo "Finding targets for: $file"
targets=$(bazel query --output=package "$file" || true)/...
targets=$(bazelisk query --output=package "$file" || true)/...
echo "$targets" >> affected_targets.txt
fi
done < affected_files.txt
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/check_pr_description.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# yamllint disable rule:line-length
---
name: PR description
name: Lint
on: # yamllint disable-line rule:truthy
pull_request:
types: [opened, edited, synchronize]

jobs:
check-description:
pr-description:
runs-on: ubuntu-latest

steps:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/clang_format.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# yamllint disable rule:line-length
---
name: Clang-Format
name: Clang
on: # yamllint disable-line rule:truthy
pull_request:
branches: ['*']

jobs:
clang-format:
format:
runs-on: ubuntu-latest
container:
image: dtors/base-cpp:latest
Expand All @@ -31,7 +31,7 @@ jobs:
> affected_cpp_files.txt

while read file; do
if [[ "$file" == *.cpp || "$file" == *.h || "$file" == *.hpp || "$file" == *.cc || "$file" == *.cxx || "$file" == *.hxx ]]; then
if [[ "$file" == *.c || "$file" == *.cc || "$file" == *.cpp || "$file" == *.cxx || "$file" == *.h || "$file" == *.hpp || "$file" == *.hxx ]]; then
echo "$file" >> affected_cpp_files.txt
fi
done < affected_files.txt
Expand All @@ -58,5 +58,5 @@ jobs:
echo -e "To automatically apply suggested fixes, run the following command:
======================================================================================
1. Run clang-format:
find . -name \"*.cpp\" -o -name \"*.h\" -o -name \"*.hpp\" -o -name \"*.cc\" -o -name \"*.cxx\" -o -name \"*.hxx\" | xargs clang-format -i
find . -iname \"*.c\" -o -iname \"*.cc\" -o -iname \"*.cpp\" -o -iname \"*.cxx\" -o -iname \"*.h\" -o -iname \"*.hpp\" -o -iname \"*.hxx\" | xargs clang-format -i
======================================================================================"
10 changes: 6 additions & 4 deletions .github/workflows/clang_tidy.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# yamllint disable rule:line-length
---
name: Clang-Tidy
name: Clang
on: # yamllint disable-line rule:truthy
pull_request:
branches: ['*']

jobs:
clang-tidy:
tidy:
runs-on: ubuntu-latest
container:
image: dtors/base-cpp:latest
Expand All @@ -31,7 +31,7 @@ jobs:
> affected_cpp_files.txt

while read file; do
if [[ "$file" == *.cpp || "$file" == *.h || "$file" == *.hpp || "$file" == *.cc || "$file" == *.cxx || "$file" == *.hxx ]]; then
if [[ "$file" == *.c || "$file" == *.cc || "$file" == *.cpp || "$file" == *.cxx || "$file" == *.h || "$file" == *.hpp || "$file" == *.hxx ]]; then
echo "$file" >> affected_cpp_files.txt
fi
done < affected_files.txt
Expand Down Expand Up @@ -66,5 +66,7 @@ jobs:
1. Generate compile commands:
bazel run @hedron_compile_commands//:refresh_all
2. Run clang-tidy:
find . -name \"*.cpp\" -o -name \"*.h\" -o -name \"*.hpp\" -o -name \"*.cc\" -o -name \"*.cxx\" -o -name \"*.hxx\" | xargs clang-tidy -fix -fix-errors -p ./compile_commands.json
find . -iname \"*.c\" -o -iname \"*.cc\" -o -iname \"*.cpp\" -o -iname \"*.cxx\" -o -iname \"*.h\" -o -iname \"*.hpp\" -o -iname \"*.hxx\" | xargs clang-tidy -p ./compile_commands.json
3. Run clang-tidy:
find . -iname \"*.c\" -o -iname \"*.cc\" -o -iname \"*.cpp\" -o -iname \"*.cxx\" -o -iname \"*.h\" -o -iname \"*.hpp\" -o -iname \"*.hxx\" | xargs clang-tidy -p ./compile_commands.json -fix --fix-errors
======================================================================================"
2 changes: 1 addition & 1 deletion .github/workflows/gitlint.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: GitLint
name: Lint
on: # yamllint disable-line rule:truthy
pull_request:
branches: ['*']
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/llvm_cov.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# yamllint disable rule:line-length
---
name: Run llvm-cov
name: Coverage
on: # yamllint disable-line rule:truthy
pull_request:
branches: ['*']

jobs:
coverage:
llvm-cov:
runs-on: ubuntu-latest
container:
image: dtors/base-cpp:latest
Expand Down
122 changes: 122 additions & 0 deletions .github/workflows/sanitizers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# yamllint disable rule:line-length
---
name: Sanitizers
on: # yamllint disable-line rule:truthy
pull_request:
branches: ['*']

jobs:
asan_ubsan_tsan:
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 --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) && "$file" != *test* ]]; then
echo "Finding targets for: $file"
targets=$(bazelisk query --output=package "$file" || true)/...
if [[ "$targets" != *test* ]]; then
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
shell: bash

- name: Find tests target of affected targets
if: env.targets != ''
run: |
test_targets=""

for target in $targets; do
result=$(bazelisk cquery "kind('cc_test', deps('$target'))") || exit 1

# Remove the part in parentheses (e.g., (f37096a))
formatted_result=$(echo "$result" | sed 's/ ([^)]*)//g')

# Prefix each line of the result with a `-`
formatted_result=$(echo "$formatted_result" | sed 's/^/-/')

test_targets+="$formatted_result"$'\n'
done

echo "$test_targets" > test_targets.txt
single_line_test_targets=$(echo "$test_targets" | tr '\n' ' ' | sed 's/ $//')
echo "test_targets=-- $single_line_test_targets" >> $GITHUB_ENV
shell: bash

- name: Setup bazel cache
if: env.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: Run ASAN
if: env.targets != ''
run: |
echo -e "Running ASAN on:
Targets: $targets
Excluded targets: $test_targets"
bazelisk build ${targets} --features=asan ${test_targets}

- name: Run UBSAN
if: env.targets != ''
run: |
echo -e "Running UBSAN on:
Targets: $targets
Excluded targets: $test_targets"
bazelisk build ${targets} --features=ubsan ${test_targets}

- name: Run TSAN
if: env.targets != ''
run: |
echo -e "Running TSAN on:
Targets: $targets
Excluded targets: $test_targets"
bazelisk build ${targets} --features=tsan ${test_targets}

- name: No targets to build
if: env.targets == ''
run: echo "No affected Bazel targets found. Skipping build."

- name: Show failure message
if: failure()
run: |-
echo -e "To run sanitizers locally use the following command:
======================================================================================
bazel run <bazel_target> --features=asan
bazel run <bazel_target> --features=ubsan
bazel run <bazel_target> --features=tsan
======================================================================================"
4 changes: 2 additions & 2 deletions .github/workflows/yamllint.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# yamllint disable rule:line-length
---
name: Lint YAML files
name: Lint
on: # yamllint disable-line rule:truthy
pull_request:
branches: ['*']

jobs:
yamllint:
yaml:
runs-on: ubuntu-latest
container:
image: dtors/base-cpp:latest
Expand Down
Loading
Loading