Commit aa5d9490 authored by Adriaan de Beer's avatar Adriaan de Beer
Browse files

ST-281 CI metrics gathered.

parent e78ddbd1
Loading
Loading
Loading
Loading
+37 −33
Original line number Diff line number Diff line
# 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.
# This can be an array or a multi-line string.
before_script:
@@ -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]


code_analysis:
  script:
    - pipenv run pylint ska_python_skeleton
    - pipenv run pylint tests
    paths:
      - ./build

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

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
+1 −1
Original line number Diff line number Diff line
@@ -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

Makefile

0 → 100644
+27 −0
Original line number Diff line number Diff line
# 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
+1 −1
Original line number Diff line number Diff line
@@ -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]