add publish.yml (#182) #17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish | ||
| on: | ||
| push: | ||
| branches: [ test_publish ] | ||
| tags: | ||
| - 'v*' | ||
| workflow_dispatch: | ||
| jobs: | ||
| build: | ||
| name: Build distributions on ${{ matrix.os }} (Python ${{ matrix.python-version }}) | ||
| runs-on: ${{ matrix.os }} | ||
| strategy: | ||
| matrix: | ||
| os: [ubuntu-latest, windows-latest] | ||
| python-version: ['3.10', '3.11', '3.12'] | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| submodules: true | ||
| - name: Install dependencies (Linux) | ||
| if: runner.os == 'Linux' | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y \ | ||
| libglm-dev libglfw3-dev libpng-dev libjpeg-dev libeigen3-dev | ||
| - name: Set up Python | ||
| uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
| cache: 'pip' | ||
| - name: Upgrade pip and install build deps | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install build setuptools scikit-build scikit-build-core pybind11 | ||
| - name: Build sdist and wheel | ||
| run: | | ||
| python -m build --sdist --wheel -n | ||
| - name: Upload built distributions as artifact | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: dist-${{ matrix.os }}-${{ matrix.python-version }} | ||
| path: dist/* | ||
| publish: | ||
| name: Publish to PyPI | ||
| runs-on: ubuntu-latest | ||
| needs: build | ||
| if: startsWith(github.ref, 'refs/tags/v') | ||
| steps: | ||
| - name: Download build artifacts | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| # download all artifacts produced by the build job | ||
| path: downloaded_artifacts | ||
| - name: Collect distributions into dist/ | ||
| run: | | ||
| mkdir -p dist | ||
| find downloaded_artifacts -type f \( -name "*.whl" -o -name "*.tar.gz" \) -exec cp {} dist/ \; | ||
| - name: Show collected files | ||
| run: ls -la dist || true | ||
| - name: Install twine | ||
| run: python -m pip install --upgrade pip twine | ||
| - name: Publish to PyPI via Twine | ||
| env: | ||
| TWINE_USERNAME: __token__ | ||
| TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | ||
| run: | | ||
| python -m pip install --upgrade twine | ||
| # twine check may warn but won't block publishing here | ||
| twine check dist/* || true | ||
| twine upload --non-interactive -u "$TWINE_USERNAME" -p "$TWINE_PASSWORD" dist/* | ||