Skip to content

Commit 7f3d749

Browse files
Add job to check formatting with clang-format 6.0
There's no clang-format 6.0 for available ubunut versions so first binary packages from older LTS are loaded. One of the packages is forced to omit python dependency, current packages are named python2. Relates-To: OCMAM-157 Signed-off-by: Rustam Gamidov <[email protected]>
1 parent 7d33c0b commit 7f3d749

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed

.github/workflows/psv_pipelines.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,47 @@ jobs:
273273
- name: Commit checker script. Verify commit text
274274
run: scripts/misc/commit_checker.sh
275275
shell: bash
276+
277+
psv-formatting-checker:
278+
name: PSV.Clang.Format.Checker
279+
runs-on: ubuntu-22.04
280+
env:
281+
CLANG_FORMAT_FILE: "clang-format.diff"
282+
steps:
283+
- name: Check out repository
284+
uses: actions/checkout@v4
285+
- name: Setup environment
286+
run: |
287+
set +x
288+
set -e
289+
sudo apt-get update
290+
sudo apt-get install -y wget libedit2 libtinfo5 python2
291+
alias python=python2
292+
mkdir _os_deps
293+
cd _os_deps
294+
wget https://apt.llvm.org/bionic/pool/main/l/llvm-toolchain-6.0/clang-format-6.0_6.0.1~svn334776-1~exp1~20190309042703.125_amd64.deb
295+
wget https://apt.llvm.org/bionic/pool/main/l/llvm-toolchain-6.0/libllvm6.0_6.0.1~svn334776-1~exp1~20190309042703.125_amd64.deb
296+
wget http://old-releases.ubuntu.com/ubuntu/pool/main/libf/libffi/libffi6_3.2.1-9_amd64.deb
297+
sudo dpkg -i libffi6_3.2.1-9_amd64.deb
298+
sudo dpkg -i libllvm6.0_6.0.1~svn334776-1~exp1~20190309042703.125_amd64.deb
299+
sudo dpkg -i --force-depends clang-format-6.0_6.0.1~svn334776-1~exp1~20190309042703.125_amd64.deb
300+
cd ..
301+
shell: bash
302+
- name: "Clang format checker script"
303+
run: ./scripts/misc/clang_format_ci.sh
304+
shell: bash
305+
- name: Store formatting check results
306+
uses: actions/upload-artifact@v4
307+
with:
308+
name: clang-format-diff
309+
path: ${{ env.CLANG_FORMAT_FILE }}
310+
- name: Verify check result
311+
run: |
312+
set +x
313+
if [ -s ${CLANG_FORMAT_FILE} ] ; then
314+
echo "Unformatted files are detected. "
315+
echo "You may apply provided patch. Download from the workflow summary and unpack to root of repository."
316+
echo "Then run: git apply $CLANG_FORMAT_FILE"
317+
exit 1
318+
fi
319+
shell: bash

scripts/misc/clang_format_ci.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
#
3+
# Copyright (C) 2025 HERE Europe B.V.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
# SPDX-License-Identifier: Apache-2.0
18+
# License-Filename: LICENSE
19+
#
20+
21+
# Important 2 lines
22+
set +e
23+
set -x
24+
25+
# This script gets the changed files in the pull request, and runs
26+
# clang-format tool to verify them
27+
28+
# Get the current branch name
29+
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
30+
31+
if [[ $CURRENT_BRANCH == "master" ]]; then
32+
printf "Currently in master branch, skipping clang-format run.\n"
33+
exit 0
34+
else
35+
printf "Currently in %s branch. Running clang-foramt.\n" "$CURRENT_BRANCH"
36+
fi
37+
38+
git branch --all
39+
git fetch origin master
40+
git branch --all
41+
# Get affected files and filter source files
42+
FILES=$(git diff-tree --no-commit-id --name-only -r origin/master "$CURRENT_BRANCH" \
43+
| grep '\.c\|\.cpp\|\.cxx\|\.h\|\.hpp\|\.hxx')
44+
45+
if [ -z "$FILES" ]; then
46+
printf "No affected files, exiting.\n"
47+
exit 0
48+
else
49+
printf "Affected files:\n %s\n" "$FILES"
50+
fi
51+
52+
printf "\n\n### Running clang-format - START ### \n\n"
53+
54+
clang-format-6.0 -i ${FILES}
55+
RESULT=$?
56+
57+
printf "\n\n### Running clang-format - DONE ### \n\n"
58+
59+
if [ "$RESULT" -ne "0" ]; then
60+
printf "\n\nClang-format failed!\n\n"
61+
exit ${RESULT}
62+
fi
63+
64+
CLANG_FORMAT_FILE=${CLANG_FORMAT_FILE:-clang-format.diff}
65+
git diff > ${CLANG_FORMAT_FILE}
66+
if [ -s ${CLANG_FORMAT_FILE} ] ; then
67+
echo "Unformatted files are detected. "
68+
echo "You may apply provided patch. Download from the workflow summary and unpack to root of repository."
69+
echo "Then run: git apply $CLANG_FORMAT_FILE"
70+
# No error here, otherwise github is skipping further steps so artifacts are not stored
71+
fi

0 commit comments

Comments
 (0)