name: publish

on:
  workflow_dispatch:
  release:
    types:
      - published

permissions:
  contents: read

jobs:
  publish:
    if: github.repository_owner == 'xonsh'
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        python-version:
          - "3.9"
          - "3.10"
          - "3.11"
          - "3.12-dev"
    steps:
      - uses: actions/checkout@v3
      - name: setup-python
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}
          cache: 'pip'
          cache-dependency-path: 'pyproject.toml'
      - name: install pypa/build
        run: pip install build
      - name: build sdist(tarball) to dist/
        if: ${{ startsWith(matrix.python-version, '3.11') }}
        run: python -m build . --sdist
      - name: build bdist(wheel) to dist/
        run: python -m build . --wheel
      - name: publish to TestPyPI
        uses: pypa/gh-action-pypi-publish@release/v1
        with:
          user: __token__
          password: ${{ secrets.PYPI_API_TOKEN }}
