Fix publish pipeline: use workflow_call, manylinux tags, add changelo… #8
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 to PyPI | ||
| on: | ||
| workflow_call: | ||
| permissions: | ||
| contents: write | ||
| jobs: | ||
| build-wheels: | ||
| strategy: | ||
| matrix: | ||
| include: | ||
| - os: ubuntu-latest | ||
| target: x86_64-unknown-linux-gnu | ||
| - os: macos-14 | ||
| target: aarch64-apple-darwin | ||
| runs-on: ${{ matrix.os }} | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Install Rust | ||
| uses: dtolnay/rust-toolchain@stable | ||
| with: | ||
| targets: ${{ matrix.target }} | ||
| - name: Build Rust binary | ||
| run: cargo build --release --target ${{ matrix.target }} | ||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.12" | ||
| - name: Install build tools | ||
| run: pip install build wheel | ||
| - name: Stage binary and parameters into package | ||
| run: | | ||
| mkdir -p policyengine_uk_compiled/bin | ||
| cp target/${{ matrix.target }}/release/policyengine-uk-rust policyengine_uk_compiled/bin/ | ||
| chmod +x policyengine_uk_compiled/bin/policyengine-uk-rust | ||
| cp -r parameters policyengine_uk_compiled/parameters | ||
| - name: Build wheel | ||
| run: python -m build --wheel | ||
| - name: Retag Linux wheel as manylinux | ||
| if: runner.os == 'Linux' | ||
| run: | | ||
| pip install wheel | ||
| for whl in dist/*.whl; do | ||
| python -c " | ||
| import pathlib, re | ||
| p = pathlib.Path('$whl') | ||
| new = re.sub(r'linux_x86_64', 'manylinux_2_17_x86_64.manylinux2014_x86_64', p.name) | ||
| if new != p.name: | ||
| p.rename(p.parent / new) | ||
| print(f'Renamed to {new}') | ||
| " | ||
| done | ||
| - uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: wheel-${{ matrix.target }} | ||
| path: dist/*.whl | ||
| publish: | ||
| needs: build-wheels | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.12" | ||
| - name: Publish git tag | ||
| run: bash .github/publish-git-tag.sh | ||
| - uses: actions/download-artifact@v4 | ||
| with: | ||
| path: dist | ||
| merge-multiple: true | ||
| - name: List wheels | ||
| run: ls -la dist/ | ||
| - name: Publish to PyPI | ||
| uses: pypa/gh-action-pypi-publish@release/v1 | ||
| with: | ||
| user: __token__ | ||
| password: ${{ secrets.PYPI }} | ||
| packages-dir: dist/ | ||
| skip-existing: true | ||