Skip to content
Snippets Groups Projects
.gitlab-ci.yml 9.32 KiB
Newer Older
Gregory Ashton's avatar
Gregory Ashton committed
# This script is an edited version of the example found at
# https://git.ligo.org/lscsoft/example-ci-project/blob/python/.gitlab-ci.yml
# Each 0th-indentation level is a job that will be run within GitLab CI
Gregory Ashton's avatar
Gregory Ashton committed
# The only exception are a short list of reserved keywords
#
# https://docs.gitlab.com/ee/ci/yaml/#gitlab-ci-yml

# stages is a reserved keyword that defines job dependencies and
# parallelization. each stage runs in parallel but must complete
# before the next stage begins

stages:
Colm Talbot's avatar
Colm Talbot committed
  - initial
Gregory Ashton's avatar
Gregory Ashton committed
  - test
Colm Talbot's avatar
Colm Talbot committed
  - docs
Gregory Ashton's avatar
Gregory Ashton committed
  - deploy

# ------------------- Initial stage -------------------------------------------

# Check author list is up to date
authors:
  stage: initial
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python37
  script:
    - python test/check_author_list.py

# Test containers scripts are up to date
containers:
  stage: initial
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python37
  script:
    - cd containers
    - python write_dockerfiles.py #HACK
    # Fail if differences exist. If this fails, you may need to run
    # write_dockerfiles.py and commit the changes.
    - git diff --exit-code

.test-python: &test-python
Colm Talbot's avatar
Colm Talbot committed
  stage: initial
  image: python
  before_script:
    # this is required because pytables doesn't use a wheel on py37
    - apt-get -yqq update
    - apt-get -yqq install libhdf5-dev
  script:
    - python -m pip install .
    - python -m pip list installed
    - python -c "import bilby"
Colm Talbot's avatar
Colm Talbot committed
    - python -c "import bilby.bilby_mcmc"
    - python -c "import bilby.core"
    - python -c "import bilby.core.prior"
    - python -c "import bilby.core.sampler"
Colm Talbot's avatar
Colm Talbot committed
    - python -c "import bilby.core.utils"
    - python -c "import bilby.gw"
    - python -c "import bilby.gw.detector"
Colm Talbot's avatar
Colm Talbot committed
    - python -c "import bilby.gw.eos"
    - python -c "import bilby.gw.likelihood"
    - python -c "import bilby.gw.sampler"
    - python -c "import bilby.hyper"
    - python -c "import cli_bilby"
Colm Talbot's avatar
Colm Talbot committed
    - python test/import_test.py
    - for script in $(pip show -f bilby | grep "bin\/" | xargs -I {} basename {}); do
          ${script} --help;
      done
# Test basic setup on python 3.7
basic-3.7:
  <<: *test-python
  image: python:3.7

# Test basic setup on python 3.8
basic-3.8:
  <<: *test-python
  image: python:3.8

# Test basic setup on python 3.9
basic-3.9:
  <<: *test-python
  image: python:3.9


precommits-py3.7:
  stage: initial
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python37
  script:
    - source activate python37
    - mkdir -p .pip37
    - pip install --upgrade pip
    - pip --cache-dir=.pip37 install --upgrade bilby
    - pip --cache-dir=.pip37 install .
    - pip --cache-dir=.pip37 install pre-commit
    # Run precommits (flake8, spellcheck, isort, no merge conflicts, etc)
    - pre-commit run --all-files --verbose --show-diff-on-failure

precommits-py3.8:
  stage: initial
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python38
  script:
    - source activate python38
    - mkdir -p .pip38
    - pip install --upgrade pip
    - pip --cache-dir=.pip38 install --upgrade bilby
    - pip --cache-dir=.pip38 install .
    - pip --cache-dir=.pip38 install pre-commit
    # Run precommits (flake8, spellcheck, isort, no merge conflicts, etc)
    - pre-commit run --all-files --verbose --show-diff-on-failure

precommits-py3.9:
  stage: initial
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python39
  script:
    - source activate python39
    - mkdir -p .pip38
    - pip install --upgrade pip
    - pip --cache-dir=.pip39 install --upgrade bilby
    - pip --cache-dir=.pip39 install .
    - pip --cache-dir=.pip39 install pre-commit
    # Run precommits (flake8, spellcheck, isort, no merge conflicts, etc)
    - pre-commit run --all-files --verbose --show-diff-on-failure

# ------------------- Test stage -------------------------------------------

# test example on python 3.7 and build coverage
python-3.7:
Gregory Ashton's avatar
Gregory Ashton committed
  stage: test
  needs: ["basic-3.7", "precommits-py3.7"]
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python37
    - python -m pip install .
    - python -m pip list installed
Gregory Ashton's avatar
Gregory Ashton committed

    # Run pyflakes
    - flake8 .

Gregory Ashton's avatar
Gregory Ashton committed
    # Run tests and collect coverage data
    - pytest --cov=bilby --durations 10
    - coverage html
    - coverage-badge -o coverage_badge.svg -f
Colm Talbot's avatar
Colm Talbot committed
  artifacts:
    paths:
      - coverage_badge.svg
      - htmlcov/

Gregory Ashton's avatar
Gregory Ashton committed
# test example on python 3.8
python-3.8:
  stage: test
  needs: ["basic-3.8", "precommits-py3.8"]
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python38
Gregory Ashton's avatar
Gregory Ashton committed
  script:
    - python -m pip install .
    - python -m pip list installed
    - pytest
