stages:
  - lint&test
  - upload
  - image

.py: &py
  image: "domaindrivenarchitecture/ddadevops-python:4.10.7"
  before_script:
    - export RELEASE_ARTIFACT_TOKEN=$MEISSA_REPO_BUERO_RW
    - python --version
    - pip install -r requirements.txt

.img: &img
  image: "domaindrivenarchitecture/ddadevops-dind:4.10.7"
  services:
    - docker:dind
  before_script:
  - export IMAGE_DOCKERHUB_USER=$DOCKERHUB_USER
  - export IMAGE_DOCKERHUB_PASSWORD=$DOCKERHUB_PASSWORD
  - export IMAGE_TAG=$CI_COMMIT_TAG

.tag_only: &tag_only
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
      when: never
    - if: '$CI_COMMIT_TAG =~ /^[0-9]+\.[0-9]+\.[0-9]+$/'

lint:
  <<: *py
  stage: lint&test
  script:
  - pip install -r dev_requirements.txt
  - pyb lint

pytest:
  <<: *py
  stage: lint&test
  script:
  - pip install -r dev_requirements.txt
  - pyb test

pypi-stable:
  <<: *py
  <<: *tag_only
  stage: upload
  script:
    - pyb -P version=$CI_COMMIT_TAG publish upload publish_artifacts

clj-cljs-image-publish:
  <<: *img
  <<: *tag_only
  stage: image
  script:
    - cd infrastructure/clj-cljs && pyb image publish

clj-image-publish:
  <<: *img
  <<: *tag_only
  stage: image
  script:
    - cd infrastructure/clj && pyb image publish

python-image-publish:
  <<: *img
  <<: *tag_only
  stage: image
  script:
    - cd infrastructure/python && pyb image publish

dind-image-publish:
  <<: *img
  <<: *tag_only
  stage: image
  script:
    - cd infrastructure/dind && pyb image publish

ddadevops-image-publish:
  <<: *img
  <<: *tag_only
  stage: image
  script:
    - cd infrastructure/ddadevops && pyb image publish

kotlin-image-publish:
  <<: *img
  <<: *tag_only
  stage: image
  script:
    - cd infrastructure/kotlin && pyb image publish