Skip to content
Snippets Groups Projects
.gitlab-ci.yml 7.6 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-python39
  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-python39
  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
basic-3.8:
  <<: *test-python
  image: python:3.8

basic-3.9:
  <<: *test-python
  image: python:3.9

basic-3.10:
  <<: *test-python
  image: python:3.10
.precommits: &precommits
  stage: initial
  script:
    - source activate $PYVERSION
    - mkdir -p $CACHE_DIR
    - pip install --upgrade pip
    - pip --cache-dir=$CACHE_DIR install --upgrade bilby
    - pip --cache-dir=$CACHE_DIR install .
    - pip --cache-dir=$CACHE_DIR 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:
  <<: *precommits
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python38
  variables:
    CACHE_DIR: ".pip38"
    PYVERSION: "python38"

precommits-py3.9:
  <<: *precommits
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python39
  variables:
    CACHE_DIR: ".pip39"
    PYVERSION: "python39"

# FIXME: when image builds for 3.10 change this back.
#precommits-py3.10:
#  <<: *precommits
#  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python310
#  variables:
#    CACHE_DIR: ".pip310"
#    PYVERSION: "python310"

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

.unit-tests: &unit-test
Gregory Ashton's avatar
Gregory Ashton committed
  stage: test
    - python -m pip install .
    - python -m pip list installed
    - pytest --cov=bilby --durations 10

python-3.8:
  <<: *unit-test
  needs: ["basic-3.8", "precommits-py3.8"]
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python38
Colm Talbot's avatar
Colm Talbot committed

python-3.9:
  <<: *unit-test
  needs: ["basic-3.9", "precommits-py3.9"]
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python39
  after_script:
    - coverage html
    - coverage xml
Colm Talbot's avatar
Colm Talbot committed
  artifacts:
    reports:
      cobertura: coverage.xml
Colm Talbot's avatar
Colm Talbot committed
    paths:
      - htmlcov/
Colm Talbot's avatar
Colm Talbot committed
    expire_in: 30 days
# add back when 3.10 image is available
#python-3.10:
#  <<: *unit-test
#  needs: ["basic-3.10", "precommits-py3.10"]
#  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python310
.test-sampler: &test-sampler
  stage: test
  script:
    - python -m pip install .
    - python -m pip list installed
    - pytest test/integration/sampler_run_test.py --durations 10
  <<: *test-sampler
  needs: ["basic-3.8", "precommits-py3.8"]
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python38
python-3.9-samplers:
  <<: *test-sampler
  needs: ["basic-3.9", "precommits-py3.9"]
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python39

# add back when 3.10 image is available
#python-3.10-samplers:
#  <<: *test-sampler
#  needs: ["basic-3.10", "precommits-py3.10"]
#  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python310
integration-tests-python-3.9:
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python39
  needs: ["basic-3.9", "precommits-py3.9"]
    - python -m pip install .
    - python -m pip list installed
    # Run tests which are only done on schedule
    - pytest test/integration/example_test.py
.plotting: &plotting
Colm Talbot's avatar
Colm Talbot committed
  stage: test
  only:
    - schedules
  script:
    - python -m pip install .
    - python -m pip list installed
Colm Talbot's avatar
Colm Talbot committed
    - pytest test/gw/plot_test.py


plotting-python-3.8:
  <<: *plotting
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python38
  needs: ["basic-3.8", "precommits-py3.8"]

Colm Talbot's avatar
Colm Talbot committed
plotting-python-3.9:
  <<: *plotting
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python39
Colm Talbot's avatar
Colm Talbot committed
  needs: ["basic-3.9", "precommits-py3.9"]
# add back when 3.10 image is available
#plotting-python-3.10:
#  <<: *plotting
#  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python310
#  needs: ["basic-3.10", "precommits-py3.10"]

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

docs:
  stage: docs
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python39
    # 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
Colm Talbot's avatar
Colm Talbot committed
  needs: ["docs", "python-3.9"]
Gregory Ashton's avatar
Gregory Ashton committed
  script:
    - mkdir public/
Gregory Ashton's avatar
Gregory Ashton committed
    - mv htmlcov/ public/
    - mv docs/_build/html/* public/
Gregory Ashton's avatar
Gregory Ashton committed
  artifacts:
    paths:
      - public
    expire_in: 30 days
.build-container: &build-container
  stage: deploy
  image: docker:20.10.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-$PYVERSION - < v3-dockerfile-test-suite-$PYVERSION
    - docker image tag v3-bilby-$PYVERSION containers.ligo.org/lscsoft/bilby/v2-bilby-$PYVERSION:latest
    - docker image push containers.ligo.org/lscsoft/bilby/v2-bilby-$PYVERSION:latest

build-python38-container:
  <<: *build-container
  variables:
    PYVERSION: "python38"

build-python39-container:
  <<: *build-container
  variables:
    PYVERSION: "python39"

# add back when 3.10 image is available
#build-python310-container:
#  <<: *build-container
#  variables:
#    PYVERSION: "python310"

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