stages:
 - install
 - test
 - build_containers
 - deploy

.junit_template: &junit_definition
    artifacts:
      reports:
        junit: "junit*.xml"


install_py37:
  stage: install
  image: python:3.7-buster
  script:
    - apt-get -y update
    - python setup.py install
    - eossr-codemeta2zenodo --help
    - eossr-codemeta2zenodo --input_codemeta_file ./codemeta.json
    - cat .zenodo.json
  only:
    - branches

test_py37:
    stage: test
    image: python:3.7-buster
    script:
      - apt-get -y update
      - pip install pytest pytest-cov
      - pip install -e .
      - pytest eossr/
        --junitxml=junit_py37.xml
        --color=yes
        --verbose
        --cov=eossr
        --cov-report=xml
        --cov-report=term
    <<: *junit_definition

build_docker:
    stage: build_containers
    image: docker:19.03.12
    services:
        - docker:19.03.12-dind
    before_script:
        - cat /etc/os-release  # "Alpine Linux v3.12"
        - apk add git
        - export LAST_RELEASE=`git ls-remote --tags --refs --sort="v:refname" $CI_PROJECT_URL.git | tail -n1 | sed 's/.*\///'`
        - echo $LAST_RELEASE
    script:
        - cd Docker
        - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
        - docker build -t $CI_REGISTRY_IMAGE:$LAST_RELEASE .
        - docker push $CI_REGISTRY_IMAGE:$LAST_RELEASE
    only:
        - tags

pages:
    stage: deploy
    image: python:3.7-alpine
    script:
      - pip install -U sphinx
      - sphinx-build -b html docs public
    artifacts:
      paths:
        - public
    only:
      - master