name: Publish

on:
  release:
    types:
      - created

jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - name: Dump GitHub context
        env:
          GITHUB_CONTEXT: ${{ toJson(github) }}
        run: echo "$GITHUB_CONTEXT"
      - uses: actions/checkout@v3
      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: "3.7"
          # Issue ref: https://github.com/actions/setup-python/issues/436
          # cache: "pip"
          cache-dependency-path: pyproject.toml
      - uses: actions/cache@v3
        id: cache
        with:
          path: ${{ env.pythonLocation }}
          key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-publish
      - name: Install build dependencies
        if: steps.cache.outputs.cache-hit != 'true'
        run: pip install build
      - name: Build distribution
        run: python -m build
      - name: Publish
        uses: pypa/gh-action-pypi-publish@v1.8.6
        with:
          password: ${{ secrets.PYPI_API_TOKEN }}
      - name: Dump GitHub context
        env:
          GITHUB_CONTEXT: ${{ toJson(github) }}
        run: echo "$GITHUB_CONTEXT"