# test example on python 3.9
python-3.9:
  stage: test
  needs: ["basic-3.9", "precommits-py3.9"]
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python39
  script:
    - python -m pip install .
    - python -m pip list installed
Gregory Ashton's avatar
Gregory Ashton committed
    - pytest

# test samplers on python 3.7
python-3.7-samplers:
  stage: test
  needs: ["basic-3.7", "precommits-py3.7"]
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python37
  script:
    - python -m pip install .
    - python -m pip list installed
    - pytest test/integration/sampler_run_test.py --durations 10
# test samplers on python 3.8
python-3.8-samplers:
  stage: test
  needs: ["basic-3.8", "precommits-py3.8"]
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python38
  script:
    - python -m pip install .
    - python -m pip list installed
    - pytest test/integration/sampler_run_test.py --durations 10
# test samplers on python 3.9
python-3.9-samplers:
  stage: test
  needs: ["basic-3.9", "precommits-py3.9"]
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python39
  script:
    - python -m pip install .
    - python -m pip list installed

    - pytest test/integration/sampler_run_test.py --durations 10
integration-tests-python-3.7:
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python37
  needs: ["basic-3.7", "precommits-py3.7"]
    - python -m pip install .
    - python -m pip list installed
    # Run tests which are only done on schedule
    - pytest test/integration/example_test.py
plotting-python-3.7:
Colm Talbot's avatar
Colm Talbot committed
  stage: test
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python37
  needs: ["basic-3.7", "precommits-py3.7"]
Colm Talbot's avatar
Colm Talbot committed
  only:
    - schedules
  script:
    - python -m pip install .
Colm Talbot's avatar
Colm Talbot committed
    - python -m pip install "ligo.skymap>=0.5.3"
    - python -m pip list installed
Colm Talbot's avatar
Colm Talbot committed
    - pytest test/gw/plot_test.py


plotting-python-3.9:
  stage: test
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python37
  needs: ["basic-3.9", "precommits-py3.9"]
  only:
    - schedules
  script:
    - python -m pip install .
    - python -m pip install "ligo.skymap>=0.5.3"
    - python -m pip list installed
Moritz Huebner's avatar
Moritz Huebner committed
    - pytest test/gw/plot_test.py

# ------------------- Docs stage -------------------------------------------

docs:
  stage: docs
  needs: ["python-3.7"]
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python37
    # Make the documentation
    - apt-get -yqq install pandoc
    - python -m pip install .
    - cd docs
    - pip install ipykernel ipython jupyter
    - cp ../examples/tutorials/*.ipynb ./
    - rm basic_ptmcmc_tutorial.ipynb
    - rm compare_samplers.ipynb
    - rm visualising_the_results.ipynb
    - jupyter nbconvert --to notebook --execute *.ipynb --inplace
    - make clean
    - make html

  artifacts:
    paths:
      - docs/_build/html/

# ------------------- Deploy stage -------------------------------------------
deploy-docs:
Gregory Ashton's avatar
Gregory Ashton committed
  stage: deploy
  needs: ["docs", "python-3.7"]
Gregory Ashton's avatar
Gregory Ashton committed
  script:
    - mkdir public/
Gregory Ashton's avatar
Gregory Ashton committed
    - mv htmlcov/ public/
    - mv coverage_badge.svg public/
    - mv docs/_build/html/* public/
Gregory Ashton's avatar
Gregory Ashton committed
  artifacts:
    paths:
      - public
    expire_in: 30 days
# Build the containers
build-python37-container:
  stage: deploy
  image: docker:19.03.12
  needs: ["containers"]
  only:
    - schedules
  script:
    - cd containers
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - docker build --tag v3-bilby-python37 - < v3-dockerfile-test-suite-python37
    - docker image tag v3-bilby-python37 containers.ligo.org/lscsoft/bilby/v2-bilby-python37:latest
    - docker image push containers.ligo.org/lscsoft/bilby/v2-bilby-python37:latest

build-python38-container:
  stage: deploy
  image: docker:19.03.12
  needs: ["containers"]
  only:
    - schedules
  script:
    - cd containers
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - docker build --tag v3-bilby-python38 - < v3-dockerfile-test-suite-python38
    - docker image tag v3-bilby-python38 containers.ligo.org/lscsoft/bilby/v2-bilby-python38:latest
    - docker image push containers.ligo.org/lscsoft/bilby/v2-bilby-python38:latest

build-python39-container:
  stage: deploy
  image: docker:19.03.12
  needs: ["containers"]
  only:
    - schedules
  script:
    - cd containers
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - docker build --tag v3-bilby-python39 - < v3-dockerfile-test-suite-python39
    - docker image tag v3-bilby-python39 containers.ligo.org/lscsoft/bilby/v2-bilby-python39:latest
    - docker image push containers.ligo.org/lscsoft/bilby/v2-bilby-python39:latest

pypi-release:
  stage: deploy
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python37
  variables:
    TWINE_USERNAME: $PYPI_USERNAME
    TWINE_PASSWORD: $PYPI_PASSWORD
  before_script:
    - pip install twine
    - python setup.py sdist
  script:
    - twine upload dist/*
  only: