File: submit-to-sonarcloud.sh

package info (click to toggle)
snoopy 2.5.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,988 kB
  • sloc: ansic: 7,167; sh: 4,514; makefile: 1,095
file content (119 lines) | stat: -rwxr-xr-x 2,345 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash



### Configure shell
#
set -e
set -u
set -o pipefail



### Settings
#
SONAR_SETTINGS_FILE="./dev-tools/submit-to-sonarcloud.conf"
BUILD_WRAPPER_OUTPUT_DIR="sonarcloud-build-wrapper-output"



### Help function
#
displayHelp()
{
    cat <<EOF
To submit build to SonarCloud, some environment variables must be defined:

export SONAR_TOKEN=""

Alternatively you may store those settings in the following config file:

    $SONAR_SETTINGS_FILE

EOF
}



### Include Coverity settings file
#
if [ -f $SONAR_SETTINGS_FILE ]; then
    echo "Reading SonarCloud settings file $SONAR_SETTINGS_FILE"
    . $SONAR_SETTINGS_FILE
else
    echo "Coverity settings file does not exist: $SONAR_SETTINGS_FILE"
fi



### Check if all environmental variables are set
#
if [ "x$SONAR_TOKEN" == "x" ]; then
    echo "ERROR: SONAR_TOKEN is not set."
    displayHelp
    exit 1
fi

# Export, as we're not passing the token explicitly as an argument
export SONAR_TOKEN



### Check for the presence of required tools
#
if ! command -v build-wrapper-linux-x86-64 > /dev/null; then
    echo "ERROR: Unable to find 'build-wrapper-linux-x86-64'."
    exit 1
fi
if ! command -v sonar-scanner > /dev/null; then
    echo "ERROR: Unable to find 'sonar-scanner'."
    exit 1
fi



### Configure
#

# Clean
./dev-tools/clean-git-repository.sh

# Configure
./bootstrap.sh
./configure --enable-everything --enable-code-coverage



### Build with SonarCloud wrapper
#
build-wrapper-linux-x86-64 \
    --out-dir $BUILD_WRAPPER_OUTPUT_DIR \
    make



### Generate coverage info
#
# No need to run `make check`, as the test suite is started by
# the `coverage` target in Makefile.
#
make coverage



### Analyze and submit
#
CURRENT_BRANCH_NAME=`git branch --show-current`
SONARCLOUD_TAG=`./dev-tools/libexec/get-sonarcloud-tag.sh`
sonar-scanner \
  -Dsonar.organization=a2o \
  -Dsonar.projectKey=snoopy \
  -Dsonar.sources=. \
  -Dsonar.coverage.exclusions=tests/**/*,src/entrypoint/execve-wrapper* \
  -Dsonar.cpd.exclusions=tests/**/*,src/entrypoint/* \
  -Dsonar.branch.name=$CURRENT_BRANCH_NAME \
  -Dsonar.projectVersion=$SONARCLOUD_TAG \
  -Dsonar.cfamily.build-wrapper-output=$BUILD_WRAPPER_OUTPUT_DIR \
  -Dsonar.cfamily.gcov.reportsPath=. \
  -Dsonar.host.url=https://sonarcloud.io
echo "INFO: Submission tag: $SONARCLOUD_TAG (branch: $CURRENT_BRANCH_NAME)"