stages:
  - unittest
  - build


.before_test:
  stage: unittest
  services:
    - name: rabbitmq:3.10-management
      alias: rabbitmq
  before_script:
    - python setup.py install
    - pip install --break-system-packages nose2 coverage requests yapf nose2[coverage_plugin]
    - coverage run --append -m compile_definitions
  artifacts:
    paths:
      - ".coverage.*"
  variables:
    AMQP_HOST: "rabbitmq"


.before_test_rmq4:
  extends: .before_test
  services:
    - name: rabbitmq:4.0-management
      alias: rabbitmq


stresstest_select:
  extends: .before_test
  script:
    - coverage run --append -m stress_tests
  variables:
    COOLAMQP_FORCE_SELECT_LISTENER: "1"
    AMQP_HOST: "rabbitmq"
  after_script:
    - mv .coverage .coverage.stressselect



stresstest_epoll:
  extends: .before_test
  script:
    - coverage run --append -m stress_tests
  after_script:
    - mv .coverage .coverage.stressepoll



unittest_select:
  extends: .before_test
  script:
    - coverage run --append -m nose2 -F -vv
  variables:
    COOLAMQP_FORCE_SELECT_LISTENER: "1"
    AMQP_HOST: "rabbitmq"
  after_script:
    - mv .coverage .coverage.unitselect



unittest_epoll_python27:
  extends: .before_test
  image: python:2.7
  before_script:
    - pip install nose2 nose2[coverage_plugin]
    - python setup.py install
  script:
    - nose2 -F -vv
  variables:
    AMQP_HOST: "rabbitmq"
  after_script:
    - mv .coverage .coverage.python27epoll


unittest_epoll:
  extends: .before_test
  script:
    - coverage run --append -m nose2 -F -vv
  after_script:
    - mv .coverage .coverage.unitepoll


unittest_epoll_rmq4:
  extends: .before_test_rmq4
  script:
    - coverage run --append -m nose2 -F -vv
  after_script:
    - mv .coverage .coverage.unitepoll_rmq4


calc_coverage:
  stage: build
  dependencies:
    - unittest_epoll_rmq4
    - unittest_epoll
    - unittest_select
    - stresstest_epoll
    - stresstest_select
  script:
    - coverage combine
    - coverage xml
    - coverage report
  coverage: /TOTAL.*\s+(\d+\%)/


pages:
  image: zoo.smok.co/build/build:latest
  stage: build
  script:
    - cd docs
    - make html
    - cd ..
    - mv docs/_build/html public
  artifacts:
    paths:
      - public


build_python:
  stage: build
  before_script:
    - pip install --break-system-packages --upgrade setuptools pip twine
  script:
    - python setup.py bdist_wheel
    - mv dist/*.whl .
  artifacts:
    paths:
      - "*.whl"
  after_script:
    - TWINE_PASSWORD=${CI_JOB_TOKEN} TWINE_USERNAME=gitlab-ci-token python3 -m twine upload --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi *.whl
  only:
    - tags
  except:
    - branches
