Skip to content
Snippets Groups Projects
.gitlab-ci.yml 8.01 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 -------------------------------------------

.list-env: &list-env
  - PREFIX="$(dirname $(which python))/.."
  - if [ -d "${PREFIX}/conda-meta" ]; then
      conda list --prefix "${PREFIX}" --show-channel-urls;
    else
      python -m pip list installed;
    fi

# Check author list is up to date
authors:
  stage: initial
Colm Talbot's avatar
Colm Talbot committed
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python310
  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-python311
  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
    - cp env-template.yml env.yml
    - echo "  - python=3.11" >> env.yml
    - mamba env create -f env.yml -n test --dry-run
.test-python: &test-python
Colm Talbot's avatar
Colm Talbot committed
  stage: initial
  image: python
  script:
    - python -m pip install .
    - 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.10:
  <<: *test-python
  image: python:3.10
Colm Talbot's avatar
Colm Talbot committed
basic-3.11:
  <<: *test-python
  image: python:3.11

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

.test-samplers-import: &test-samplers-import
  stage: initial
  script:
    - python -m pip install .
    - pytest test/test_samplers_import.py -v

import-samplers-3.10:
  <<: *test-samplers-import
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python310

Colm Talbot's avatar
Colm Talbot committed
import-samplers-3.11:
  <<: *test-samplers-import
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python311

import-samplers-3.12:
  <<: *test-samplers-import
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python312

.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 .
    # Run precommits (flake8, spellcheck, isort, no merge conflicts, etc)
    - pre-commit run --all-files --verbose --show-diff-on-failure

  <<: *precommits
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python311
  variables:
    CACHE_DIR: ".pip311"
    PYVERSION: "python311"
install:
  stage: initial
  parallel:
    matrix:
      - EXTRA: [gw, mcmc, all]
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python311
  script:
    - pip install .[$EXTRA]

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

.unit-tests: &unit-test
Gregory Ashton's avatar
Gregory Ashton committed
  stage: test
    - python -m pip install .
    - pytest --cov=bilby --durations 10
Colm Talbot's avatar
Colm Talbot committed
python-3.10:
  <<: *unit-test
  needs: ["basic-3.10"]
Colm Talbot's avatar
Colm Talbot committed
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python310

python-3.11:
  <<: *unit-test
  needs: ["basic-3.11", "precommits-py3.11"]
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python311
  after_script:
    - coverage html
    - coverage xml
Colm Talbot's avatar
Colm Talbot committed
  coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
Colm Talbot's avatar
Colm Talbot committed
  artifacts:
    reports:
Colm Talbot's avatar
Colm Talbot committed
      coverage_report:
        coverage_format: cobertura
Colm Talbot's avatar
Colm Talbot committed
        path: coverage.xml
Colm Talbot's avatar
Colm Talbot committed
    paths:
      - htmlcov/
Colm Talbot's avatar
Colm Talbot committed
    expire_in: 30 days
Colm Talbot's avatar
Colm Talbot committed
  <<: *unit-test
  needs: ["basic-3.12"]
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python312
.test-sampler: &test-sampler
  stage: test
  script:
    - python -m pip install .[all]
    - pytest test/integration/sampler_run_test.py --durations 10 -v
python-3.10-samplers:
  <<: *test-sampler
  needs: ["basic-3.10"]
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python310
Colm Talbot's avatar
Colm Talbot committed
python-3.11-samplers:
  <<: *test-sampler
  needs: ["basic-3.11", "precommits-py3.11"]
Colm Talbot's avatar
Colm Talbot committed
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python311

python-3.12-samplers:
  <<: *test-sampler
  needs: ["basic-3.12"]
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python312

integration-tests-python-3.11:
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python311
  needs: ["basic-3.11", "precommits-py3.11"]
    - python -m pip install .
    # 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 .
Colm Talbot's avatar
Colm Talbot committed
    - pytest test/gw/plot_test.py

plotting-python-3.10:
  <<: *plotting
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python310
  needs: ["basic-3.10"]
Colm Talbot's avatar
Colm Talbot committed
plotting-python-3.11:
  <<: *plotting
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python311
  needs: ["basic-3.11", "precommits-py3.11"]

plotting-python-3.12:
  <<: *plotting
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python312
  needs: ["basic-3.12"]
# ------------------- Docs stage -------------------------------------------

docs:
  stage: docs
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python311
Colm Talbot's avatar
Colm Talbot committed
  before_script:
    - python -m ipykernel install
    # Make the documentation
    - python -m pip install .
    - python -m pip install myst_parser # only for testing purposes - remove once test image is generating correctly
Colm Talbot's avatar
Colm Talbot committed
    - cd examples/tutorials
    - jupyter nbconvert --to notebook --execute *.ipynb --output-dir ../../docs
    - cd ../../docs
    - make clean
    - make html

  artifacts:
    paths:
      - docs/_build/html/

# ------------------- Deploy stage -------------------------------------------
Gregory Ashton's avatar
Gregory Ashton committed
  stage: deploy
  needs: ["docs", "python-3.11"]
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.23
  needs: ["containers"]
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
      changes:
        compare_to: 'refs/heads/main'
        paths:
          - containers/*
      when: manual
    - if: $CI_PIPELINE_SOURCE == "schedule"
  script:
    - cd containers
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
Colm Talbot's avatar
Colm Talbot committed
    - cp v3-dockerfile-test-suite-$PYVERSION Dockerfile
    - docker build --tag v3-bilby-$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-python310-container:
  <<: *build-container
  variables:
    PYVERSION: "python310"
Colm Talbot's avatar
Colm Talbot committed
build-python311-container:
  <<: *build-container
  variables:
    PYVERSION: "python311"

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

pypi-release:
  stage: deploy
Colm Talbot's avatar
Colm Talbot committed
  image: containers.ligo.org/lscsoft/bilby/v2-bilby-python310
  variables:
    TWINE_USERNAME: $PYPI_USERNAME
    TWINE_PASSWORD: $PYPI_PASSWORD
  before_script:
    - python -m build --sdist --wheel --outdir dist/ .
  script:
    - twine upload dist/*
  only: