name: Release

on:
  push:
    tags:
      - 'v*.*.*'

jobs:
  build-release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: '3.11'
      - name: Install build tools
        run: |
          python -m pip install --upgrade pip
          pip install build pyinstaller
      - name: Build wheel
        run: python -m build --wheel --sdist
      - name: Build binary
        run: pyinstaller --onefile -n voxvera voxvera/cli.py
      - name: Create AppImage
        run: |
          sudo apt-get update
          sudo apt-get install -y wget
          bash packaging/build_appimage.sh
      - name: Build Docker image
        run: docker build -t ghcr.io/${{ github.repository_owner }}/voxvera:${{ github.ref_name }} .
      - name: Login to GHCR
        uses: docker/login-action@v2
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Push Docker image
        run: docker push ghcr.io/${{ github.repository_owner }}/voxvera:${{ github.ref_name }}
      - name: Publish to PyPI
        uses: pypa/gh-action-pypi-publish@release/v1
        with:
          password: ${{ secrets.PYPI_API_TOKEN }}
      - name: Upload release assets
        uses: softprops/action-gh-release@v1
        with:
          files: |
            dist/*.whl
            dist/*.tar.gz
            dist/voxvera
            dist/VoxVera.AppImage
