stages:
    - test
    - examples
    - deploy_test
    - test_install
    - deploy_prod
    - prod_install

test_docker:
    stage: test
    image: ubuntu:rolling
    tags: 
            - docker.meteo.physik.lmu.de
    # Since enstools is a dependency, we still need to install all these libraries.
    before_script:
            - apt update
            - export DEBIAN_FRONTEND=noninteractive
            - apt-get install -y libproj-dev proj-data proj-bin
            - apt-get install -y libgeos-dev
            - apt-get install -y libeccodes-dev
            - apt install -yq git python3 python3-pip python3-venv
    script: ./run_tests.sh

deploy-to-testpypi:
  stage: deploy_test
  image: python:3.10
  tags:
    - docker.meteo.physik.lmu.de
  only:
    - tags
  script:
    - pip install twine
    - python setup.py sdist bdist_wheel
    - twine upload -u "__token__" -p "$PYPI_TEST_PASSWORD" --repository-url https://test.pypi.org/legacy/ --skip-existing dist/*

install-from-testpypi:
  stage: test_install
  image: ubuntu:rolling
  tags:
    - docker.meteo.physik.lmu.de
  only:
    - tags
  needs: ["deploy-to-testpypi"]
  before_script:
    - apt update
    - export DEBIAN_FRONTEND=noninteractive
    - apt-get install -y libproj-dev proj-data proj-bin
    - apt-get install -y libgeos-dev
    - apt-get install -y libeccodes-dev
    - apt install -yq git vim python3 python3-pip python3-venv
  script:
    - pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ enstools-compression --break-system-packages
    - python -c "from enstools.compression import api"


deploy-to-pypi:
  stage: deploy_prod
  image: python:3.10
  only:
    - tags
  tags:
    - docker.meteo.physik.lmu.de
  needs: ["install-from-testpypi"]
  script:
    - pip install twine
    - python setup.py sdist bdist_wheel
    - twine upload -u "__token__" -p "$PYPI_PASSWORD" --skip-existing dist/*

install-from-pypi:
  stage: prod_install
  image: ubuntu:rolling
  tags:
    - docker.meteo.physik.lmu.de
  only:
    - tags
  needs: ["deploy-to-pypi"]
  before_script:
    - apt update
    - export DEBIAN_FRONTEND=noninteractive
    - apt-get install -y libproj-dev proj-data proj-bin
    - apt-get install -y libgeos-dev
    - apt-get install -y libeccodes-dev
    - apt install -yq git vim python3 python3-pip python3-venv
  script:
    - pip install enstools-compression --break-system-packages
    - python -c "from enstools.compression import api"