name: publish
on:
  workflow_dispatch:
  release:
    types:
      - published
permissions:
  contents: read
  id-token: write
jobs:
  publish:
    if: github.repository_owner == 'xonsh'
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        python-version:
          - "3.11"
          - "3.12"
          - "3.13"
    steps:
      - uses: actions/checkout@v6
      - name: setup-python
        uses: actions/setup-python@v6
        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 PyPI
        uses: pypa/gh-action-pypi-publish@release/v1

  build-appimage:
    if: github.repository_owner == 'xonsh'
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v6
      - name: setup-python
        uses: actions/setup-python@v6
        with:
          python-version: "3.11"
          cache: 'pip'
          cache-dependency-path: 'pyproject.toml'
      - name: install python-appimage
        run: pip install python-appimage
      - name: create requirements.txt
        run: |
          echo $PWD > ./appimage/requirements.txt
          cat ./appimage/pre-requirements.txt >> ./appimage/requirements.txt
      - name: build xonsh AppImage
        run: |
          python -m python_appimage build app -p 3.11 ./appimage  # Unpin python after fix https://github.com/xonsh/xonsh/issues/5166
      - name: upload xonsh AppImage to release
        if: github.event_name == 'release' || github.event_name == 'workflow_dispatch'
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: gh release upload ${{ github.ref_name }} ./xonsh-x86_64.AppImage
