-
Notifications
You must be signed in to change notification settings - Fork 42
79 lines (73 loc) · 3.5 KB
/
python.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
name: Build and publish Python package
on:
push:
tags:
- 'v*'
workflow_dispatch:
# How cross compilation works with PyO3/maturin-action:
# - For Linux targets, it uses Docker.
# - For other targets, it runs on the host (Docker mostly only supports Linux containers).
# - Even if targeting another platform (e.g. Windows from Linux) was possible, this is likely problematic and suboptimal:
# - Working with libraries and headers for another OS is likely very tricky.
# - Usually the host compilers (e.g. Xcode on macOS, MSVC on Windows) are the most optimal in terms of correctness and performance.
# - It may be against Apple's terms to build macOS binaries from other platforms.
# - On Windows, the action appears to just use the host binary. Cross compilation to a different arch doesn't seem to be yet supported.
# - On macOS, the action appears to be able to target aarch64 just fine despite running on an Intel Mac.
# - We don't need to set up Rust, the action will do so itself.
# - We don't need to set up Python:
# - On macOS, the action auto finds all versions: https://github.com/PyO3/maturin-action/blob/a3013db91b2ef2e51420cfe99ee619c8e72a17e6/src/index.ts#L732
# - On Linux, a Docker container is used which has its own Rust, Python, etc.
# - On Windows, we use the "generate-import-lib" feature on pyo3: https://www.maturin.rs/distribution#cross-compile-to-windows
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-11.0, windows-2019]
variant: ['', '-onepass']
target: [x86_64, aarch64]
python: ['3.8', '3.9', '3.10', '3.11', '3.12']
exclude:
# Building for Windows aarch64 isn't ready yet.
- os: windows-2019
target: aarch64
steps:
- uses: actions/checkout@v1
- name: Patches
shell: bash
run: |
# Maturin uses Cargo.toml name for Python name: https://www.maturin.rs/#usage.
# We edit it here instead of just updating our repo code as Cargo workspace names must be different.
newName=minify-html${{ matrix.variant }}
newName=${newName//-/_}
sed -i.bak 's%^name = ".*$%name = "'$newName'"%' ./minify-html${{ matrix.variant }}-python/Cargo.toml
rm ./minify-html${{ matrix.variant }}-python/Cargo.toml.bak
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
manylinux: auto
# https://github.com/PyO3/maturin-action/issues/49#issuecomment-1166242843
args: --release --sdist --strip -m ./minify-html${{ matrix.variant }}-python/Cargo.toml -i ${{ matrix.python }}
sccache: true
- name: Install Python build tools (macOS)
if: runner.os == 'macOS'
run: sudo pip install --upgrade twine
- name: Install Python build tools (Linux, Windows)
if: runner.os != 'macOS'
run: pip install --upgrade twine
- name: Pack and publish package
shell: bash
working-directory: ./minify-html${{ matrix.variant }}-python
run: |
cat << 'EOF' > "$HOME/.pypirc"
[pypi]
username = __token__
password = ${{ secrets.PYPI_API_TOKEN }}
EOF
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
# For idempotency, ignore any existing built wheels that have already been successfully uploaded.
twine upload --skip-existing ../target/wheels/*
else
ls -al ../target/wheels/*
fi