2020-01-20 03:42:45 -05:00
name : Build and publish Python package
2020-01-19 00:50:21 -05:00
on :
2021-08-05 22:22:24 -04:00
push :
2020-01-19 00:50:21 -05:00
tags :
- 'v*'
2021-08-05 22:22:24 -04:00
workflow_dispatch :
2020-01-19 00:50:21 -05:00
jobs :
2020-01-20 03:42:45 -05:00
build :
2021-08-07 11:48:52 -04:00
runs-on : ${{ matrix.os }}
2020-01-19 00:50:21 -05:00
strategy :
matrix :
2022-06-21 22:24:15 -04:00
variant : [ main, onepass]
2021-11-12 00:20:50 -05:00
os : [ macos-11.0, ubuntu-18.04, windows-2019, self-hosted-linux-arm64, self-hosted-macos-arm64]
2021-11-12 00:34:59 -05:00
python : [ 3.8 , 3.9 , '3.10' ]
2020-01-19 00:50:21 -05:00
steps :
- uses : actions/checkout@v1
2021-11-11 23:57:08 -05:00
- name : Set up Python (x64)
2021-11-12 00:04:15 -05:00
if : runner.name != 'linux-arm64' && runner.name != 'macos-arm64'
2020-01-19 00:50:21 -05:00
uses : actions/setup-python@v1
with :
2020-01-20 05:55:17 -05:00
python-version : ${{ matrix.python }}
2020-01-19 00:50:21 -05:00
architecture : 'x64'
2021-11-11 23:57:08 -05:00
- name : Set up Python (Linux ARM64)
2021-11-12 00:04:15 -05:00
if : runner.name == 'linux-arm64'
2021-11-11 23:57:08 -05:00
run : |
2021-11-12 00:09:36 -05:00
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
2021-11-11 23:57:08 -05:00
pyenv install -s ${{ matrix.python }}:latest
pyenv global $(pyenv versions --bare | grep -F '${{ matrix.python }}.')
2021-11-12 00:04:15 -05:00
- name : Set up Python (macOS ARM64)
if : runner.name == 'macos-arm64'
run : |
brew unlink python
brew link python@${{ matrix.python }}
2020-07-11 10:47:17 -04:00
2020-07-22 07:52:54 -04:00
- name : Set up Rust
2021-11-12 00:20:50 -05:00
if : runner.name != 'macos-arm64'
2020-01-19 00:50:21 -05:00
uses : actions-rs/toolchain@v1
with :
2020-07-03 03:34:57 -04:00
toolchain : stable
2020-01-19 00:50:21 -05:00
profile : minimal
default : true
2020-07-11 10:47:17 -04:00
2020-07-11 09:25:36 -04:00
- name : Run prebuild steps
shell : bash
run : bash ./prebuild.sh
2020-07-11 10:47:17 -04:00
2020-01-19 00:50:21 -05:00
- name : Build native module
2022-06-21 22:24:15 -04:00
working-directory : ./python/${{ matrix.feature }}
2022-06-21 07:52:28 -04:00
run : cargo build --release
2020-07-11 10:47:17 -04:00
2021-11-12 00:17:23 -05:00
- name : Install Python build tools (macOS x64)
if : runner.os == 'macOS' && runner.name != 'macos-arm64'
2021-11-11 23:43:00 -05:00
run : sudo pip install --upgrade maturin setuptools wheel twine
2021-11-12 00:17:23 -05:00
- name : Install Python build tools (Linux x64, Windows x64)
if : runner.os != 'macOS' && runner.name != 'linux-arm64'
2021-11-11 23:43:00 -05:00
run : pip install --upgrade maturin setuptools wheel twine
2021-11-12 00:17:23 -05:00
- name : Install Python build tools (Linux ARM64)
if : runner.name == 'linux-arm64'
run : |
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
pip3 install --upgrade maturin setuptools wheel twine
- name : Install Python build tools (macOS ARM64)
if : runner.name == 'macos-arm64'
2021-11-12 00:43:59 -05:00
run : /opt/homebrew/bin/pip3 install --upgrade maturin setuptools wheel twine
2020-07-11 10:47:17 -04:00
2020-01-20 03:42:45 -05:00
- name : Pack and publish package
2020-07-11 10:47:17 -04:00
shell : bash
2022-06-21 22:24:15 -04:00
working-directory : ./python/${{ matrix.feature }}
2020-01-20 03:42:45 -05:00
run : |
cat << 'EOF' > "$HOME/.pypirc"
[ pypi]
username = __token__
password = ${{ secrets.PYPI_API_TOKEN }}
EOF
2021-11-12 00:09:36 -05:00
if [[ "${{ runner.name }}" == linux-arm64 ]]; then
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
fi
2021-11-12 00:27:52 -05:00
if [[ "${{ runner.name }}" == macos-arm64 ]]; then
2021-11-12 00:39:59 -05:00
pathToPython="/opt/homebrew/bin/python3"
2021-11-12 00:59:28 -05:00
# Ensure correct maturin and twine are used.
export PATH="/opt/homebrew/bin:$PATH"
2021-11-12 00:27:52 -05:00
else
pathToPython="$(which python)"
fi
2022-06-21 07:52:28 -04:00
# On macOS ARM64 this may emit a warning like "Couldn't find the symbol `PyInit_minify_html` in the native library. Python will fail to import this module." Ignore this message.
2021-11-12 00:27:52 -05:00
maturin build --release --strip -i "$pathToPython"
2020-07-11 10:47:17 -04:00
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
2022-06-17 04:01:13 -04:00
# For idempotency, ignore any existing built wheels that have already been successfully uploaded.
twine upload --skip-existing target/wheels/*
2021-11-11 23:43:00 -05:00
else
ls -al target/wheels/*
2020-06-18 21:44:54 -04:00
fi