stages:
  - test

cache:
  key: "$CI_PROJECT_NAME"
  paths:
    - $HOME/.cache/pip

before_script:
  - pip install tox

test:
  stage: test
  image: $IMAGE
  script: tox --skip-missing-interpreters
  parallel:
    matrix:
      - IMAGE:
          - python:3.7
          - python:3.8
          - python:3.9

stages:
  - test
  - release

cache:
  key: "$CI_PROJECT_NAME"
  paths:
    - $HOME/.cache/pip

before_script:
  - pip install tox

test:
  stage: test
  image: $IMAGE
  script: tox --skip-missing-interpreters
  parallel:
    matrix:
      - IMAGE:
          - python:3.7
          - python:3.8
          - python:3.9

publish_pkg:
  image: python:3.9
  stage: release
  rules:
    - if: $CI_COMMIT_TAG && $CI_COMMIT_REF_PROTECTED
  script:
    - pip install twine
    - python setup.py sdist bdist_wheel
    # Publish to PyPI
    - export TWINE_USERNAME=__token__
    - export TWINE_PASSWORD=${PYPI_TOKEN}
    - python -m twine upload
        --repository-url https://upload.pypi.org/legacy/
        dist/*
    # Publish to Gitlab
    - export TWINE_USERNAME=gitlab-ci-token
    - export TWINE_PASSWORD=${CI_JOB_TOKEN}
    - python -m twine upload
        --repository-url https://gitlab.com/api/v4/projects/${CI_PROJECT_ID}/packages/pypi
        dist/*

publish_gitlab_release:
  image: registry.gitlab.com/gitlab-org/release-cli:latest
  stage: release
  rules:
    - if: $CI_COMMIT_TAG && $CI_COMMIT_REF_PROTECTED
  script:
    - echo 'release job'
  release:
    name: 'Release $CI_COMMIT_TAG'
    description: 'Release $CI_COMMIT_TAG. Tagged by $GITLAB_USER_LOGIN'
    tag_name: '$CI_COMMIT_TAG'
    ref: '$CI_COMMIT_TAG'

Add release jobs to gitlab ci
Add release jobs to gitlab ci
