name: Publish to PyPI

on:
  push:
    branches:
    - develop
    - main
    - patch-1
    paths:
    - ogc_api_records_core_client/**
    - .github/workflows/package.yaml
  release:
    types:
    - published
  pull_request:
    branches:
    - develop
    - main
    paths:
    - src/**

permissions:
  contents: read
  packages: write

jobs:

  deploy:
    runs-on: ubuntu-latest
    environment: release
    permissions:
      id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
    steps:
    - uses: actions/checkout@v4
    - name: Set up Python
      uses: actions/setup-python@v5
      with:
        python-version: '3.10'
        cache: pip
    - name: Install dependencies
      run: |
        # python -m pip install --upgrade pip
        # python -m pip install --upgrade pip
        pip install hatch
    - name: Build package
      run: "hatch build \n"
    - name: Test package
      run: |
        #hatch test
        echo "placeholder for tests"
    - name: Publish package distributions to PyPI (main)
      if: github.ref == 'refs/heads/main'
      uses: pypa/gh-action-pypi-publish@release/v1
      with:
        repository-url: https://upload.pypi.org/legacy/
    - name: Publish package distributions to PyPI (develop)
      if: github.ref != 'refs/heads/main'
      uses: pypa/gh-action-pypi-publish@release/v1
      with:
        repository-url: https://test.pypi.org/legacy/
