#!/bin/bash
#/*
# * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
# * contributor license agreements. See the NOTICE file distributed with
# * this work for additional information regarding copyright ownership.
# * The OpenAirInterface Software Alliance licenses this file to You under
# * the OAI Public License, Version 1.1 (the "License"); you may not use this file
# * except in compliance with the License.
# * You may obtain a copy of the License at
# *
# * http://www.openairinterface.org/?page_id=698
# *
# * Unless required by applicable law or agreed to in writing, software
# * distributed under the License is distributed on an "AS IS" BASIS,
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# * See the License for the specific language governing permissions and
# * limitations under the License.
# *-------------------------------------------------------------------------------
# * For more information about the OpenAirInterface (OAI) Software Alliance:
# * contact@openairinterface.org
# */
function report_build_usage {
echo "OAI CI VM script"
echo " Original Author: Raphael Defosseux"
echo ""
echo "Usage:"
echo "------"
echo " oai-ci-vm-tool report-build [OPTIONS]"
echo ""
echo "Options:"
echo "--------"
echo ""
echo " --help OR -h"
echo " Print this help message."
echo ""
echo "Job Options:"
echo "------------"
echo ""
echo " --git-url #### OR -gu ####"
echo " Specify the URL of the GIT Repository."
echo ""
echo " --job-name #### OR -jn ####"
echo " Specify the name of the Jenkins job."
echo ""
echo " --build-id #### OR -id ####"
echo " Specify the build ID of the Jenkins job."
echo ""
echo " --workspace #### OR -ws ####"
echo " Specify the workspace."
echo ""
echo " --trigger merge-request OR -mr"
echo " --trigger push OR -pu"
echo " Specify trigger action of the Jenkins job. Either a merge-request event or a push event."
echo ""
echo "Merge-Request Options:"
echo "----------------------"
echo ""
echo " --src-branch #### OR -sb ####"
echo " Specify the source branch of the merge request."
echo ""
echo " --src-commit #### OR -sc ####"
echo " Specify the source commit ID (SHA-1) of the merge request."
echo ""
echo " --target-branch #### OR -tb ####"
echo " Specify the target branch of the merge request (usually develop)."
echo ""
echo " --target-commit #### OR -tc ####"
echo " Specify the target commit ID (SHA-1) of the merge request."
echo ""
echo "Push Options:"
echo "----------------------"
echo ""
echo " --branch #### OR -br ####"
echo " Specify the branch of the push event."
echo ""
echo " --commit #### OR -co ####"
echo " Specify the commit ID (SHA-1) of the push event."
echo ""
echo ""
}
function trigger_usage {
echo "OAI CI VM script"
echo " Original Author: Raphael Defosseux"
echo ""
echo " --trigger merge-request OR -mr"
echo " --trigger push OR -pu"
echo " Specify trigger action of the Jenkins job. Either a merge-request event or a push event."
echo ""
}
function details_table {
echo "
$1
" >> $3
echo "
" >> $3
echo "
" >> $3
echo "
File
" >> $3
echo "
Line Number
" >> $3
echo "
Status
" >> $3
echo "
Message
" >> $3
echo "
" >> $3
LIST_MESSAGES=`egrep "error:|warning:" $2 | egrep -v "jobserver unavailable|Clock skew detected.|flexran.proto"`
COMPLETE_MESSAGE="start"
for MESSAGE in $LIST_MESSAGES
do
if [[ $MESSAGE == *"/home/ubuntu/tmp"* ]] || [[ $MESSAGE == *"/tmp/CI-eNB"* ]]
then
FILENAME=`echo $MESSAGE | sed -e "s#^/home/ubuntu/tmp/##" -e "s#^.*/tmp/CI-eNB/##" | awk -F ":" '{print $1}'`
LINENB=`echo $MESSAGE | awk -F ":" '{print $2}'`
if [ "$COMPLETE_MESSAGE" != "start" ]
then
COMPLETE_MESSAGE=`echo $COMPLETE_MESSAGE | sed -e "s#‘#'#g" -e "s#’#'#g"`
echo "
$COMPLETE_MESSAGE
" >> $3
echo " " >> $3
fi
echo "
" >> $3
echo "
$FILENAME
" >> $3
echo "
$LINENB
" >> $3
else
if [[ $MESSAGE == *"warning:"* ]] || [[ $MESSAGE == *"error:"* ]]
then
MSGTYPE=`echo $MESSAGE | sed -e "s#:##g"`
echo "
$MSGTYPE
" >> $3
COMPLETE_MESSAGE=""
else
COMPLETE_MESSAGE=$COMPLETE_MESSAGE" "$MESSAGE
fi
fi
done
if [ "$COMPLETE_MESSAGE" != "start" ]
then
COMPLETE_MESSAGE=`echo $COMPLETE_MESSAGE | sed -e "s#‘#'#g" -e "s#’#'#g"`
echo "
$COMPLETE_MESSAGE
" >> $3
echo "
" >> $3
fi
echo "
" >> $3
}
function summary_table_header {
echo "
$1
" >> ./build_results.html
if [ -f $2/build_final_status.log ]
then
if [ `grep -c COMMAND $2/build_final_status.log` -eq 1 ]
then
COMMAND=`grep COMMAND $2/build_final_status.log | sed -e "s#COMMAND: ##"`
else
COMMAND="Unknown"
fi
if [ `grep -c BUILD_OK $2/build_final_status.log` -eq 1 ]
then
echo "
" >> ./build_results.html
echo " $COMMAND " >> ./build_results.html
echo " BUILD was a FAILURE! " >> ./build_results.html
echo "
" >> ./build_results.html
fi
else
echo "
" >> ./build_results.html
echo " COULD NOT DETERMINE BUILD FINAL STATUS! " >> ./build_results.html
echo "
" >> ./build_results.html
fi
echo "
" >> ./build_results.html
echo "
" >> ./build_results.html
echo "
Element
" >> ./build_results.html
echo "
Status
" >> ./build_results.html
echo "
Nb Errors
" >> ./build_results.html
echo "
Nb Warnings
" >> ./build_results.html
echo "
" >> ./build_results.html
}
function summary_table_row {
echo "
" >> ./build_results.html
echo "
$1" >> ./build_results.html
if [ -f $2 ]
then
BUILD_STATUS=`egrep -c "$3" $2`
if [ $BUILD_STATUS -eq 1 ]
then
echo "
OK" >> ./build_results.html
else
echo "
KO" >> ./build_results.html
fi
NB_ERRORS=`egrep -c "error:" $2`
if [ $NB_ERRORS -eq 0 ]
then
echo "
$NB_ERRORS" >> ./build_results.html
else
echo "
$NB_ERRORS" >> ./build_results.html
fi
NB_WARNINGS=`egrep "warning:" $2 | egrep -v "jobserver unavailable|Clock skew detected.|flexran.proto" | egrep -c "warning:"`
if [ $NB_WARNINGS -eq 0 ]
then
echo "
$NB_WARNINGS" >> ./build_results.html
else
if [ $NB_WARNINGS -gt 20 ]
then
echo "
$NB_WARNINGS" >> ./build_results.html
else
echo "
$NB_WARNINGS" >> ./build_results.html
fi
fi
if [ $NB_ERRORS -ne 0 ] || [ $NB_WARNINGS -ne 0 ]
then
details_table "$1" $2 $4
fi
else
echo "
Unknown" >> ./build_results.html
echo "
--" >> ./build_results.html
echo "
--" >> ./build_results.html
fi
echo "
" >> ./build_results.html
}
function summary_table_footer {
echo "
" >> ./build_results.html
}
function sca_summary_table_header {
echo "
$2
" >> ./build_results.html
NB_ERRORS=`egrep -c "severity=\"error\"" $1`
NB_WARNINGS=`egrep -c "severity=\"warning\"" $1`
ADDED_ERRORS="0"
ADDED_WARNINGS="0"
FINAL_LOG=`echo $1 | sed -e "s#cppcheck\.xml#build_final_status.log#"`
if [ `grep -c COMMAND $FINAL_LOG` -eq 1 ]
then
COMMAND=`grep COMMAND $FINAL_LOG | sed -e "s#COMMAND: ##"`
else
COMMAND="Unknown"
fi
if [ $MR_TRIG -eq 1 ]
then
if [ -d ../../cppcheck_archives ]
then
if [ -d ../../cppcheck_archives/$JOB_NAME ]
then
ADDED_ERRORS=`diff $1 ../../cppcheck_archives/$JOB_NAME/cppcheck.xml | egrep --color=never "^<" | egrep -c "severity=\"error"`
ADDED_WARNINGS=`diff $1 ../../cppcheck_archives/$JOB_NAME/cppcheck.xml | egrep --color=never "^<" | egrep -c "severity=\"warning"`
fi
fi
local TOTAL_NUMBER=$[$ADDED_ERRORS+$ADDED_WARNINGS]
if [ -f $JENKINS_WKSP/oai_cppcheck_added_errors.txt ]; then rm -f $JENKINS_WKSP/oai_cppcheck_added_errors.txt; fi
echo "$TOTAL_NUMBER" > $JENKINS_WKSP/oai_cppcheck_added_errors.txt
fi
if [ $NB_ERRORS -eq 0 ] && [ $NB_WARNINGS -eq 0 ]
then
echo "
" >> ./build_results.html
echo " $COMMAND
" >> ./build_results.html
echo " CPPCHECK found NO error and NO warning " >> ./build_results.html
echo "
" >> ./build_results.html
else
if [ $NB_ERRORS -eq 0 ]
then
echo "
" >> ./build_results.html
echo " $COMMAND
" >> ./build_results.html
if [ $PU_TRIG -eq 1 ]
then
echo " CPPCHECK found NO error and $NB_WARNINGS warnings " >> ./build_results.html
fi
if [ $MR_TRIG -eq 1 ]
then
if [ $ADDED_WARNINGS -eq 0 ]
then
echo " CPPCHECK found NO error and $NB_WARNINGS warnings " >> ./build_results.html
else
echo " CPPCHECK found NO error and $NB_WARNINGS warnings " >> ./build_results.html
fi
fi
echo "
" >> ./build_results.html
else
echo "
" >> ./build_results.html
echo " $COMMAND
" >> ./build_results.html
if [ $PU_TRIG -eq 1 ]
then
echo " CPPCHECK found $NB_ERRORS errors and $NB_WARNINGS warnings " >> ./build_results.html
fi
if [ $MR_TRIG -eq 1 ]
then
if [ $ADDED_ERRORS -eq 0 ] && [ $ADDED_WARNINGS -eq 0 ]
then
echo " CPPCHECK found $NB_ERRORS errors and $NB_WARNINGS warnings " >> ./build_results.html
else
echo " CPPCHECK found $NB_ERRORS errors and $NB_WARNINGS warnings " >> ./build_results.html
echo " " >> ./build_results.html
echo " " >> ./build_results.html
echo " This Merge Request may have introduced up to $ADDED_ERRORS errors and $ADDED_WARNINGS warnings. " >> ./build_results.html
fi
fi
echo "
" >> ./build_results.html
fi
fi
if [ $PU_TRIG -eq 1 ]
then
if [ -d ../../cppcheck_archives ]
then
if [ -d ../../cppcheck_archives/$JOB_NAME ]
then
cp $1 ../../cppcheck_archives/$JOB_NAME
fi
fi
fi
echo " " >> ./build_results.html
echo "
" >> ./build_results.html
if [ -f ./oai_rules_result.txt ]
then
echo "
OAI Coding / Formatting Guidelines Check
" >> ./build_results.html
NB_FILES=`cat ./oai_rules_result.txt`
if [ $NB_FILES = "0" ]
then
echo "
" >> ./build_results.html
if [ $PU_TRIG -eq 1 ]; then echo " All files in repository follow OAI rules. " >> ./build_results.html; fi
if [ $MR_TRIG -eq 1 ]; then echo " All modified files in Merge-Request follow OAI rules. " >> ./build_results.html; fi
echo "
" >> ./build_results.html
else
echo "
" >> ./build_results.html
if [ $PU_TRIG -eq 1 ]; then echo " $NB_FILES files in repository DO NOT follow OAI rules. " >> ./build_results.html; fi
if [ $MR_TRIG -eq 1 ]; then echo " $NB_FILES modified files in Merge-Request DO NOT follow OAI rules. " >> ./build_results.html; fi
echo "
" >> ./build_results.html
fi
if [ -f ./oai_rules_result_list.txt ]
then
echo " " >> ./build_results.html
echo "
" >> ./build_results.html
echo "
Please apply the following command to this(ese) file(s):