Skip to content
Snippets Groups Projects
.gitlab-ci.yml 3.14 KiB
Newer Older
# 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: 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:
Adriaan de Beer's avatar
Adriaan de Beer committed
  - python3 -m pip install -r docker-requirements.txt
  
Matteo04052017's avatar
.  
Matteo04052017 committed
stages:
  - test
  - linting
Matteo04052017's avatar
.  
Matteo04052017 committed
  - 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 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.
Matteo04052017's avatar
.  
Matteo04052017 committed
test:
Matteo04052017's avatar
.  
Matteo04052017 committed
  stage: test
  script:
Adriaan de Beer's avatar
Adriaan de Beer committed
  #  - pipenv run python setup.py test
   - python3 setup.py test
   - mv coverage.xml ./build/reports/code-coverage.xml
Matteo04052017's avatar
.  
Matteo04052017 committed
  artifacts:
    paths:
    - ./build
Bruno S. Morgado's avatar
Bruno S. Morgado committed
list_dependencies:
  stage: test
Adriaan de Beer's avatar
Adriaan de Beer committed
    # - pipenv graph >> pipenv_deps.txt
    - pipdeptree --json >> pip_deps.json
    - pipdeptree >> pip_deps.txt
    - dpkg -l >> system_deps.txt
    - awk 'FNR>5 {print $2 ", " $3}' system_deps.txt >> system_deps.csv
Adriaan de Beer's avatar
Adriaan de Beer committed
    - cp pip_deps.txt .public/
    - cp pip_deps.json .public/
    - cp system_deps.txt .public/
    - cp system_deps.csv .public/
    - mv .public public
linting:
  image: nexus.engageska-portugal.pt/ska-docker/ska-python-buildenv:latest
Matteo04052017's avatar
.  
Matteo04052017 committed
  tags:
    - docker-executor
  stage: linting
  script:
    - make lint
  when: always
Matteo04052017's avatar
.  
Matteo04052017 committed
  artifacts:
    paths:
      - ./build
Matteo04052017's avatar
.  
Matteo04052017 committed
pages:
  stage: deploy
  tags:
   - docker-executor
Matteo04052017's avatar
.  
Matteo04052017 committed
  dependencies:
    - test
  script:
   - ls -la
   - mkdir .public
   - cp -r htmlcov/* .public
   - rm -rf htmlcov
Matteo04052017's avatar
.  
Matteo04052017 committed
   - 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