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

85 lines
2.8 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-20.04, windows-2019, self-hosted-linux-arm64]
2022-10-27 20:00:42 -04:00
python: ['3.8', '3.9', '3.10', '3.11']
steps:
- uses: actions/checkout@v1
2021-11-11 23:57:08 -05:00
- name: Set up Python (x64)
if: runner.name != 'linux-arm64'
2022-10-27 20:00:42 -04:00
uses: actions/setup-python@v4
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 }}.')
2020-07-11 10:47:17 -04:00
- name: Set up Rust
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:44:14 -04:00
working-directory: ./python/${{ matrix.variant }}
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'
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
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:44:14 -04:00
working-directory: ./python/${{ matrix.variant }}
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
2022-10-25 16:29:40 -04:00
maturin build --release --sdist --strip -i "$(which python)"
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