stages:
    - test
    - deploy_test
    - test_install
    - deploy_prod

test_docker:
    stage: test
    image: ubuntu:rolling
    tags: 
            - docker.meteo.physik.lmu.de
    before_script:
        - apt update
        - export DEBIAN_FRONTEND=noninteractive
        - apt install -yq git python3 python3-pip python3-venv
    script: ./run_tests.sh
    rules:
        - if: '$CI_COMMIT_TAG == null'

deploy-to-testpypi:
  stage: deploy_test
  image: python:3.8
  tags:
    - docker.meteo.physik.lmu.de
#  only:
#    - tags
  script:
    - pip install twine
    - python setup.py sdist bdist_wheel
    - echo "Dummy:'$ENVTEST'"
    - echo "Dummy:$ENVTEST"
    - echo "My password is:'$PYPI_TEST_PASSWORD'"
    - 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: python:3.8
  tags:
    - docker.meteo.physik.lmu.de
#  only:
#    - tags
  needs: ["deploy-to-testpypi"]
  script:
    - pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ enstools-encoding
  artifacts:
    when: on_failure
    paths:
      - "*.log"

deploy-to-pypi:
  stage: deploy_prod
  image: python:3.8
  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/*