name: "CI for pypl publish"
on:
  push:
    branches:
      - master # publish release on master
      - develop # publish snapshot on develop
  workflow_dispatch:
  # allow manual trigger
env:
  DEBIAN_FRONTEND: noninteractive
  TZ: UTC
jobs:
  publish-lib:
    runs-on: general
    container:
      image: ubuntu:24.04
    steps:
      # need to setup node and git
      - run: |
          apt-get update
          apt-get install -y nodejs git libsqlite3-0
      # check out code
      - uses: actions/checkout@v4
      - uses: https://github.com/actions/setup-python@v5
        with:
          python-version: '3.11'
      # install dependencies
      - run: pip install -e .[dev]
      # run pytest
      - run: pytest
      # replace timestamp building dev version
      - name: Add timestamp to version
        if: github.head_ref != 'master'
        run: |
          sed -i -E "s/(version = \"[^\"]+)(-dev)\"/\1\2$(date -u +'%Y%m%d%H%M%S')\"/" pyproject.toml
          cat pyproject.toml
      - name: Build wheel
        run: |
          python -m build
      # publish
      - name: publish to pulp pypi
        run: |
          twine upload --repository-url https://git.cleverthis.com/api/packages/clevermicro/pypi \
                       --username ${CI_REGISTRY_USER} \
                       --password ${CI_REGISTRY_PASSWORD} \
                       --verbose \
                        dist/*
        env:
          CI_REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
          CI_REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
