Skip to content

DRAFT: Add clang-tidy testing #287

DRAFT: Add clang-tidy testing

DRAFT: Add clang-tidy testing #287

Workflow file for this run

# Simple workflow for running non-documentation PR testing
name: Run ock tests for PR testing
on:
pull_request:
paths:
- 'source/**'
- 'modules/**'
- 'examples/**'
- 'cmake/**'
- 'hal/**'
- '.github/actions/do_build_ock/**'
- '.github/actions/setup_ubuntu_build/**'
- '.github/workflows/run_pr_tests.yml'
- 'CMakeLists.txt'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
# build and run host x86_64, execute UnitCL and lit tests and build and run offline
run_host_x86_64:
runs-on: ubuntu-22.04
steps:
- name: Checkout repo
uses: actions/checkout@v3
# installs tools, ninja, installs llvm and sets up sccahe
- name: setup-ubuntu
uses: ./.github/actions/setup_ubuntu_build
with:
llvm_version: 16
llvm_build_type: RelAssert
# These need to match the configurations of build_pr_cache to use the cache effectively
- name: build host x86_64 online release
uses: ./.github/actions/do_build_ock
with:
build_type: Release
- name: run just online lit
run:
ninja -C build check-all-lit
- name: run host online check
run:
ninja -C build check-UnitCL
# use the previous build for online to get clc
- name: build host x86_64 offline release
uses: ./.github/actions/do_build_ock
with:
build_type: Release
extra_flags: -DCA_RUNTIME_COMPILER_ENABLED=OFF -DCA_EXTERNAL_CLC=${{ github.workspace }}/build/bin/clc
build_dir: build_offline
build_targets: UnitCL
assemble_spirv_ll_lit_test_offline: ON
- name: run host x86_64 offline
run:
ninja -C build_offline check-UnitCL
# build and run riscv m1, execute UnitCL and lit tests
run_riscv_m1:
runs-on: ubuntu-22.04
steps:
- name: Checkout repo
uses: actions/checkout@v3
# installs tools, ninja, installs llvm and sets up sccahe
- name: setup-ubuntu
uses: ./.github/actions/setup_ubuntu_build
with:
llvm_version: 16
llvm_build_type: RelAssert
- name: build riscv M1
uses: ./.github/actions/do_build_ock/do_build_m1
- name: run riscv M1 lit
run:
ninja -C build check-all-lit
- name: run riscv M1 UnitCL tests
run:
ninja -C build check-UnitCL
# build and run clang-tidy
run_clang_tidy_changes:
runs-on: ubuntu-22.04
steps:
- name: Checkout repo
uses: actions/checkout@v3
# installs tools, ninja, installs llvm and sets up sccahe
- name: setup-ubuntu
uses: ./.github/actions/setup_ubuntu_build
with:
llvm_version: 16
llvm_build_type: RelAssert
# installs clang-tidy
- name: setup-clang-tidy
run:
sudo apt-get install -y clang-tidy-12
# These need to match the configurations of build_pr_cache to use the cache effectively
- name: build initial config files
uses: ./.github/actions/do_build_ock
with:
build_type: ReleaseAssert
host_image: ON
build_targets: build.ninja
# Make a good guess as to the generated targets we require.
#
# Here we compute the set difference between the output of the two
# temporary file descriptors using `awk`. Awk processes both files line by
# line, going through the first file, then the second file. The NR==FNR
# predicate executes its block only on the records of the first file,
# ensuring to call `next` (equivalent to `return`) to avoid running the
# second block on each line in the first file.
#
# The first input to `awk` lists all targets reported by ninja.
#
# The second input to awk collects all targets on which `tidy-` targets
# depend. This may include targets which are guarded by if() statements in
# CMake, hence why we need to compute a set difference with the targets that
# ninja reports.
- name: build actual targets needed
run:
ninja -C build
$(
awk -F':' 'NR==FNR { targets[$1] = 1; next } $1 in targets { print $1 }'
<(ninja -C build -t targets)
<(
find modules source -type f -name CMakeLists.txt -exec
awk -F"[()]" '/add_dependencies\(tidy-/ {sub(/[^ ]*/, "", $2);print $2}'
{} \+ | tr ' ' '\n'
)
)
- name: run clang-tidy
run: |
git fetch origin ${{ github.base_ref }}
./scripts/compute-dependants.py \
--exclude-filter='(/build/.*\.s$)|(.*/(external|cookie)/.*)' \
--build-dir="$PWD/build" \
`git diff --name-only --diff-filter=d \
HEAD..origin/${{ github.base_ref }} | \
grep -P '\.(c|cc|cxx|cpp|h|hh|hpp|hxx)$'` | \
tee /dev/stderr | \
parallel --verbose -- clang-tidy-12 --quiet -p "$PWD/build/" "{}"
# ^ When updating the clang-tidy version, the version used by the cmake
# target should match updated c.f. the `tidy` target
# run clang-format-diff on the repo
run_clang_format:
runs-on: ubuntu-22.04
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: setup-ubuntu-clang-format
run:
pip install clang-format==16.0.6
- name: run clang-format
run: |
# we've installed clang-format-16 in the docker via pip, which just installs it as clang-format,
# so just use clang-format-diff and -b clang-format directly
git fetch origin ${{ github.base_ref }}
git diff -U0 --no-color origin/${{ github.base_ref }} | \
clang-format-diff.py -p1 -regex \
"^(?!(.+\\/)*(external|cookie)\\/).*\\.(c|cc|cxx|cpp|h|hh|hxx|hpp)$" -b clang-format \
> clang-format.diff
if [ `wc -l < clang-format.diff` = 0 ]; then
echo 'success: clang-format did not generate a diff'
exit 0
fi
cat clang-format.diff
exit 1