# CI configuration which tests ucamlookup against supported Django and Python
# versions.
#
# GitLab CI does nto support Matrix builds in the traditional sense. Instead we
# build up a matrix of test jobs using inheritance via "extends".
#
# See also: https://gitlab.com/gitlab-org/gitlab-ce/issues/19199

# Test code coverage
coverage:
  extends: .test
  variables:
    TOX_ENVLIST: coverage
    PYTHON_VERSION: "3.7"

  # Look for the summary line output from coverage's text report. The
  # parentheses are used to indicate which portion of the report contains the
  # coverage percentage.
  coverage: '/^TOTAL\s+\d+\s+\d+\s+(\d+)%$/'

# Check for PEP8 violations
flake8:
  extends: .test
  variables:
    TOX_ENVLIST: flake8
    PYTHON_VERSION: "3.7"

# Run test suite against supported Python/Django combinations.
python27-django111:
  extends: .py27
  variables:
    TOX_DJANGO_FRAGMENT: "django111"

python34-django111:
  extends: .py34
  variables:
    TOX_DJANGO_FRAGMENT: "django111"

python35-django111:
  extends: .py35
  variables:
    TOX_DJANGO_FRAGMENT: "django111"

python36-django111:
  extends: .py36
  variables:
    TOX_DJANGO_FRAGMENT: "django111"

python37-django111:
  extends: .py37
  variables:
    TOX_DJANGO_FRAGMENT: "django111"

python34-django20:
  extends: .py34
  variables:
    TOX_DJANGO_FRAGMENT: "django20"

python35-django20:
  extends: .py35
  variables:
    TOX_DJANGO_FRAGMENT: "django20"

python36-django20:
  extends: .py36
  variables:
    TOX_DJANGO_FRAGMENT: "django20"

python37-django20:
  extends: .py37
  variables:
    TOX_DJANGO_FRAGMENT: "django20"

python35-django21:
  extends: .py35
  variables:
    TOX_DJANGO_FRAGMENT: "django21"

python36-django21:
  extends: .py36
  variables:
    TOX_DJANGO_FRAGMENT: "django21"

python37-django21:
  extends: .py37
  variables:
    TOX_DJANGO_FRAGMENT: "django21"

# Template jobs which run tests in various Python versions.
.py27:
  extends: .test
  variables:
    PYTHON_VERSION: "2.7"
    TOX_PY_FRAGMENT: "py27"

.py34:
  extends: .test
  variables:
    PYTHON_VERSION: "3.4"
    TOX_PY_FRAGMENT: "py34"

.py35:
  extends: .test
  variables:
    PYTHON_VERSION: "3.5"
    TOX_PY_FRAGMENT: "py35"

.py36:
  extends: .test
  variables:
    PYTHON_VERSION: "3.6"
    TOX_PY_FRAGMENT: "py36"

.py37:
  extends: .test
  variables:
    PYTHON_VERSION: "3.7"
    TOX_PY_FRAGMENT: "py37"

# Base test template job.
.test:
  image: python:${PYTHON_VERSION}

  script:
    - pip install tox
    - tox -e ${TOX_ENVLIST}

  variables:
    PYTHON_VERSION: replace-with-python-version
    TOX_PY_FRAGMENT: replace-with-pyXY
    TOX_DJANGO_FRAGMENT: replace-with-djangoXY
    TOX_ENVLIST: "$TOX_PY_FRAGMENT-$TOX_DJANGO_FRAGMENT"
