minify-html/.github/workflows/python.yml

102 lines
3.7 KiB
YAML
Raw Normal View History

name: Build and publish Python package
on:
2021-08-05 22:22:24 -04:00
push:
tags:
- 'v*'
2021-08-05 22:22:24 -04:00
workflow_dispatch:
jobs:
build:
2021-08-07 11:48:52 -04:00
runs-on: ${{ matrix.os }}
strategy:
matrix:
2022-06-21 22:24:15 -04:00
variant: [main, onepass]
os: [macos-11.0, ubuntu-18.04, windows-2019, self-hosted-linux-arm64, self-hosted-macos-arm64]
python: [3.8, 3.9, '3.10']
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'
uses: actions/setup-python@v1
with:
2020-01-20 05:55:17 -05:00
python-version: ${{ matrix.python }}
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
- name: Set up Rust
if: runner.name != 'macos-arm64'
uses: actions-rs/toolchain@v1
with:
2020-07-03 03:34:57 -04:00
toolchain: stable
profile: minimal
default: true
2020-07-11 10:47:17 -04:00
- name: Run prebuild steps
shell: bash
run: bash ./prebuild.sh
2020-07-11 10:47:17 -04: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'
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'
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
- 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 }}
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
# For idempotency, ignore any existing built wheels that have already been successfully uploaded.
twine upload --skip-existing target/wheels/*
else
ls -al target/wheels/*
2020-06-18 21:44:54 -04:00
fi