Generate wheels on every commit #415
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: Python wheel | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| pull_request: | |
| branches: [ "main" ] | |
| permissions: | |
| contents: read | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Set up Python | |
| uses: actions/setup-python@v3 | |
| with: | |
| python-version: '3.12' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install build | |
| - name: Build package | |
| run: python -m build | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: wheel | |
| path: ./dist/*.whl | |
| - name: Publish wheels to orphan `wheels` branch | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| # Create a fresh working directory | |
| rm -rf wheels-branch | |
| mkdir wheels-branch | |
| cd wheels-branch | |
| # Initialize git repo | |
| git init | |
| git remote add origin https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git | |
| git fetch origin wheels || true | |
| # Create orphan branch | |
| git checkout --orphan wheels | |
| git reset --hard | |
| # Copy wheels | |
| mkdir -p wheels | |
| cp ./dist/*.whl wheels/ | |
| echo "Wheels to publish:" | |
| ls -lh wheels/ | |
| # Commit | |
| git config user.name "GitHub Actions" | |
| git config user.email "actions@github.com" | |
| git add wheels | |
| git commit -m "Update wheels for release ${{ github.ref_name }}" | |
| # Force push | |
| git push origin wheels --force |