stages:
  - deploy:staging
  - deploy:production

.deploy:
  image:
    name: ghcr.io/pyo3/maturin:v1.7.1
    entrypoint: ["/usr/bin/bash"]
  script:
    - sed -i "s/##VERSION##/$CI_COMMIT_TAG/g" Cargo.toml
    - sed -i "s/##VERSION##/$CI_COMMIT_TAG/g" pyproject.toml
    - maturin publish --repository-url $MATURIN_REPOSITORY_URL --token $MATURIN_PYPI_TOKEN
  rules:
  - if: $CI_COMMIT_TAG
  artifacts:
    expire_in: 1 week
    paths:
      - target/*


deploy:staging:
    extends: .deploy
    stage: deploy:staging
    environment:
      name: staging
    variables:
        MATURIN_REPOSITORY_URL: https://test.pypi.org/legacy/

deploy:production:
    extends: .deploy
    stage: deploy:production
    when: manual
    environment:
      name: production
    variables:
      MATURIN_REPOSITORY_URL: https://pypi.org/legacy/