infra bot: Add Memcheck bot (valgrind)
[platform/core/graphics/tizenvg.git] / .github / workflows / cpp_lint_check.sh
1 #!/bin/bash
2
3 if [[ -z "$GITHUB_TOKEN" ]]; then
4         echo "The GITHUB_TOKEN is required."
5         exit 1
6 fi
7
8 FILES_LINK=`jq -r '.pull_request._links.self.href' "$GITHUB_EVENT_PATH"`/files
9 echo "Files = $FILES_LINK"
10
11 curl $FILES_LINK > files.json
12 FILES_URLS_STRING=`jq -r '.[].raw_url' files.json`
13
14 readarray -t URLS <<<"$FILES_URLS_STRING"
15
16 echo "File names: $URLS"
17
18 mkdir files
19 cd files
20 for i in "${URLS[@]}"
21 do
22    echo "Downloading $i"
23    curl -LOk --remote-name $i 
24 done
25
26 echo "Files downloaded!"
27 echo "Performing checkup:"
28
29 cpplint --filter=-,\
30 +whitespace/parens,\
31 +whitespace/indent,\
32 +whitespace/end_of_line,\
33 +whitespace/blank_line \
34 --extension=cpp,h,c \
35 --recursive \
36 ./ > cpp-report.txt 2>&1
37
38 PAYLOAD_CPPLINT=`cat cpp-report.txt`
39 COMMENTS_URL=$(cat $GITHUB_EVENT_PATH | jq -r .pull_request.comments_url)
40
41 echo $COMMENTS_URL
42 echo "Cppcheck errors:"
43 echo $PAYLOAD_CPPLINT
44
45 if [[ $PAYLOAD_CPPLINT == *"Total errors found: "* ]]; then
46   OUTPUT+=$'\n**CODING STYLE CHECK**:\n'
47   OUTPUT+=$'\n```\n'
48   OUTPUT+="$PAYLOAD_CPPLINT"
49   OUTPUT+=$'\n```\n' 
50 fi
51
52 PAYLOAD=$(echo '{}' | jq --arg body "$OUTPUT" '.body = $body')
53
54 curl -s -S -H "Authorization: token $GITHUB_TOKEN" --header "Content-Type: application/vnd.github.VERSION.text+json" --data "$PAYLOAD" "$COMMENTS_URL"