-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild-analyze.sh
executable file
·35 lines (27 loc) · 1.87 KB
/
build-analyze.sh
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
#!/bin/bash
# SonarQube needs a full clone to work correctly but some CIs perform shallow clones
# so we first need to make sure that the source repository is complete
git fetch --unshallow
export SONAR_HOST_URL="${SONAR_HOST_URL}" # Comes from a Github secret
#export SONAR_TOKEN= # Access token coming from SonarQube projet creation page. In this example, it is defined in the environement through a Github secret.
export SONAR_SCANNER_VERSION="5.0.1.3006" # Find the latest version in the "Linux" link on this page:
# https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/
export BUILD_WRAPPER_OUT_DIR="bw-output" # Directory where build-wrapper output will be placed
mkdir $HOME/.sonar
# Download build-wrapper
curl -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip "${SONAR_HOST_URL}/static/cpp/build-wrapper-linux-x86.zip"
unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/
export PATH=$HOME/.sonar/build-wrapper-linux-x86:$PATH
# Download sonar-scanner
curl -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux.zip
unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
export PATH=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux/bin:$PATH
# Setup the build system
autoreconf --install
./configure
# Build inside the build-wrapper
build-wrapper-linux-x86-64 --out-dir $BUILD_WRAPPER_OUT_DIR make clean all
# Run sonar scanner
sonar-scanner -Dsonar.host.url="${SONAR_HOST_URL}" -Dsonar.login=$SONAR_TOKEN -Dsonar.cfamily.compile-commands=$BUILD_WRAPPER_OUT_DIR/compile_commands.json
# if you are using using SonarQube 10.5 or earlier, replace -Dsonar.cfamily.compile-commands with -Dsonar.cfamily.build-wrapper-output=$BUILD_WRAPPER_OUT_DIR
# as build-wrapper does not generate a compile_commands.json file before SonarQube 10.6