test:
  stage: test
  needs: []
  image:
    name: python:3.14.0-slim@sha256:0aecac02dc3d4c5dbb024b753af084cafe41f5416e02193f1ce345d671ec966e
    entrypoint: [""]
  before_script:
    - apt-get update
    - apt-get install -y --no-install-recommends git
    - pip install --root-user-action=ignore hatch hatch-pip-compile
  script:
    - hatch fmt
    - hatch test --cover -vv
    - hatch run types:check
    - hatch run hatch-test.py3.13:coverage html
    - git add --intent-to-add .
    - git diff --exit-code HEAD
  interruptible: true
  rules:
    - if: '$TEST_DISABLED'
      when: never
    - if: '$CI_COMMIT_TAG || $CI_COMMIT_BRANCH'
  artifacts:
    paths:
      - htmlcov/
    expire_in: 15 days
    when: always


test-deb:
  stage: test
  image: debian:bookworm@sha256:3d957cd5e0693cf44cbb65aa43033fb701443df6b0afa4dcc9293c9bb7a258f9
  needs: [build-deb]
  before_script:
    - apt-get update
    - apt-get install -y autopkgtest python3-setuptools python3-vcr ./debian/output/gitlabracadabra_*_all.deb
  script:
    - autopkgtest --output-dir /tmp/output-dir -B  . -- null
  rules:
    - if: '$TEST_DISABLED'
      when: never
    - if: '$CI_COMMIT_TAG || $CI_COMMIT_BRANCH'


test-image:
  stage: test
  image: debian:trixie-slim@sha256:18764e98673c3baf1a6f8d960b5b5a1ec69092049522abac4e24a7726425b016
  needs: [build]
  services:
    - name: 'docker:29-dind@sha256:d003717ad7a27d359dd2f5f6aa6ca691f5f58671e8d1ff0277d07e5635bb8332'
      command: ['--tls=false', '--host=tcp://0.0.0.0:2375']
  before_script:
    - apt-get update
    - apt-get install -y docker.io
  script:
    - |
      if [[ -z "$CI_COMMIT_TAG" ]]; then
        export CI_APPLICATION_REPOSITORY=${CI_APPLICATION_REPOSITORY:-$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG}
        export CI_APPLICATION_TAG=${CI_APPLICATION_TAG:-$CI_COMMIT_SHA}
      else
        export CI_APPLICATION_REPOSITORY=${CI_APPLICATION_REPOSITORY:-$CI_REGISTRY_IMAGE}
        export CI_APPLICATION_TAG=${CI_APPLICATION_TAG:-$CI_COMMIT_TAG}
      fi
    - export DOCKER_HOST='docker'
    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
    - docker build --file test/Dockerfile --build-arg IMAGE="$CI_APPLICATION_REPOSITORY:$CI_APPLICATION_TAG" .
  rules:
    - if: '$TEST_DISABLED'
      when: never
    - if: '$CI_COMMIT_TAG || $CI_COMMIT_BRANCH'
