# 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

include:
  # Bring in the AutoDevOps template from GitLab.
  # It can be viewed at:
  # https://gitlab.com/gitlab-org/gitlab-ee/blob/master/lib/gitlab/ci/templates/Auto-DevOps.gitlab-ci.yml
  - template: Auto-DevOps.gitlab-ci.yml

  # Support uploading to PyPI
  - project: 'uis/devops/continuous-delivery/ci-templates'
    ref: v3.7.1
    file: '/pypi-release.yml'

variables:
  # We use matrix testing (below) rather than the Auto-DevOps "test" job.
  TEST_DISABLED: "true"

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

  # 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.11"

# Run test suite against supported Python/Django combinations.
python38-django42:
  extends: .py38
  variables:
    TOX_DJANGO_FRAGMENT: "django42"

python39-django42:
  extends: .py39
  variables:
    TOX_DJANGO_FRAGMENT: "django42"

python310-django42:
  extends: .py310
  variables:
    TOX_DJANGO_FRAGMENT: "django42"

python311-django42:
  extends: .py311
  variables:
    TOX_DJANGO_FRAGMENT: "django42"

python312-django42:
  extends: .py312
  variables:
    TOX_DJANGO_FRAGMENT: "django42"

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

python38-django32:
  extends: .py38
  variables:
    TOX_DJANGO_FRAGMENT: "django32"

python39-django32:
  extends: .py39
  variables:
    TOX_DJANGO_FRAGMENT: "django32"

# Template jobs which run tests in various Python versions.

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

.py38:
  extends: .test
  variables:
    PYTHON_VERSION: "3.8"
    TOX_PY_FRAGMENT: "py38"

.py39:
  extends: .test
  variables:
    PYTHON_VERSION: "3.9"
    TOX_PY_FRAGMENT: "py39"

.py310:
  extends: .test
  variables:
    PYTHON_VERSION: "3.10"
    TOX_PY_FRAGMENT: "py310"

.py311:
  extends: .test
  variables:
    PYTHON_VERSION: "3.11"
    TOX_PY_FRAGMENT: "py311"

.py312:
  extends: .test
  variables:
    PYTHON_VERSION: "3.12"
    TOX_PY_FRAGMENT: "py312"

# Base test template job.
.test:
  stage: 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"
