Skip to content

Commit

Permalink
Feature #2379 main_v11.1 sonarqube updates (#2851)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnHalleyGotway authored Apr 8, 2024
1 parent 8ee59fc commit 7a8712d
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 143 deletions.
4 changes: 2 additions & 2 deletions .github/jobs/build_sonarqube_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ fi

# Copy the .scannerwork directory from the image
id=$(docker create ${DOCKERHUB_TAG})
time_command docker cp $id:/met/.scannerwork /tmp/met_scannerwork
time_command mkdir -p /tmp/scannerwork
time_command docker cp $id:/met/.scannerwork/report-task.txt /tmp/scannerwork/report-task.txt
docker rm -v $id

17 changes: 3 additions & 14 deletions .github/workflows/sonarqube.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,11 @@ jobs:
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

- name: SonarQube Python Quality Gate check
id: sonarqube-python-quality-gate-check
- name: SonarQube Quality Gate check
id: sonarqube-quality-gate-check
uses: sonarsource/sonarqube-quality-gate-action@master
with:
scanMetadataReportFile: /tmp/met_scannerwork/python-report-task.txt
timeout-minutes: 5
env:
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

- name: SonarQube CXX Quality Gate check
id: sonarqube-cxx-quality-gate-check
uses: sonarsource/sonarqube-quality-gate-action@master
with:
scanMetadataReportFile: /tmp/met_scannerwork/cxx-report-task.txt
scanMetadataReportFile: /tmp/scannerwork/report-task.txt
timeout-minutes: 5
env:
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
Expand All @@ -99,4 +89,3 @@ jobs:
name: logs_sonarqube
path: ${{ runner.workspace }}/logs
if-no-files-found: ignore

1 change: 0 additions & 1 deletion internal/scripts/docker/Dockerfile.sonarqube
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,3 @@ RUN if [ ! -e "${MET_REPO_DIR}/configure.ac" ]; then \

RUN cd ${MET_REPO_DIR} \
&& internal/scripts/docker/build_met_sonarqube.sh

54 changes: 22 additions & 32 deletions internal/scripts/docker/build_met_sonarqube.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#
# This build_met_sonarqube.sh script must be run from the top-level
# directory of the MET repository to be analyzed. It runs SonarQube to
# scan both the Python and C/C++ MET source code.
# scan the MET source code.
#
# Usage: internal/scripts/docker/build_met_sonarqube.sh
#
Expand Down Expand Up @@ -75,54 +75,37 @@ if [ -z ${SONARQUBE_OUT_DIR} ]; then
export SONARQUBE_OUT_DIR=bw-outputs
fi

# Define the version string
SONAR_PROJECT_VERSION=$(cat docs/version | cut -d'=' -f2 | tr -d '" ')

# Store the full path to the scripts directory
SONAR_PROPERTIES_DIR=internal/scripts/sonarqube
SONAR_PROPERTIES=sonar-project.properties

# Copy sonar-project.properties for Python code
[ -e $SONAR_PROPERTIES ] && rm $SONAR_PROPERTIES
sed -e "s|SONAR_TOKEN|$SONAR_TOKEN|" \
-e "s|SONAR_HOST_URL|$SONAR_HOST_URL|" \
-e "s|SONAR_PROJECT_KEY|MET-GHA-Python|" \
-e "s|SONAR_PROJECT_NAME|MET GHA Python|" \
-e "s|SONAR_BRANCH_NAME|$MET_GIT_NAME|" \
$SONAR_PROPERTIES_DIR/python.sonar-project.properties > $SONAR_PROPERTIES

# The source and reference branches must differ to define new code
if [ "$MET_GIT_NAME" != "$SONAR_REFERENCE_BRANCH" ]; then
echo "sonar.newCode.referenceBranch=${SONAR_REFERENCE_BRANCH}" >> $SONAR_PROPERTIES
fi

# Run SonarQube scan for Python code
time_command $SONAR_SCANNER

