Skip to content

Commit 5fc03e7

Browse files
committed
[ci] add clang-tidy code analysis (WIP)
1 parent 8fecb0b commit 5fc03e7

2 files changed

Lines changed: 62 additions & 27 deletions

File tree

.ci/tidy_script.sh

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,20 @@
11
#!/usr/bin/env bash
22

3-
set -ex
3+
set -e
44

5-
CLANG_TIDY_CHECKS='-*'
6-
if [[ $TOOL == clang-tidy-analyzer ]]; then
7-
CLANG_TIDY_CHECKS+=',clang-analyzer-*,-clang-analyzer-alpha*,bugprone*'
8-
elif [[ $TOOL == clang-tidy-modernize ]]; then
9-
CLANG_TIDY_CHECKS+=',modernize*'
10-
fi
5+
echo "Running $(realpath $0) from $PWD"
116

12-
echo "Running clang-tidy only against the changes in branch $TRAVIS_BRANCH."
7+
WORKSPACE="${GITHUB_WORKSPACE:-${PWD}}"
8+
echo "Setting WORKSPACE to $WORKSPACE"
139

14-
cd ../root/
10+
SRC_DIR="${WORKSPACE}/ROOT-CI/src"
11+
BUILD_DIR="${WORKSPACE}/ROOT-CI/build"
1512

16-
# Workaround for travis issue: travis-ci/travis-ci#6069
17-
git remote set-branches --add origin master
18-
git fetch
13+
mkdir -v -p "${SRC_DIR}" "${BUILD_DIR}"
1914

20-
# clang-tidy-diff.py not installed on travis
21-
wget https://raw.githubusercontent.com/llvm-mirror/clang-tools-extra/release_50/clang-tidy/tool/clang-tidy-diff.py
15+
cmake -B "${BUILD_DIR}" -S ${SRC_DIR} \
16+
-DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DCMAKE_EXPORT_COMPILE_COMMANDS=on \
17+
-Dminimal=on -Dasserts=on
2218

23-
RESULT_OUTPUT="$(git diff -U0 origin/master | python clang-tidy-diff.py -p1 -clang-tidy-binary $(which clang-tidy) \
24-
-checks=$CLANG_TIDY_CHECKS)"
25-
if [[ $? -eq 0 ]]; then
26-
echo "$TOOL passed."
27-
exit 0
28-
else
29-
echo "To reproduce it locally please run"
30-
echo -e "\tgit checkout $TRAVIS_BRANCH"
31-
echo -e "Command: git diff -U0 $TRAVIS_BRANCH..origin/master | clang-tidy-diff.py -p1 -clang-tidy-binary \$(which clang-tidy) -checks=$CLANG_TIDY_CHECKS"
32-
echo "$RESULT_OUTPUT"
33-
exit 1
34-
fi
19+
clang-tidy --version
20+
exit 0

.github/workflows/code_analysis.yml

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
2424
runs-on: ubuntu-latest
2525
env:
26-
TRAVIS_BRANCH: ${{ github.base_ref }}
26+
TRAVIS_BRANCH: ${{ github.base_ref }}
2727
TRAVIS_PULL_REQUEST_REPO: ${{ github.event.pull_request.head.repo.html_url }}
2828
TRAVIS_PULL_REQUEST_BRANCH: ${{ github.head_ref }}
2929
BASE_COMMIT: ${{ github.event.pull_request.base.sha }}
@@ -48,6 +48,55 @@ jobs:
4848
PATH=/usr/lib/llvm-20/bin:${PATH}
4949
.ci/format_script.sh
5050
51+
clang-tidy:
52+
# For any event that is not a PR, the CI will always run. In PRs, the CI
53+
# can be skipped if the tag [skip-ci] is written in the title.
54+
if: |
55+
(github.repository_owner == 'root-project' && github.event_name != 'pull_request') ||
56+
(github.event_name == 'pull_request' && !(
57+
contains(github.event.pull_request.title, '[skip-ci]') ||
58+
contains(github.event.pull_request.labels.*.name, 'skip ci') ||
59+
contains(github.event.pull_request.labels.*.name, 'skip code analysis')
60+
))
61+
62+
runs-on:
63+
- self-hosted
64+
- linux
65+
- x64
66+
67+
container:
68+
image: registry.cern.ch/root-ci/alma10:buildready
69+
options: '--security-opt label=disable --rm'
70+
env:
71+
OS_APPLICATION_CREDENTIAL_ID: '7f5b64a265244623a3a933308569bdba'
72+
OS_APPLICATION_CREDENTIAL_SECRET: ${{ secrets.OS_APPLICATION_CREDENTIAL_SECRET }}
73+
OS_AUTH_TYPE: 'v3applicationcredential'
74+
OS_AUTH_URL: 'https://keystone.cern.ch/v3'
75+
OS_IDENTITY_API_VERSION: 3
76+
OS_INTERFACE: 'public'
77+
OS_REGION_NAME: 'cern'
78+
PYTHONUNBUFFERED: true
79+
80+
env:
81+
TRAVIS_BRANCH: ${{ github.base_ref }}
82+
TRAVIS_PULL_REQUEST_REPO: ${{ github.event.pull_request.head.repo.html_url }}
83+
TRAVIS_PULL_REQUEST_BRANCH: ${{ github.head_ref }}
84+
BASE_COMMIT: ${{ github.event.pull_request.base.sha }}
85+
86+
steps:
87+
- uses: actions/checkout@v6
88+
with:
89+
fetch-depth: 1
90+
ref: ${{ github.event.pull_request.head.sha }}
91+
path: ROOT-CI/src
92+
- name: Fetch base sha
93+
run: cd ROOT-CI/src && git fetch --depth=1 origin +${{github.event.pull_request.base.sha}}:origin/base_sha
94+
- name: Determine merge base
95+
run: echo "MERGE_BASE=$(cd ROOT-CI/src && git merge-base ${{ github.event.pull_request.base.sha }} HEAD)" >> $GITHUB_ENV
96+
- name: run clang-tidy script
97+
run: |
98+
ROOT-CI/src/.ci/tidy_script.sh
99+
51100
ruff:
52101
if: |
53102
(github.repository_owner == 'root-project' && github.event_name != 'pull_request') ||

0 commit comments

Comments
 (0)