image: mambaorg/micromamba:1.5.6-jammy

cache:
  paths:
    - micromamba
    - .pre-commit-cache
before_script:
  - mkdir -p micromamba
  - export MAMBA_ROOT_PREFIX=micromamba
  - micromamba create -yf environment.yml
  - eval "$(micromamba shell hook --shell bash)"
  - micromamba activate mumps
  - git config --global --add safe.directory $CI_PROJECT_DIR
variables:
  PRE_COMMIT_HOME: $CI_PROJECT_DIR/.pre-commit-cache

build and test:
  script:
    - spin test

pre-commit:
  script:
    - pre-commit run --all-files

publish to test pypi:
  needs:
    - build and test
    - pre-commit
  rules:
    - if: '$CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+.*\+test$/' # vX.Y.Z.post1+test
  script:
    - python -m build
    - mkdir wheelhouse && mv dist/*.whl wheelhouse
    - auditwheel repair --plat manylinux_2_12_x86_64 wheelhouse/*.whl -w dist
    - twine check dist/*
    - twine upload -u __token__ -p $PYPI_TEST_TOKEN --repository testpypi dist/*

publish to pypi:
  needs:
    - build and test
    - pre-commit
  rules:
    - if: '$CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+[^+]*$/' # No +test
  script:
    - python -m build
    - mkdir wheelhouse && mv dist/*.whl wheelhouse
    - auditwheel repair --plat manylinux_2_12_x86_64 wheelhouse/*.whl -w dist
    - twine check dist/*
    - twine upload -u __token__ -p $PYPI_TOKEN dist/*
