image: ghcr.io/prefix-dev/pixi:0.29.0

variables:
  FF_USE_FASTZIP: "true"
  CACHE_COMPRESSION_LEVEL: "fastest"

pre-commit:
  variables:
    PRE_COMMIT_HOME: $CI_PROJECT_DIR/.pre-commit-cache
  script:
    - pixi run -e precommit git config --global --add safe.directory $CI_PROJECT_DIR
    - pixi run -e precommit check
  cache:
    key: "$CI_JOB_NAME"
    paths:
      - .pre-commit-cache
      - .pixi

test:
  script:
    - pixi run test
  cache:
    key: "$CI_JOB_NAME"
    paths:
      - .pixi
      - build

build:
  script:
    - pixi run -e publish uv build --sdist
    - pixi run -e publish twine check dist/*
  artifacts:
    paths:
      - dist
    expire_in: "7 days"
  cache:
    key: "$CI_JOB_NAME"
    paths:
      - .pixi

publish to test pypi:
  needs:
    - test
    - build
    - pre-commit
  rules:
    - if: '$CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+.*\+test$/' # vX.Y.Z.post1+test
  script:
    - pixi run -e publish twine upload -u __token__ -p $PYPI_TEST_TOKEN --repository testpypi dist/*
  cache:
    key: "$CI_JOB_NAME"
    paths:
      - .pixi

publish to pypi:
  needs:
    - test
    - build
    - pre-commit
  rules:
    - if: '$CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+[^+]*$/' # No +test
  script:
    - pixi run -e publish twine upload -u __token__ -p $PYPI_TOKEN dist/*
  cache:
    key: "$CI_JOB_NAME"
    paths:
      - .pixi
