Skip to content

Commit fc0969a

Browse files
authored
Add clang-tidy to CI (#1830)
1 parent 5e8c5ba commit fc0969a

File tree

3 files changed

+67
-5
lines changed

3 files changed

+67
-5
lines changed

.github/workflows/clang-tidy.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Apply clang-tidy
2+
on:
3+
pull_request:
4+
5+
permissions:
6+
contents: write
7+
8+
jobs:
9+
clang-tidy:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Install just
13+
uses: extractions/setup-just@v3
14+
15+
- name: Checkout ldmx-sw
16+
uses: actions/checkout@v5
17+
with:
18+
submodules: 'recursive'
19+
fetch-depth: 0
20+
ref: trunk
21+
22+
- name: Pull latest changes
23+
run: |
24+
git fetch origin ${GITHUB_HEAD_REF}
25+
git checkout ${GITHUB_HEAD_REF}
26+
git pull origin ${GITHUB_HEAD_REF}
27+
28+
- name: Run clang tidy on the C++
29+
run: |
30+
just install-denv init
31+
just compile
32+
just tidy-cpp
33+
34+
- name: Set up git user as the bot
35+
run: |
36+
git config user.name 'github-actions[bot]'
37+
git config user.email 'github-actions[bot]@users.noreply.github.com'
38+
39+
- name: Auto-commit the changes
40+
run: |
41+
git add .
42+
git commit -m "Apply clang-tidy" || echo "No changes to commit"
43+
id: commit
44+
45+
- name: Push changes
46+
if: github.ref != 'refs/heads/trunk'
47+
run: |
48+
git push origin HEAD:${GITHUB_HEAD_REF}
49+

Ecal/test/EcalDigiPipelineTest.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static const double MIP_SI_ENERGY = 0.130;
2929
* charge [fC] * (1000 electrons / 0.1602 fC) * (1 MIP / 37 000 electrons) *
3030
* (0.130 MeV / 1 MIP)
3131
*/
32-
static const double ME_V_PER_F_C = MIP_SI_ENERGY / (37 * 0.1602);
32+
static const double MEV_PER_FC = MIP_SI_ENERGY / (37 * 0.1602);
3333

3434
/**
3535
* Maximum percent error that a single hit
@@ -154,7 +154,7 @@ class EcalFakeSimHits : public framework::Producer {
154154
* The maximum value to be readout is 4096 TDC which
155155
* is equivalent to ~10000fC deposited charge.
156156
*/
157-
const double MAX_ENERGY = 10000. * ME_V_PER_F_C;
157+
const double MAX_ENERGY = 10000. * MEV_PER_FC;
158158

159159
/**
160160
* Minimum energy to make a sim hit for [MeV]
@@ -293,7 +293,7 @@ class EcalCheckEnergyReconstruction : public framework::Analyzer {
293293

294294
auto trig_digi = trig_digis.at(0);
295295
float tp_energy =
296-
8 * trig_digi.linearPrimitive() * 320. / 1024 * ME_V_PER_F_C;
296+
8 * trig_digi.linearPrimitive() * 320. / 1024 * MEV_PER_FC;
297297

298298
CHECK_THAT(tp_energy, IsCloseEnough(truth_energy, MAX_ENERGY_ERROR_TP,
299299
MAX_ENERGY_PERCENT_ERROR_TP));

justfile

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,21 @@ tidy-cpp *ARGS='-p build --fix -fix-errors --quiet ':
180180
#!/usr/bin/env sh
181181
set -exu
182182
format_list=$(mktemp)
183-
git diff --name-only --diff-filter=AM origin/trunk..HEAD | egrep '(\.h|\.cxx)$' | grep -v '^HLS' > ${format_list}
184-
#git ls-tree -r HEAD --name-only | egrep '(\.h|\.cxx)$' | grep -v '^HLS' > ${format_list}
183+
git diff --name-only origin/trunk..HEAD | egrep '(\.h|\.cxx)$' > ${format_list}
184+
# if the list is not empty, run clang-tidy
185+
if [ ! -s ${format_list} ]; then
186+
echo "No C++ files changed, skipping clang-tidy"
187+
else
188+
denv clang-tidy $(cat ${format_list}) {{ ARGS }}
189+
rm ${format_list}
190+
fi
191+
192+
193+
tidy-cpp-dir DIR *ARGS='-p build --fix -fix-errors --quiet ':
194+
#!/usr/bin/env sh
195+
set -exu
196+
format_list=$(mktemp)
197+
find {{ DIR }} -name "*.h" -o -name "*.cxx" > ${format_list}
185198
denv clang-tidy $(cat ${format_list}) {{ ARGS }}
186199
rm ${format_list}
187200

0 commit comments

Comments
 (0)