Refactor CI and include a Coverity scan build

This commit is contained in:
Ian McInerney 2020-07-17 19:42:14 +01:00
parent 1e9d947598
commit 6a2a4643d1
4 changed files with 259 additions and 191 deletions

View File

@ -6,46 +6,6 @@ stages:
default:
image: registry.gitlab.com/kicad/kicad-ci/source_containers/master/fedora:31
##########################################################################
# This will allow the job to run whenever code events trigger it.
##########################################################################
.only_code:
only:
- master
- branches
- merge_requests
- pushes
##########################################################################
# Define a template for all the unit tests, since each one is run in a separate
# job to make the display nicer.
##########################################################################
.unit_test:
stage: test
when: on_success
needs:
- job: build_linux
artifacts: true
# We define this using a before script because GitLab cannot merge variable
# definitions across inheritance (so the variables block from this would disappear)
before_script:
- export BOOST_TEST_LOGGER='JUNIT,all,test_results.${TEST}.xml:HRF,warning'
- export CTEST_OUTPUT_ON_FAILURE=1
script:
- cd build/linux/qa
- ctest -R ${TEST}
# GitLab supports displaying the results in the GUI through JUNIT artifacts
# (https://docs.gitlab.com/ee/ci/junit_test_reports.html)
# so we upload the JUNIT results. Note that there is a bug with how paths
# are processed in the junit report (https://gitlab.com/gitlab-org/gitlab/issues/23835)
# so we can't use a glob and have to list out each hierarchy separately.
artifacts:
reports:
junit:
- build/linux/qa/*/*.xml
- build/linux/qa/*/*/*.xml
##########################################################################
# Test the formatting in a merge request using clang-format
@ -72,154 +32,7 @@ test_formatting:
- ./tools/check_coding.sh --diff --ci --commit ${MERGE_BASE_SHA}
##########################################################################
# Build KiCad and save the results
##########################################################################
build_linux:
stage: build
extends: .only_code
interruptible: false
cache:
key: "cache-linux"
paths:
- ccache/
before_script:
# CCache Config
- mkdir -p ccache
- export CCACHE_BASEDIR=${PWD}
- export CCACHE_DIR=${PWD}/ccache
script:
- mkdir -p build/linux
- cd build/linux
- cmake
-DCMAKE_C_COMPILER_LAUNCHER=ccache
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
-DCMAKE_BUILD_TYPE=Debug
-DKICAD_STDLIB_LIGHT_DEBUG=ON
-DKICAD_SCRIPTING=ON
-DKICAD_SCRIPTING_MODULES=ON
-DKICAD_SCRIPTING_PYTHON3=ON
-DKICAD_SCRIPTING_WXPYTHON=ON
-DKICAD_SCRIPTING_WXPYTHON_PHOENIX=ON
-DKICAD_SCRIPTING_ACTION_MENU=ON
-DBUILD_GITHUB_PLUGIN=ON
-DKICAD_USE_OCE=OFF
-DKICAD_USE_OCC=ON
-DKICAD_SPICE=ON
../../
- make 2>&1 | tee compilation_log.txt
- cd ../../
artifacts:
# Only save the artifacts that are needed for running the tests in the next stage
# and the compilation log. The entire build directory is too large to save as an
# artifact.
expire_in: 2 hrs
when: always
paths:
- build/linux/3d-viewer/
- build/linux/pcbnew/pcbnew.py
- build/linux/pcbnew/_pcbnew.so
- build/linux/qa/
- build/linux/compilation_log.txt
# Upload the compilation log in an easily downloadable form
report_build_warn:
stage: report
extends: .only_code
when: always
needs:
- job: build_linux
artifacts: true
script:
- echo "Uploading compilation log"
- cp build/linux/compilation_log.txt compilation_log.txt
artifacts:
expire_in: 1 year
expose_as: 'Build log'
name: "build_log.txt"
paths:
- compilation_log.txt
# Report on the metrics of the code
report_metrics:
stage: report
extends: .only_code
when: always
needs:
- job: build_linux
artifacts: true
script:
- cat build/linux/compilation_log.txt | grep "warning:" | awk '{total+=1}END{print "number_of_warnings "total}' > metrics.txt
- cat metrics.txt
artifacts:
reports:
metrics: metrics.txt
##########################################################################
# Run the code unit tests. Each QA executable is split into a separate job so that the display
# gives the test results broken down by the test executable.
##########################################################################
qa_python:
extends:
- .unit_test
- .only_code
variables:
TEST: 'qa_python'
qa_common_eeschema:
extends:
- .unit_test
- .only_code
variables:
TEST: 'common_eeschema'
qa_common_pcbnew:
extends:
- .unit_test
- .only_code
variables:
TEST: 'common_pcbnew'
qa_common_gerbview:
extends:
- .unit_test
- .only_code
variables:
TEST: 'qa_common_gerbview'
qa_pcbnew:
extends:
- .unit_test
- .only_code
variables:
TEST: 'pcbnew'
qa_eeschema:
extends:
- .unit_test
- .only_code
variables:
TEST: 'eeschema'
qa_kimath:
extends:
- .unit_test
- .only_code
variables:
TEST: 'kimath'
qa_sexpr:
extends:
- .unit_test
- .only_code
variables:
TEST: 'sexpr'
qa_kicad2step:
extends:
- .unit_test
- .only_code
variables:
TEST: 'kicad2step'
include:
- local: '/.gitlab/templates.yml'
- local: '/.gitlab/Fedora-Linux-CI.yml'
- local: '/.gitlab/coverity.yml'

150
.gitlab/Fedora-Linux-CI.yml Normal file
View File

@ -0,0 +1,150 @@
##########################################################################
# Build KiCad on Fedora and save the results
##########################################################################
build_linux:
stage: build
extends: .only_code
interruptible: false
cache:
key: "cache-linux"
paths:
- ccache/
before_script:
# CCache Config
- mkdir -p ccache
- export CCACHE_BASEDIR=${PWD}
- export CCACHE_DIR=${PWD}/ccache
script:
- mkdir -p build/linux
- cd build/linux
- cmake
-DCMAKE_C_COMPILER_LAUNCHER=ccache
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
-DCMAKE_BUILD_TYPE=Debug
-DKICAD_STDLIB_LIGHT_DEBUG=ON
-DKICAD_SCRIPTING=ON
-DKICAD_SCRIPTING_MODULES=ON
-DKICAD_SCRIPTING_PYTHON3=ON
-DKICAD_SCRIPTING_WXPYTHON=ON
-DKICAD_SCRIPTING_WXPYTHON_PHOENIX=ON
-DKICAD_SCRIPTING_ACTION_MENU=ON
-DBUILD_GITHUB_PLUGIN=ON
-DKICAD_USE_OCE=OFF
-DKICAD_USE_OCC=ON
-DKICAD_SPICE=ON
../../
- make 2>&1 | tee compilation_log.txt
- cd ../../
artifacts:
# Only save the artifacts that are needed for running the tests in the next stage
# and the compilation log. The entire build directory is too large to save as an
# artifact.
expire_in: 2 hrs
when: always
paths:
- build/linux/3d-viewer/
- build/linux/pcbnew/pcbnew.py
- build/linux/pcbnew/_pcbnew.so
- build/linux/qa/
- build/linux/compilation_log.txt
# Upload the compilation log in an easily downloadable form
report_build_warn:
stage: report
extends: .only_code
when: always
needs:
- job: build_linux
artifacts: true
script:
- echo "Uploading compilation log"
- cp build/linux/compilation_log.txt compilation_log.txt
artifacts:
expire_in: 1 year
expose_as: 'Build log'
name: "build_log.txt"
paths:
- compilation_log.txt
# Report on the metrics of the code
report_metrics:
stage: report
extends: .only_code
when: always
needs:
- job: build_linux
artifacts: true
script:
- cat build/linux/compilation_log.txt | grep "warning:" | awk '{total+=1}END{print "number_of_warnings "total}' > metrics.txt
- cat metrics.txt
artifacts:
reports:
metrics: metrics.txt
##########################################################################
# Run the code unit tests. Each QA executable is split into a separate job so that the display
# gives the test results broken down by the test executable.
##########################################################################
qa_python:
extends:
- .unit_test
- .only_code
variables:
TEST: 'qa_python'
qa_common_eeschema:
extends:
- .unit_test
- .only_code
variables:
TEST: 'common_eeschema'
qa_common_pcbnew:
extends:
- .unit_test
- .only_code
variables:
TEST: 'common_pcbnew'
qa_common_gerbview:
extends:
- .unit_test
- .only_code
variables:
TEST: 'qa_common_gerbview'
qa_pcbnew:
extends:
- .unit_test
- .only_code
variables:
TEST: 'pcbnew'
qa_eeschema:
extends:
- .unit_test
- .only_code
variables:
TEST: 'eeschema'
qa_kimath:
extends:
- .unit_test
- .only_code
variables:
TEST: 'kimath'
qa_sexpr:
extends:
- .unit_test
- .only_code
variables:
TEST: 'sexpr'
qa_kicad2step:
extends:
- .unit_test
- .only_code
variables:
TEST: 'kicad2step'

65
.gitlab/coverity.yml Normal file
View File

@ -0,0 +1,65 @@
# This script is responsible for configuring the coverity file from the cache
# (e.g. extracting it or updating it if needed)
.coverity_cache_prep: &coverity_cache_prep |
echo "Downloading MD5 hash of current Coverity Scan version to compare against cache"
curl --output cov-analysis-linux64.md5 https://scan.coverity.com/download/linux64 \
--form project=$COVERITY_SCAN_PROJECT_NAME \
--form token=$COVERITY_SCAN_TOKEN \
--form md5=1
test "$(md5sum cov-analysis-linux64.tgz | awk '{ print $1 }')" = "$(cat cov-analysis-linux64.md5)" || (
echo "Downloading new Coverity Scan version"
curl --output cov-analysis-linux64.tgz https://scan.coverity.com/download/linux64 \
--form project=$COVERITY_SCAN_PROJECT_NAME \
--form token=$COVERITY_SCAN_TOKEN
)
echo "Extracting Coverity Scan"
mkdir coverity/
tar xzf cov-analysis-linux64.tgz --strip-components=1 -C coverity
test -d coverity/bin
# This script is responsible for tar'ing and submitting the results of the build.
# These results will be saved for 1 day if the build fails.
.coverity_submit: &coverity_submit |
echo "Creating tar file of scan results"
tar cfz cov-int.tar.gz cov-int
echo "Submitting scan results"
curl -v https://scan.coverity.com/builds?project=$COVERITY_SCAN_PROJECT_NAME \
--form token=$COVERITY_SCAN_TOKEN \
--form email=$GITLAB_USER_EMAIL \
--form file=@cov-int.tar.gz \
--form version="`git describe --tags`" \
--form description="`git describe --tags` / $CI_COMMIT_TITLE / $CI_COMMIT_REF_NAME:$CI_PIPELINE_ID " 2>&1 \
| tee curl-response.txt
grep -q 'Build successfully submitted' curl-response.txt
Coverity:
tags:
- coverity
stage: build
only:
variables:
- $SCHEDULED_JOB_NAME == "coverity"
cache:
key: coverity
paths:
- cov-analysis-linux64.tgz
before_script:
- export COVERITY_SCAN_PROJECT_NAME="kicad"
script:
- *coverity_cache_prep
- cmake
-DCMAKE_BUILD_TYPE=Debug
-DKICAD_STDLIB_LIGHT_DEBUG=ON
-DKICAD_SCRIPTING=ON
-DKICAD_SCRIPTING_MODULES=ON
-DKICAD_SCRIPTING_PYTHON3=ON
-DKICAD_SCRIPTING_WXPYTHON=ON
-DKICAD_SCRIPTING_WXPYTHON_PHOENIX=ON
-DKICAD_SCRIPTING_ACTION_MENU=ON
-DBUILD_GITHUB_PLUGIN=ON
-DKICAD_USE_OCE=OFF
-DKICAD_USE_OCC=ON
-DKICAD_SPICE=ON
- coverity/bin/cov-build --dir cov-int make -j8
- *coverity_submit

40
.gitlab/templates.yml Normal file
View File

@ -0,0 +1,40 @@
##########################################################################
# This will allow the job to run whenever code events trigger it.
##########################################################################
.only_code:
only:
- master
- branches
- merge_requests
- pushes
except:
- schedules
##########################################################################
# Define a template for all the unit tests, since each one is run in a separate
# job to make the display nicer.
##########################################################################
.unit_test:
stage: test
when: on_success
needs:
- job: build_linux
artifacts: true
# We define this using a before script because GitLab cannot merge variable
# definitions across inheritance (so the variables block from this would disappear)
before_script:
- export BOOST_TEST_LOGGER='JUNIT,all,test_results.${TEST}.xml:HRF,warning'
- export CTEST_OUTPUT_ON_FAILURE=1
script:
- cd build/linux/qa
- ctest -R ${TEST}
# GitLab supports displaying the results in the GUI through JUNIT artifacts
# (https://docs.gitlab.com/ee/ci/junit_test_reports.html)
# so we upload the JUNIT results. Note that there is a bug with how paths
# are processed in the junit report (https://gitlab.com/gitlab-org/gitlab/issues/23835)
# so we can't use a glob and have to list out each hierarchy separately.
artifacts:
reports:
junit:
- build/linux/qa/*/*.xml
- build/linux/qa/*/*/*.xml