stages:
  - test
  - build
  - deploy



pages_pdf:
  needs: []
  before_script:
    - pip3 install --break-system-packages --upgrade Cython setuptools pip
    - pip3 install --break-system-packages -r requirements.txt
    - python3 setup.py build_ext --inplace
  when: manual
  stage: build
  image: zoo.smok.co/build/build:pages
  script:
    - cd docs
    - make latexpdf
    - cd ..
    - mv docs/_build/latex/*.pdf .
  artifacts:
    paths:
      - "*.pdf"


pages:
  stage: build
  image: zoo.smok.co/build/build:pages
  before_script:
    - pip3 install --break-system-packages --upgrade Cython setuptools pip
    - pip3 install --break-system-packages -r requirements.txt
    - python3 setup.py build_ext --inplace
  script:
    - cd docs
    - make html
    - mv _build/html ../public
  artifacts:
    paths:
      - "public"
  only:
    - master
  needs: []

.test_python:
  stage: test
  before_script:
    - pip install --upgrade Cython setuptools pip coverage nose2
    - pip install -r requirements.txt
    - python setup.py build_ext --inplace
  variables:
    TESTING: "1"
  script:
    - python -m coverage run -m nose2 -vv -F
    - python -m coverage report
  coverage: /TOTAL.*\s+(\d+\%)/


test_python38:
  extends: .test_python
  image: python:3.8



test_python39:
  extends: .test_python
  image: python:3.9


test_python310:
  extends: .test_python
  image: python:3.10


test_python312:
  extends: .test_python
  image: python:3.12


test_python311:
  extends: .test_python
  image: python:3.11


.build_python:
  only:
    - tags
  except:
    - branches
  stage: build
  script:
    - pip install --break-system-packages --upgrade Cython setuptools pip repairwheel doctor-wheel
    - pip install --break-system-packages -r requirements.txt
    - python setup.py bdist_wheel
    - repairwheel dist/*.whl -o .
    - doctor-wheel *.whl
  after_script:
    - pip install twine
    - TWINE_PASSWORD=${CI_JOB_TOKEN} TWINE_USERNAME=gitlab-ci-token python3 -m twine upload --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi *.whl

upload_python311_armv7l:
  image: zoo.smok.co/build/build:latest
  stage: deploy
  dependencies:
    - build_python311_armv7l
  script:
    - TWINE_PASSWORD=${CI_JOB_TOKEN} TWINE_USERNAME=gitlab-ci-token python3 -m twine upload --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi *.whl
  only:
    - tags
  except:
    - branches

build_python38:
  extends: .build_python
  image: python:3.8

build_python39:
  extends: .build_python
  image: python:3.9


build_python310:
  extends: .build_python
  image: python:3.10


build_python311:
  extends: .build_python
  image: python:3.11


build_python312:
  extends: .build_python
  image: python:3.12



build_python3_sdist:
  extends: .build_python
  image: python:3.9
  artifacts:
    paths:
      - "*.whl"
  script:
    - pip install --break-system-packages --upgrade Cython setuptools pip
    - pip install --break-system-packages -r requirements.txt
    - python setup.py sdist
  after_script:
    - pip install twine
    - TWINE_PASSWORD=${CI_JOB_TOKEN} TWINE_USERNAME=gitlab-ci-token python3 -m twine upload --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi *.whl


build_python311_armv7l:
  extends: .build_python
  image: zoo.smok.co/build/build:armv7l-python3.11
  after_script:
    - echo "Do nothing"
  artifacts:
    paths:
      - "*.whl"
