diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b5ff4c2329443c05de49f730d232d27858e996f6..7df5905f03a108cfdcb2ee8f84f77954e31f755f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,14 +1,13 @@ # GitLab CI in conjunction with GitLab Runner can use Docker Engine to test and build any application. # Docker, when used with GitLab CI, runs each job in a separate and isolated container using the predefined image that is set up in .gitlab-ci.yml. # In this case we use the latest python docker image to build and test this project. -image: python:3.5-slim +image: nexus.engageska-portugal.pt/ska-docker/ska-python-buildenv:latest # cache is used to specify a list of files and directories which should be cached between jobs. You can only use paths that are within the project workspace. # If cache is defined outside the scope of jobs, it means it is set globally and all jobs will use that definition cache: paths: - -# before_script is used to define the command that should be run before all jobs, including deploy jobs, but after the restoration of artifacts. +# before_script is used to define the command that should be run before all jobs, including deploy jobs, but after the restoration of artifacts. # This can be an array or a multi-line string. before_script: - pip install pipenv @@ -16,21 +15,25 @@ before_script: stages: - test + - linting - deploy # The YAML file defines a set of jobs with constraints stating when they should be run. -# You can specify an unlimited number of jobs which are defined as top-level elements with an arbitrary name and always have to contain at least the script clause. -# In this case we have only the test job which produce an artifacts (it must be placed into a directory called "public") -# It is also specified that only the master branch will be subject of this job. +# You can specify an unlimited number of jobs which are defined as top-level elements with an arbitrary name and always +# have to contain at least the script clause. +# In this case we have only the test job which produces a coverage report and the unittest output (see setup.cfg), and +# the coverage xml report is moved to the reports directory while the html output is persisted for use by the pages +# job. TODO: possibly a candidate for refactor / renaming later on. test: stage: test # tags: # - docker-executor script: - pipenv run python setup.py test - - cp coverage.xml htmlcov/ + - mv coverage.xml ./build/reports/code-coverage.xml artifacts: paths: + - ./build - htmlcov list_dependencies: @@ -48,46 +51,47 @@ list_dependencies: paths: - public -code_quality: +linting: + image: nexus.engageska-portugal.pt/ska-docker/ska-python-buildenv:latest tags: - docker-executor - image: docker:stable - variables: - DOCKER_DRIVER: overlay2 - allow_failure: true - services: - - docker:stable-dind - before_script: - - ls -la + stage: linting script: - - export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/') - - docker run - --env SOURCE_CODE="$PWD" - --volume "$PWD":/code - --volume /var/run/docker.sock:/var/run/docker.sock - "registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code - - more gl-code-quality-report.json + - make lint + when: always artifacts: - paths: [gl-code-quality-report.json] - + paths: + - ./build -code_analysis: - script: - - pipenv run pylint ska_python_skeleton - - pipenv run pylint tests - pages: stage: deploy -# tags: -# - docker-executor + tags: + - docker-executor dependencies: - test script: - ls -la - mkdir .public - cp -r htmlcov/* .public + - rm -rf htmlcov - mv .public public artifacts: paths: - public - expire_in: 30 days \ No newline at end of file + expire_in: 30 days + +create ci metrics: + stage: .post + image: nexus.engageska-portugal.pt/ska-docker/ska-python-buildenv:latest + when: always + tags: + - docker-executor + script: + # Gitlab CI badges creation: START + - apt-get -y update + - apt-get install -y curl --no-install-recommends + - curl -s https://gitlab.com/ska-telescope/ci-metrics-utilities/raw/master/scripts/ci-badges-func.sh | sh + # Gitlab CI badges creation: END + artifacts: + paths: + - ./build \ No newline at end of file diff --git a/.pylintrc b/.pylintrc index 56f86d64d542a8aaa87944d213ac6ea8d3db208c..eae6a06eec1ab98f68a4c854b6b56a5cb1c7bc63 100644 --- a/.pylintrc +++ b/.pylintrc @@ -19,7 +19,7 @@ ignore-patterns= # Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the # number of processors available to use. -jobs=1 +jobs=0 # Control the amount of potential inferred values when inferring a single # object. This can help the performance when dealing with large functions or diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..462303c2ea953f4823124ee905744a602d4b6fb1 --- /dev/null +++ b/Makefile @@ -0,0 +1,27 @@ +# Use bash shell with pipefail option enabled so that the return status of a +# piped command is the value of the last (rightmost) commnand to exit with a +# non-zero status. This lets us pipe output into tee but still exit on test +# failures. +SHELL = /bin/bash +.SHELLFLAGS = -o pipefail -c + +all: test lint + +# The following steps copy across useful output to this volume which can +# then be extracted to form the CI summary for the test procedure. +test: + + python setup.py test | tee ./build/setup_py_test.stdout; \ + mv coverage.xml ./build/reports/code-coverage.xml; + +# The following steps copy across useful output to this volume which can +# then be extracted to form the CI summary for the test procedure. +lint: + + # FIXME pylint needs to run twice since there is no way go gather the text and junit xml output at the same time + pip3 install pylint2junit; \ + pylint --output-format=parseable ska_python_skeleton | tee ./build/code_analysis.stdout; \ + pylint --output-format=pylint2junit.JunitReporter ska_python_skeleton > ./build/reports/linting.xml; + + +.PHONY: all test lint diff --git a/setup.cfg b/setup.cfg index 140dc017a874f77e020473649af69112daf86750..3f0083ccde8be19b671d6e977b83151763b5c1ea 100644 --- a/setup.cfg +++ b/setup.cfg @@ -11,7 +11,7 @@ source = ska_python_skeleton [tool:pytest] testpaths = tests -addopts = --cov --json-report --json-report-file=htmlcov/report.json --cov-report term --cov-report html --cov-report xml --pylint --pylint-error-types=EF +addopts = --cov --json-report --json-report-file=htmlcov/report.json --cov-report term --cov-report html --cov-report xml --pylint --pylint-error-types=EF --junitxml=./build/reports/unit-tests.xml # Define `python setup.py build_sphinx` [build_sphinx]