v0.1.2 #6
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: Release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| defaults: | |
| run: | |
| shell: bash | |
| permissions: | |
| contents: write | |
| actions: write | |
| jobs: | |
| cleanup: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| actions: write | |
| steps: | |
| - name: Cleanup artifacts | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const artifacts = await github.paginate(github.rest.actions.listArtifactsForRepo, { | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| per_page: 100, | |
| }); | |
| const toDelete = artifacts.filter((artifact) => artifact.name.startsWith("wheels-")); | |
| for (const artifact of toDelete) { | |
| await github.rest.actions.deleteArtifact({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| artifact_id: artifact.id, | |
| }); | |
| } | |
| build: | |
| runs-on: ${{ matrix.os }} | |
| needs: cleanup | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: | |
| - ubuntu-latest | |
| - windows-latest | |
| - macos-latest | |
| python-version: | |
| - "3.13" | |
| env: | |
| PYTHONIOENCODING: "utf-8" | |
| PYTHONUTF8: "1" | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Set up Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - uses: Swatinem/rust-cache@v2 | |
| - name: Create venv (Unix) | |
| if: runner.os != 'Windows' | |
| run: | | |
| python -m venv .venv | |
| echo "PYTHON_EXEC=$PWD/.venv/bin/python" >> $GITHUB_ENV | |
| - name: Create venv (Windows) | |
| if: runner.os == 'Windows' | |
| run: | | |
| python -m venv .venv | |
| echo "PYTHON_EXEC=$(pwd)/.venv/Scripts/python.exe" >> $GITHUB_ENV | |
| - name: Install maturin | |
| run: $PYTHON_EXEC -m pip install --upgrade pip maturin setuptools wheel | |
| - name: Build wheels | |
| run: $PYTHON_EXEC -m maturin build --release --out dist | |
| - name: Repack wheels | |
| run: | | |
| $PYTHON_EXEC .github/scripts/repack_wheels.py | |
| - name: Install wheel | |
| run: $PYTHON_EXEC -m pip install dist/*.whl | |
| - name: Run Tests | |
| run: | | |
| $PYTHON_EXEC -m unittest discover tests | |
| - name: Upload wheels | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: wheels-${{ matrix.os }}-py${{ matrix.python-version }} | |
| path: dist/* | |
| retention-days: 3 | |
| release: | |
| runs-on: ubuntu-latest | |
| needs: build | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Cleanup latest release assets | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| try { | |
| const release = await github.rest.repos.getReleaseByTag({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| tag: "latest", | |
| }); | |
| const assets = release.data.assets || []; | |
| for (const asset of assets) { | |
| await github.rest.repos.deleteReleaseAsset({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| asset_id: asset.id, | |
| }); | |
| } | |
| } catch (error) { | |
| if (error.status !== 404) { | |
| throw error; | |
| } | |
| } | |
| - name: Remove latest release | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| try { | |
| const release = await github.rest.repos.getReleaseByTag({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| tag: "latest", | |
| }); | |
| await github.rest.repos.deleteRelease({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| release_id: release.data.id, | |
| }); | |
| await github.rest.git.deleteRef({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| ref: "tags/latest", | |
| }); | |
| } catch (error) { | |
| if (error.status !== 404) { | |
| throw error; | |
| } | |
| } | |
| - name: Download wheels | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: dist | |
| merge-multiple: true | |
| - name: Publish latest release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: latest | |
| name: latest | |
| generate_release_notes: true | |
| files: dist/* |