673051b886b83e21a5edda6d6aa206442d4a5464
[platform/upstream/nnstreamer.git] / .github / workflows / static.check.scripts / indent.sh
1 #!/usr/bin/env bash
2
3 ##
4 # Imported from TAOS-CI
5 # Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved.
6 # Modified for Github-Action in 2024.
7 #
8 # Argument 1 ($1): the file containing the list of files to be checked
9
10 ##
11 # @file indent.sh
12 # @brief Check the code formatting style with GNU indent. Orignally pr-prebuild-indent.sh
13 # @see      https://www.gnu.org/software/indent
14 # @see      https://github.com/nnstreamer/TAOS-CI
15 # @see      https://github.com/nnstreamer/nnstreamer
16 # @author   Geunsik Lim <geunsik.lim@samsung.com>
17 # @author   MyungJoo Ham <myungjoo.ham@samsung.com>
18 #
19
20 if [ -z $1 ]; then
21   echo "::error The argument (file path) is not given."
22   exit 1
23 fi
24
25 files=$1
26 failed=0
27
28 if [ ! -f $files ]; then
29   echo "::error The file $files does not exists."
30   exit 1
31 fi
32
33 which indent
34 if [[ $? -ne 0 ]]; then
35   echo "::error The indent utility is not found."
36   exit 1
37 fi
38
39 echo "::group::Indent check started"
40
41 for file in `cat $files`; do
42   if [[ `file $file | grep "ASCII text" | wc -l` -gt 0 ]]; then
43     case $file in
44       *.c|*.cpp)
45         indent \
46           --braces-on-if-line \
47           --case-brace-indentation0 \
48           --case-indentation2 \
49           --braces-after-struct-decl-line \
50           --line-length80 \
51           --no-tabs \
52           --cuddle-else \
53           --dont-line-up-parentheses \
54           --continuation-indentation4 \
55           --honour-newlines \
56           --tab-size8 \
57           --indent-level2 \
58           $file
59       ;;
60     esac
61   fi
62 done
63
64 tmpfile=$(mktemp)
65 git diff > ${tmpfile}
66 PATCHFILESIZE=$(stat -c%s ${tmpfile})
67 if [[ $PATCHFILESIZE -ne 0 ]]; then
68   failed=1
69 fi
70
71 echo "::endgroup::"
72
73 if [ $failed = 1 ]; then
74     echo "::error There is an indentation style error."
75     echo "::group::The indentation style errors are..."
76     cat ${tmpfile}
77     echo "::endgroup::"
78     exit 1
79 fi