---
.python3:
  tags: [ns4.shore.co.il]
  image: registry.shore.co.il/ci-images:python3
  variables:
    XDG_CACHE_HOME: "$CI_PROJECT_DIR/.cache"
  cache:
    paths:
      - .cache/

.python3-build:
  extends: .python3
  stage: build
  image: registry.shore.co.il/ci-images:python3-build

build-wheel:
  extends: .python3-build
  script:
    - >-
      [ ! -f setup.py ] ||
      python3 setup.py check --verbose --metadata --restructuredtext --strict
    - python3 -m build
  after_script:
    - &twine_check twine check dist/*.whl
  artifacts:
    paths:
      - dist/*.tar.gz
      - dist/*.whl

.install-wheel:
  extends: .python3
  stage: test
  before_script:
    - python3 -m pip install --break-system-packages dist/*.whl
  script:
    - "true"
  needs:
    - job: build-wheel
      artifacts: true

.audit-wheel:
  extends: .python3-build
  stage: test
  script:
    - find dist/ -name '*.whl' -print0 | xargs --null auditwheel --verbose show
  needs:
    - job: build-wheel
      artifacts: true

pypi-upload:
  extends: .python3-build
  stage: deploy
  script:
    - *twine_check
    - twine upload --config-file "$pypirc" dist/*
  rules:
    - if: $CI_COMMIT_TAG && ($SKIP_PYPI_UPLOAD == null)
  needs:
    - job: build-wheel
      artifacts: true
