Skip to content

Commit 7dbe0c9

Browse files
Add job to check formatting with clang-format 6.0 (#1624)
There is no clang-format 6.0 binaries for current ubuntu versions. Github pool has no old ubuntu images. So preparation steps are downloading binaries from older ubuntu distros and installing them. python-is-python2 symlinks python to python2 and covers clang-format 6.0 package requirement for python. python-is-python3 is conflicting with the python-is-python2 thus removed Relates-To: OCMAM-157 Signed-off-by: Rustam Gamidov <[email protected]>
1 parent a387a38 commit 7dbe0c9

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed

.github/workflows/psv_pipelines.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,49 @@ 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
291+
mkdir _os_deps
292+
cd _os_deps
293+
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
294+
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
295+
wget https://mirrors.edge.kernel.org/ubuntu/pool/main/libf/libffi/libffi6_3.2.1-8_amd64.deb
296+
wget https://mirrors.edge.kernel.org/ubuntu/pool/universe/w/what-is-python/python-is-python2_2.7.17-4_all.deb
297+
sudo apt-get install -y ./libffi6_3.2.1-8_amd64.deb
298+
sudo apt-get install -y ./libllvm6.0_6.0.1~svn334776-1~exp1~20190309042703.125_amd64.deb
299+
sudo apt-get remove python-is-python3
300+
sudo apt-get install -y ./python-is-python2_2.7.17-4_all.deb
301+
sudo apt-get install -y ./clang-format-6.0_6.0.1~svn334776-1~exp1~20190309042703.125_amd64.deb
302+
cd ..
303+
shell: bash
304+
- name: "Clang format checker script"
305+
run: ./scripts/misc/clang_format_ci.sh
306+
shell: bash
307+
- name: Store formatting check results
308+
uses: actions/upload-artifact@v4
309+
with:
310+
name: clang-format-diff
311+
path: ${{ env.CLANG_FORMAT_FILE }}
312+
- name: Verify check result
313+
run: |
314+
set +x
315+
if [ -s ${CLANG_FORMAT_FILE} ] ; then
316+
echo "Unformatted files are detected. "
317+
echo "You may apply provided patch. Download from the workflow summary and unpack to root of repository."
318+
echo "Then run: git apply $CLANG_FORMAT_FILE"
319+
exit 1
320+
fi
321+
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)