name: Release version

on:
  push:
    tags:
      - '*'

jobs:
  deploy-package:
    name: Publish package
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - uses: actions/setup-python@v3

      - name: Install build dependencies
        run: pip install -U twine build

      - name: Build
        run: python -mbuild --wheel --sdist .

      - uses: actions/upload-artifact@v2
        with:
          path: |
            ./dist/*.whl
            ./dist/*.tar.gz

      - name: Publish to PyPI
        env:
          TWINE_USERNAME: __token__
          TWINE_PASSWORD: ${{ secrets.OPENQASM_BOT_PYPI_TOKEN }}
        run: twine upload dist/*.whl dist/*.tar.gz

      - name: Publish to GitHub
        uses: softprops/action-gh-release@v1
        with:
          draft: false
          prerelease: false
          fail_on_unmatched_files: true
          generate_release_notes: true
          files: |
            ./dist/*.whl
            ./dist/*.tar.gz

  deploy-docs:
    name: Publish documentation
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - uses: actions/setup-python@v3
        with:
          python-version: '3.9'

      - name: Install dependencies
        run: python -m pip install --upgrade pip tox

      - name: Generate HTML
        run: tox -e docs

      - name: Deploy HTML documentation
        uses: JamesIves/github-pages-deploy-action@v4.3.3
        with:
          branch: gh-pages
          folder: docs/_build/html
