actions: static/rpm-spec check added
[platform/upstream/nnstreamer.git] / .github / workflows / static.check.yml
1 name: Static checkers and verifiers
2
3 # "Pre-build" Scripts from TAOS-CI
4 # @todo Make this "reusable workflow" and publish for all projects.
5
6 ## Common variables and files
7 # - changed_file_list in GITHUB_ENV: the list of files updated in this pull-request.
8
9 on:
10   pull_request:
11     branches: [ main ]
12
13 jobs:
14   simple_script_checkers:
15     runs-on: ubuntu-latest
16     name: Static checks
17     steps:
18       - name: Preparing step 1... Checking out
19         uses: actions/checkout@v4
20         with:
21           ref: ${{ github.event.pull_request.head.sha }}
22           fetch-depth: -${{ github.event.pull_request.commits }}
23       - name: Preparing step 2... Installing packages
24         run: sudo apt-get update && sudo apt-get install clang-format git grep gawk exuberant-ctags indent pylint rpmlint aha
25       - name: Preparing step 3... Identify changed files
26         run: |
27           tmpfile_pre=$(mktemp)
28           tmpfile=$(mktemp)
29           git show --pretty="format:" --name-only --diff-filter=AMRC ${{ github.event.pull_request.head.sha}} -${{ github.event.pull_request.commits }} > ${tmpfile_pre}
30
31           ####### Screen out deleted files from the file list!!!
32
33           echo "::group::The list of changed files"
34           for file in `cat ${tmpfile_pre}`; do
35             if [[ -f $file ]]; then
36               echo "$file"
37               echo "$file" >> $tmpfile
38             else
39               echo "$file is deleted."
40             fi
41           done
42           echo "::endgroup::"
43           echo "changed_file_list=${tmpfile}" >> "$GITHUB_ENV"
44       - name: /Checker/ clang-format for .cc/.hh/.hpp/.cpp files
45         # Originally from "pr-prebuild-clang"
46         # Need "clang-format"
47         run: |
48           echo "Check .clang-format file"
49           if [ ! -f ".clang-format" ]; then
50             echo "::error .clang-format file not found"
51             exit 1
52           fi
53           for file in `cat $changed_file_list`; do
54             echo "Checking $file"
55             if [[ "$file" =~ .*\.hh$ ]] || [[ "$file" =~ .*\.hpp ]] || [[ "$file" =~ .*\.cc$ ]] || [[ "$file" =~ .*\.cpp ]]; then
56               clang-format -i ${file}
57             fi
58           done
59           git diff -- *.cc *.hh *.hpp *.cpp > .ci.clang-format.patch
60           SIZE=$(stat -c%s .ci.clang-format.patch)
61           if [[ $SIZE -ne 0 ]]; then
62             echo "::group::The clang-format complaints..."
63             cat .ci.clang-format.patch
64             echo "::endgroup::"
65             echo "::error clang-format has found style errors in C++ files."
66             exit 1
67           fi
68           echo "clang-format shows no style errors."
69       - name: /Checker/ File size check
70         # Originally from "pr-prebuild-file-size"
71         run: |
72           for file in `cat $changed_file_list`; do
73             echo "Checking $file"
74             FILESIZE=$(stat -c%s "$file")
75             FILESIZE_NUM=`echo $FILESIZE | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'`
76             if [[ $FILESIZE -gt $[ 5*1024*1024 ] ]]; then
77               echo "::error $file is too large: $FILESIZE > 5MiB"
78               exit 1
79             fi
80           done
81       - name: /Checker/ Doxygen tag check
82         # Originally from "pr-prebuild-doxygen-tag"
83         # Need "grep"
84         run: |
85           bash .github/workflows/static.check.scripts/doxygen-tag.sh $changed_file_list 1
86       - name: /Checker/ Indent
87         # Originally from "pr-prebuild-indent"
88         # Need "indent"
89         run: |
90           bash .github/workflows/static.check.scripts/indent.sh $changed_file_list
91       - name: /Checker/ Pylint
92         # Originally from "pr-prebuild-pylint"
93         # Need "pylint"
94         run: |
95           bash .github/workflows/static.check.scripts/pylint.sh $changed_file_list
96       - name: /Checker/ Newline
97         # Originally from "pr-prebuild-newline"
98         run: |
99           bash .github/workflows/static.check.scripts/newline.sh $changed_file_list
100       - name: /Checker/ RPM Spec
101         # Originally from "pr-prebuild-rpm-spec"
102         # Need "rpmlint", "aha"
103         # Tolerated errors: 40 (make it 0 someday!!!)
104         run: |
105           bash .github/workflows/static.check.scripts/rpm-spec.sh $changed_file_list 40