.gitlab-ci.yml 3.11 KB
Newer Older
dboe's avatar
dboe committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
image: python:latest

# Change pip's cache directory to be inside the project directory since we can
# only cache local items.
variables:
  PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"

# Pip's cache doesn't store the python packages
# https://pip.pypa.io/en/stable/reference/pip_install/#caching
#
# If you want to also cache the installed packages, you have to install
# them in a virtualenv and cache it as well.
cache:
  paths:
    - .cache/pip
    - venv/
dboe's avatar
dboe committed
17
    - .cache/apt
dboe's avatar
dboe committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31

stages:
  - build
  - test
  - deploy

before_script:
  - pip install virtualenv
  - virtualenv venv
  - source venv/bin/activate

dist:
  stage: build
  script:
32
    - mkdir -p .cache/apt
dboe's avatar
dboe committed
33
    - apt-get update -yqq
dboe's avatar
dboe committed
34
    - apt-get install -y gfortran libopenblas-dev liblapack-dev
dboe's avatar
dboe committed
35
    - apt-get -o dir::cache::archives=".cache/apt" install -y -qq gfortran liblapack-dev libgmp-dev
dboe's avatar
dboe committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
    - python setup.py bdist_wheel
    # an alternative approach is to install and run:
    - pip install dist/*
    # run the command here
  artifacts:
    paths:
      - dist/*.whl
    expire_in: 1h
  only:
    - tags

pages:
  stage: build
  script:
    - pip install sphinx sphinx_rtd_theme recommonmark
    - cd docs
    - make html
    - cd ..
    - mkdir -p public
    - rm -rf public/*
    - mv docs/_build/html/* public/  # add it to pages. Pages is exposing public/index.html
  only:
    - master
  cache:
    paths:
      - public
  artifacts:
    paths:
      - public
      - docs

lint:
  stage: test
  before_script:
    - pip install -q flake8
  script:
    - flake8

test:
  stage: test
  script:
    - pip --version
    - pip install tox  # you can also use tox
79
    - tox
dboe's avatar
dboe committed
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
  coverage: '/^TOTAL.+?(\d+\%)$/'
  artifacts:
    # paths:
    # pa- report/unit
    reports:
      junit:
        - report/junit.xml
    
gitlab-release:
  image: inetprocess/gitlab-release
  stage: deploy
  before_script:
    - echo "Starting release"
  script:
    - gitlab-release --message 'Automatic release' dist/*  # Note:
  only:
    - tags

pypi:
  image: docker.km3net.de/base/python:3
  stage: deploy
  cache: {}
  before_script:
    - echo "Starting upload to pypi"
  script:
    # Check if current_version is already uploaded
    - VERSION=$((python -c "import configparser; config = configparser.ConfigParser(); config.read('setup.cfg'); print(config['bumpversion']['current_version'])") 2>&1)
    - MODULE_NAME=$((python -c "import configparser; config = configparser.ConfigParser(); config.read('setup.cfg'); print(config['metadata']['name'])") 2>&1)
    - PACKAGE_JSON_URL="https://pypi.org/pypi/$MODULE_NAME/json" 
    - apt-get install -qq -y jq
    - PYPI_VERSIONS=$(curl -s "$PACKAGE_JSON_URL" | jq  -r '.releases | keys | .[]' | sort -V)
    - if [[ $PYPI_VERSIONS =~ $VERSION ]]; then echo "Version $VERSION is already uploaded!"; exit 1; fi
    # Version not already uploaded so do it now.
    - echo "Uploading version $VERSION"
    - pip install -U twine
    - python setup.py sdist
    - twine upload dist/*
  rules:
    # for debuggin: git commit -am "deb" && git push && bumpversion patch && git tag -l --sort=-v:refname | head -n 1 | git push origin
    - if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/