stages:
  - test
  - quality-assurance
  - build
  - release

variables:
  CONTAINER_TEST_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
  CONTAINER_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest

py312:
  stage: test
  image: python:3.12-alpine
  before_script:
    - apk add --no-cache libmagic
    - apk add --no-cache gettext
    - pip install tox --no-cache-dir
  script: tox -e py312

py313:
  stage: test
  image: python:3.13-alpine
  before_script:
    - apk add --no-cache libmagic
    - apk add --no-cache gettext
    - pip install tox --no-cache-dir
  script: tox -e py313

linters:
  stage: quality-assurance
  image: python:3-alpine
  before_script:
    - pip install tox --no-cache-dir
  script: tox -e linters
  allow_failure: true

build-image:
  image: docker
  stage: build
  services:
    - docker:dind
  before_script:
    - echo "$CI_REGISTRY_PASSWORD" | docker login $CI_REGISTRY -u $CI_REGISTRY_USER --password-stdin
  script:
    - docker build --pull -t $CONTAINER_TEST_IMAGE .
    - docker push $CONTAINER_TEST_IMAGE

release-image:
  image: docker
  stage: release
  services:
    - docker:dind
  before_script:
    - echo "$CI_REGISTRY_PASSWORD" | docker login $CI_REGISTRY -u $CI_REGISTRY_USER --password-stdin
  script:
    - docker pull $CONTAINER_TEST_IMAGE
    - docker tag $CONTAINER_TEST_IMAGE $CONTAINER_RELEASE_IMAGE
    - docker push $CONTAINER_RELEASE_IMAGE
  rules:
    - if: $CI_COMMIT_BRANCH == "main"

