kind: pipeline
type: docker
name: default

workspace:
  path: /drone/src

steps:
  - name: build
    image: git.argideli.com/quertex/docker-win-pyinstaller:latest
    pull: always
    commands:
      # prepare output directory
      - mkdir -p /drone/src/out/
      - mkdir -p /drone/src/dist/
      # add dependancies
      - pacman -Syu  --noconfirm
      #- pacman -Sy --noconfirm --needed wget lib32-gnutls libunwind lib32-expat python3 python-pip python-pipenv gcc-fortran  base-devel python-numpy python-pandas gcc-libs gnutls wine-staging
      - pacman -Sy --noconfirm --needed libxkbcommon lib32-libxkbcommon  python-xkbcommon python-cryptography python-pillow python-pycryptodome python-typing_extensions python-build python-flit-core python-installer python-setuptools python-wheel  wget lib32-gnutls libunwind lib32-expat python3 python-pip gcc-fortran base-devel gcc-libs gnutls wine-staging
      # linux build
      - cd /drone/src/
      - python --version
      #- python -m venv --without-pip --system-site-packages venv
      - python -m venv venv
      - source venv/bin/activate
      #- ldd /usr/lib/python3.12/lib-dynload/pyexpat.cpython-312-x86_64-linux-gnu.so
      - pip3 list
      - pip3 config --user set global.progress_bar off
      - pip3 config set global.trusted-host "pypi.org files.pythonhosted.org pypi.python.org" --trusted-host=pypi.python.org --trusted-host=pypi.org --trusted-host=files.pythonhosted.org
      - pip3 install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org pip setuptools
      - pip3 install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --ignore-installed -r requirements.txt
      - pyinstaller --onefile --name akmi-utils.bin -y  --distpath /drone/src/out/ /drone/src/widget.py
      - deactivate
      - cp -v out/akmi-utils.bin dist/
      # clean up
      - rm -rf venv
      - rm -rf /drone/src/out
      - mkdir -p /drone/src/out/
      # windows build
      - wine c:/python/python.exe -m pip config --user set global.progress_bar off
      - wine c:/python/python.exe -m pip install --prefer-binary -r z:/drone/src/requirements.txt
      - wine c:/python/Scripts/pyinstaller.exe --onefile --name akmi-utils -y --distpath z:/drone/src/out z:/drone/src/widget.py
      - cp -v out/akmi-utils.exe dist/

  - name: gitea_release
    image: plugins/gitea-release
    settings:
      base_url: https://git.argideli.com
      api_key:
        from_secret: gitea_token
      files: /drone/src/dist/*
      checksum:
        - md5
        - sha256
        - crc32
    when:
      event:
        exclude:
        - push
  
image_pull_secrets:
  - docker_token
