image: nbxmpp-master:latest

stages:
  - test
  - build
  - deploy
  - publish

test-isort:
  stage: test
  rules:
    - when: always
  script:
    - isort --version
    - isort --check .
  interruptible: true

test-black:
  stage: test
  rules:
    - when: always
  script:
    - black --version
    - black --check .
  interruptible: true

test-ruff:
  stage: test
  rules:
    - when: always
  script:
    - ruff --version
    - ruff check .
  interruptible: true

test-pyright:
  stage: test
  rules:
    - when: always
  script:
    - pip install pygobject-stubs==2.16.0
    - pyright --version
    - pyright
  interruptible: true

test-unittest:
  stage: test
  rules:
    - when: always
  script:
    - python -m unittest discover -v
  interruptible: true

build-unix:
  stage: build
  dependencies: []
  rules:
    - when: always
  script:
    - pip install git+https://dev.gajim.org/gajim/release-helper.git
    - pip install build
    - python3 -m build
    - release-helper build-debian-pkg "$(find dist/nbxmpp-*.tar.gz)" 1 --pkgprefix=python3 --pkgsuffix=nightly

  artifacts:
    name: "nbxmpp-$CI_COMMIT_SHA"
    expire_in: 1 week
    paths:
      - dist/nbxmpp-*.tar.gz
      - dist/nbxmpp-*.whl
      - debian_build/*

deploy-pypi:
  image: nbxmpp-deploy:latest
  stage: deploy
  dependencies:
    - "build-unix"
  rules:
    - if: '$CI_COMMIT_TAG'
  script:
    - twine upload --username=__token__ --password=$PYPI_TOKEN dist/*

deploy-debian-nightly:
  image: nbxmpp-deploy:latest
  stage: deploy
  dependencies:
    - build-unix
  rules:
    - if: '$NIGHTLY_BUILD'
  allow_failure:
    exit_codes:
      - 100
  script:
    - |
      if [ "$FORCE_DEB_DEPLOY" != "true" ]
      then
        release-helper nightly-check
      fi
    - >
      release-helper deploy-to-ftp \
        --host=$FTP_HOST \
        --user=$FTP_USER \
        --password=$FTP_PASS \
        --directory=debian/nbxmpp/"$(date +'%Y%m%d')" \
        debian_build

publish-release:
  image: nbxmpp-publish:latest
  stage: publish
  dependencies: []
  rules:
    - if: '$CI_COMMIT_TAG'
  script:
    - >
      release-helper create-release \
        $CI_PROJECT_ID \
        $CI_RELEASE_TOKEN \
        --version=$CI_COMMIT_TAG \
        --tag=$CI_COMMIT_TAG
