name: CI
on: [push, pull_request]
jobs:
  build-and-test:
    name: Build and run unit tests
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install uv
        uses: astral-sh/setup-uv@v5
      - run: uv build
      - run: uv run --group dev pytest
      - name: "Upload Artifacts"
        uses: actions/upload-artifact@v4
        with:
          name: dist
          path: dist
  pypi-release:
    name: Upload release to PyPI
    needs: build-and-test
    runs-on: ubuntu-latest
    environment:
      name: release
      url: https://pypi.org/p/legacy-cgi
    permissions:
      id-token: write
    if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
    steps:
      - name: "Download Artifacts"
        uses: actions/download-artifact@v4
        with:
          name: dist
          path: dist
      - name: Publish package distributions to PyPI
        uses: pypa/gh-action-pypi-publish@release/v1
