# This workflow uploads the CSE.LK package to Test PyPI for testing purposes

name: Publish to Test PyPI

on:
  push:
    tags:
      - 'v*-beta*'
      - 'v*-alpha*'
      - 'v*-rc*'
  # Allow manual triggering
  workflow_dispatch:

permissions:
  contents: read

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ["3.8", "3.9", "3.10", "3.11"]

    steps:
      - uses: actions/checkout@v4

      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -e ".[dev]"

      - name: Run tests
        run: |
          python -m pytest tests/ -v

  build-and-publish:
    runs-on: ubuntu-latest
    needs: test
    permissions:
      # IMPORTANT: this permission is mandatory for trusted publishing
      id-token: write

    environment:
      name: test-pypi
      url: https://test.pypi.org/project/cse.lk/

    steps:
      - uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.x"

      - name: Install build dependencies
        run: |
          python -m pip install --upgrade pip
          python -m pip install build twine

      - name: Build package
        run: |
          python -m build

      - name: Check package
        run: |
          python -m twine check dist/*

      - name: Publish to Test PyPI
        uses: pypa/gh-action-pypi-publish@release/v1
        with:
          repository-url: https://test.pypi.org/legacy/
          packages-dir: dist/
          print-hash: true 