Skip to content

Workflow file for this run

name: Build distributions and upload to PyPI
# Build on every branch push, tag push, and pull request change:
on: [push, pull_request]
jobs:
calculate_wheels_to_build:
name: Calculate OS/archs to build wheels on
runs-on: ubuntu-20.04
env:
ARCHS_LINUX_BASE: '["x86_64"]'
ARCHS_LINUX_ON_TAGS: '["x86_64", "i686", "aarch64"]'
ARCHS_MACOS_BASE: '["x86_64"]'
ARCHS_MACOS_ON_TAGS: '["x86_64", "arm64", "universal2"]'
ARCHS_WINDOWS_BASE: '["AMD64"]'
ARCHS_WINDOWS_ON_TAGS: '["AMD64", "x86"]'
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Calculate strategy matrix
shell: python
id: set-matrix
env:
ARCHS_LINUX: ${{ startsWith(github.event.ref, 'refs/tags/v') && env.ARCHS_LINUX_BASE || env.ARCHS_LINUX_ON_TAGS }}
ARCHS_MACOS: ${{ startsWith(github.event.ref, 'refs/tags/v') && env.ARCHS_MACOS_BASE || env.ARCHS_MACOS_ON_TAGS }}
ARCHS_WINDOWS: ${{ startsWith(github.event.ref, 'refs/tags/v') && env.ARCHS_WINDOWS_BASE || env.ARCHS_WINDOWS_ON_TAGS }}
run: |
import json
import os
combinations = (
("ubuntu-20.04", "ARCHS_LINUX"),
("macos-12", "ARCHS_MACOS"),
("windows-2019", "ARCHS_WINDOWS"),
)
includes = [
{"os": os_name, "arch": arch}
for os_name, archs_envvar in combinations
for arch in json.loads(os.getenv(archs_envvar))
]
matrix = {"includes": includes}
with open(os.getenv("GITHUB_OUTPUT"), "at") as github_output:
github_output.write(f'matrix={json.dumps(matrix)}')
print(f"Calculated matrix strategy:\n{json.dumps(matrix)}")
build_wheels:
name: Build wheels on ${{matrix.arch}} for ${{ matrix.os }}
needs: calculate_wheels_to_build
runs-on: ${{ matrix.os }}
strategy:
matrix: ${{ fromJson(needs.calculate_wheels_to_build.outputs.matrix) }}
env:
CIBW_ARCHS: ${{ matrix.arch }}
steps:
- uses: actions/checkout@v3
with:
submodules: true
- uses: actions/setup-python@v4
name: Install Python
with:
python-version: '3.12'
- uses: docker/setup-qemu-action@v1
if: ${{ matrix.arch == 'aarch64' && matrix.os == 'linux' }}
name: Set up QEMU
- name: Install cibuildwheel
run: |
python -m pip install cibuildwheel
- name: Build wheels
run: |
python -m cibuildwheel --output-dir wheelhouse
env:
CIBW_BEFORE_ALL: "bash -c 'cd \"{project}\"; sh .github/tools/install_yajl.sh'"
CIBW_BUILD_VERBOSITY: 1
CIBW_ENVIRONMENT_MACOS: "IJSON_EMBED_YAJL=1"
CIBW_ENVIRONMENT_WINDOWS: "IJSON_EMBED_YAJL=1"
CIBW_TEST_COMMAND: "bash -c 'cd \"{project}\"; pytest -vv'"
CIBW_TEST_REQUIRES: pytest cffi
- uses: actions/upload-artifact@v3
with:
path: ./wheelhouse/*.whl
build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
name: Install Python
with:
python-version: '3.12'
- name: Install setuptools
run: pip install setuptools
- name: Build sdist
run: python setup.py sdist
- uses: actions/upload-artifact@v3
with:
path: dist/*.tar.gz
upload_pypi:
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
if: startsWith(github.event.ref, 'refs/tags/v')
steps:
- uses: actions/download-artifact@v3
with:
name: artifact
path: dist
- uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.pypi_password }}