# Copy the Python scan report-task.txt file
mkdir -p /met/.scannerwork
cp .scannerwork/report-task.txt /met/.scannerwork/python-report-task.txt

# Copy sonar-project.properties for C/C++ code
# Configure the sonar-project.properties
[ -e $SONAR_PROPERTIES ] && rm $SONAR_PROPERTIES
sed -e "s|SONAR_TOKEN|$SONAR_TOKEN|" \
sed -e "s|SONAR_PROJECT_KEY|MET-GHA|" \
-e "s|SONAR_PROJECT_NAME|MET GHA|" \
-e "s|SONAR_PROJECT_VERSION|$SONAR_PROJECT_VERSION|" \
-e "s|SONAR_HOST_URL|$SONAR_HOST_URL|" \
-e "s|SONAR_PROJECT_KEY|MET-GHA-CXX|" \
-e "s|SONAR_PROJECT_NAME|MET GHA CXX|" \
-e "s|SONAR_TOKEN|$SONAR_TOKEN|" \
-e "s|SONAR_BRANCH_NAME|$MET_GIT_NAME|" \
$SONAR_PROPERTIES_DIR/sonar-project.properties > $SONAR_PROPERTIES
$SONAR_PROPERTIES_DIR/$SONAR_PROPERTIES > $SONAR_PROPERTIES

# The source and reference branches must differ to define new code
if [ "$MET_GIT_NAME" != "$SONAR_REFERENCE_BRANCH" ]; then
echo "sonar.newCode.referenceBranch=${SONAR_REFERENCE_BRANCH}" >> $SONAR_PROPERTIES
fi

# Run the configure script
# Run the MET configure script
time_command ./configure \
BUFRLIB_NAME=${BUFRLIB_NAME} \
GRIB2CLIB_NAME=${GRIB2CLIB_NAME} \
--enable-grib2 \
--enable-modis \
--enable-mode_graphics \
--enable-lidar2nc \
--enable-python
--enable-python \
CPPFLAGS="-I/usr/local/include -I/usr/local/include/freetype2 -I/usr/local/include/cairo" \
LIBS="-ltirpc"

Expand All @@ -132,11 +115,18 @@ time_command make clean
# Run SonarQube make
time_command $SONAR_WRAPPER --out-dir $SONARQUBE_OUT_DIR make

# Run SonarQube scan for C/C++ code
# Run SonarQube scan
time_command $SONAR_SCANNER
status=$?

# Check return status
if [[ $status -ne 0 ]]; then
echo "ERROR: ${0} -> the SonarQube scan returned with non-zero status (${status})!"
exit ${status}
fi

# Copy the C/C++ scan report-task.txt file
# Copy the scan report-task.txt file
mkdir -p /met/.scannerwork
cp .scannerwork/report-task.txt /met/.scannerwork/cxx-report-task.txt
cp .scannerwork/report-task.txt /met/.scannerwork/report-task.txt

[ -e $SONAR_PROPERTIES ] && rm $SONAR_PROPERTIES
17 changes: 0 additions & 17 deletions internal/scripts/sonarqube/python.sonar-project.properties

This file was deleted.

44 changes: 15 additions & 29 deletions internal/scripts/sonarqube/run_sonarqube.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
GIT_REPO="https://github.com/dtcenter/${GIT_REPO_NAME}"

function usage {
echo
echo "USAGE: $(basename $0) name"
echo " where \"name\" specifies a branch, tag, or hash."
echo
echo
echo "USAGE: $(basename $0) name"
echo " where \"name\" specifies a branch, tag, or hash."
echo
}

# Check for arguments
Expand Down Expand Up @@ -90,7 +90,6 @@ function run_command() {
return ${STATUS}
}


# Store the full path to the scripts directory
SCRIPT_DIR=`dirname $0`
if [[ ${0:0:1} != "/" ]]; then SCRIPT_DIR=$(pwd)/${SCRIPT_DIR}; fi
Expand Down Expand Up @@ -118,48 +117,35 @@ run_command "./configure --prefix=`pwd` \
--enable-lidar2nc \
--enable-python"

