name: Build and Publish on: push: # Only trigger on tags with version format tags: - '*.*.*' # Allow manual triggering for testing workflow_dispatch: jobs: # Use Python build first, as fallback build-python: runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v4 with: fetch-depth: 0 - name: Set up Python uses: actions/setup-python@v5 with: python-version: '3.12' - name: Install build tools run: | python -m pip install --upgrade pip pip install build twine - name: Build package run: | python -m build - name: Store Python build uses: christopherhx/gitea-upload-artifact@v4 with: name: python-package path: | dist/*.tar.gz dist/*.whl retention-days: 7 build-uv: runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v4 with: fetch-depth: 0 - name: Install uv uses: astral-sh/setup-uv@v5 with: enable-cache: true - name: Set up Python uses: actions/setup-python@v5 with: python-version: '3.12' - name: Install the project run: uv sync --all-extras --dev - name: Build package run: | uv build - name: Store Python build uses: christopherhx/gitea-upload-artifact@v4 with: name: uv-package path: | dist/*.tar.gz dist/*.whl retention-days: 7 # Use Nix build as primary method # build-nix: # runs-on: nix-runner # steps: # - name: Checkout repository # uses: actions/checkout@v4 # with: # fetch-depth: 0 # - name: Setup Attic Cache # uses: ryanccn/attic-action@3354ae812cb672e1381be4c7914204c44db53866 # with: # endpoint: ${{ secrets.ATTIC_ENDPOINT }} # cache: ${{ secrets.ATTIC_CACHE }} # token: ${{ secrets.ATTIC_TOKEN }} # # Build the package using Nix # - name: Build with Nix # run: | # # Build Python package with Nix # # Adjust this to match your flake output for the Python package # nix build .#pythonPackage # - name: Copy built package to dist # run: | # mkdir -p dist # cp -r result/* dist/ || echo "Failed to copy result to dist - check paths" # - name: Store Nix build # uses: christopherhx/gitea-upload-artifact@v4 # with: # name: nix-package # path: dist/ # retention-days: 7 # Publish to PyPI publish-pypi: needs: [build-python, build-uv] runs-on: ubuntu-latest environment: name: pypi # Only publish on tag push, not on manual workflow dispatch if: startsWith(github.ref, 'refs/tags/') steps: - name: Install uv uses: astral-sh/setup-uv@v5 with: enable-cache: true - name: Download Uv build uses: christopherhx/gitea-download-artifact@v4 with: name: uv-package path: dist-uv - name: Download Python build (fallback) uses: christopherhx/gitea-download-artifact@v4 with: name: python-package path: dist-python - name: Setup distribution directory run: | mkdir -p dist # Prefer Nix build results, fall back to Python build if [ -n "$(ls -A dist-uv 2>/dev/null)" ]; then echo "Using uv build artifacts" cp -r dist-uv/* dist/ elif [ -n "$(ls -A dist-nix 2>/dev/null)" ]; then echo "Using Nix build artifacts" cp -r dist-nix/* dist/ else echo "Using Python build artifacts" cp -r dist-python/* dist/ fi - name: Print distribution directory run: ls -la dist - name: Publish to PyPI run: uv publish env: UV_PUBLISH_TOKEN: ${{ secrets.PYPI_API_TOKEN }} # Use TestPyPI for non-production releases # repository-url: https://test.pypi.org/legacy/