image: python:3.7
stages:
  - test
  - test-deploy
  - deploy
  - release

.test-job:
  stage: test

  except:
    - schedules

  cache:
    paths:
      - .cache/pip

  artifacts:
    when: always
    reports:
      junit:
        - test-report.xml

  variables:
    PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"

  before_script:
    - pip install tox

client-tests:
  extends: .test-job
  script: tox -- --junitxml=test-report.xml

client-tests-fork:
  extends: .test-job
  script:
    - pip install -U git+https://gitlab.com/teklia/apistar.git
    - tox -- --junitxml=test-report.xml

client-lint:
  image: python:3

  except:
    - schedules

  before_script:
    - pip install pre-commit

  script:
    - pre-commit run -a

client-deploy-pypi:
  stage: deploy
  only:
    - tags
  environment:
    name: pypi
    url: https://pypi.org/project/arkindex-client

  before_script:
    - pip install twine setuptools wheel
    - echo "[distutils]" > ~/.pypirc
    - echo "index-servers =" >> ~/.pypirc
    - echo "  pypi" >> ~/.pypirc
    - echo "[pypi]" >> ~/.pypirc
    - echo "repository=https://upload.pypi.org/legacy/" >> ~/.pypirc
    - echo "username=$PYPI_DEPLOY_USERNAME" >> ~/.pypirc
    - echo "password=$PYPI_DEPLOY_PASSWORD" >> ~/.pypirc
  script:
    - python setup.py sdist bdist_wheel
    - twine upload dist/* -r pypi

pages:
  stage: deploy
  only:
    - tags

  # Nothing to do!
  script: /bin/true

  artifacts:
    paths:
      - public

release-notes:
  stage: release
  image: registry.gitlab.com/teklia/devops:latest

  only:
    - tags

  script:
    - devops release-notes

bump-python-deps:
  stage: release
  image: registry.gitlab.com/teklia/devops:latest

  only:
    - schedules

  script:
    - devops python-deps requirements.txt tests-requirements.txt