# Set the build id
#BUILD_ID="MET-${1}"
# Define the version string
SONAR_PROJECT_VERSION=$(grep "^version" docs/conf.py | cut -d'=' -f2 | tr -d "\'\" ")

SONAR_PROPERTIES=sonar-project.properties

# Copy sonar-project.properties for Python code
# Configure sonar-project.properties
[ -e $SONAR_PROPERTIES ] && rm $SONAR_PROPERTIES
[ -z "$SONAR_HOST_URL" ] && SONAR_HOST_URL="http://localhost:9000"
if [ -z "$SONAR_TOKEN" ]; then
echo " == ERROR == SONAR_TOKEN is not defined"
exit 1
else
sed -e "s|SONAR_TOKEN|$SONAR_TOKEN|" \
-e "s|SONAR_HOST_URL|$SONAR_HOST_URL|" \
-e "s|SONAR_PROJECT_KEY|MET_python_NB|" \
-e "s|SONAR_PROJECT_NAME|MET python Nightly Build|" \
-e "s|SONAR_BRANCH_NAME|develop|" \
$SCRIPT_DIR/python.sonar-project.properties > $SONAR_PROPERTIES

# Run SonarQube scan for Python code
run_command "$SONAR_SCANNER"

# Copy sonar-project.properties for C/C++ code
[ -e $SONAR_PROPERTIES ] && rm $SONAR_PROPERTIES
sed -e "s|SONAR_TOKEN|$SONAR_TOKEN|" \
-e "s|SONAR_HOST_URL|$SONAR_HOST_URL|" \
-e "s|SONAR_PROJECT_KEY|MET_develop_NB|" \
sed -e "s|SONAR_PROJECT_KEY|MET_NB|" \
-e "s|SONAR_PROJECT_NAME|MET Nightly Build|" \
-e "s|SONAR_BRANCH_NAME|develop|" \
$SCRIPT_DIR/sonar-project.properties > $SONAR_PROPERTIES
-e "s|SONAR_PROJECT_VERSION|$SONAR_PROJECT_VERSION|" \
-e "s|SONAR_HOST_URL|$SONAR_HOST_URL|" \
-e "s|SONAR_TOKEN|$SONAR_TOKEN|" \
-e "s|SONAR_BRANCH_NAME|${1}|" \
$SCRIPT_DIR/$SONAR_PROPERTIES > $SONAR_PROPERTIES

# Run SonarQube clean
run_command "make clean"

# Run SonarQube make
# Run SonarQube build wrapper
run_command "$SONAR_WRAPPER --out-dir $SONARQUBE_OUT_DIR make"

# Run SonarQube scan for C/C++ code
# Run SonarQube scan
run_command "$SONAR_SCANNER"

[ -e $SONAR_PROPERTIES ] && rm $SONAR_PROPERTIES
fi

# Run SonarQube report generator to make a PDF file
#TODAY=`date +%Y%m%d`
16 changes: 7 additions & 9 deletions internal/scripts/sonarqube/sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
# Project and source code settings
sonar.projectKey=SONAR_PROJECT_KEY
sonar.projectName=SONAR_PROJECT_NAME
sonar.projectVersion=1.0

sonar.sources=src
sonar.projectVersion=SONAR_PROJECT_VERSION
sonar.branch.name=SONAR_BRANCH_NAME
sonar.sources=src,scripts/python,data/wrappers
sonar.python.version=3.6.3
sonar.sourceEncoding=UTF-8

# The build-wrapper output dir
sonar.cfamily.build-wrapper-output=bw-outputs

# Encoding of the source files
sonar.sourceEncoding=UTF-8

#----- Default SonarQube server
# SonarQube server
sonar.host.url=SONAR_HOST_URL

sonar.token=SONAR_TOKEN
sonar.branch.name=SONAR_BRANCH_NAME
File renamed without changes.
39 changes: 0 additions & 39 deletions src/libcode/vx_python3_utils/point.py

This file was deleted.

0 comments on commit 7a8712d

Please sign in to comment.