Skip to content

GH

GH #89

Workflow file for this run

name: GH
on:
pull_request:
push:
branches: master
release:
types: [released, prereleased]
workflow_dispatch: # allows running workflow manually from the Actions tab
jobs:
build-sdist:
runs-on: ubuntu-latest
env:
PIP_DISABLE_PIP_VERSION_CHECK: 1
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- run: sudo apt-get install -y libmagic1
- name: Build source distribution
run: |
pip install -U setuptools wheel pip
python setup.py sdist
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist/*.tar.*
build-wheels-matrix:
runs-on: ubuntu-latest
outputs:
include: ${{ steps.set-matrix.outputs.include }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- run: pip install cibuildwheel==2.16.2 # sync version with pypa/cibuildwheel below
- id: set-matrix
env:
CIBW_PROJECT_REQUIRES_PYTHON: '==3.11.*'
run: |
MATRIX_INCLUDE=$(
{
cibuildwheel --print-build-identifiers --platform linux --arch x86_64,aarch64,i686 | grep cp | jq -nRc '{"only": inputs, "os": "ubuntu-latest"}' \
&& cibuildwheel --print-build-identifiers --platform macos --arch x86_64,arm64 | grep cp | jq -nRc '{"only": inputs, "os": "macos-11"}' \
&& cibuildwheel --print-build-identifiers --platform windows --arch x86,AMD64 | grep cp | jq -nRc '{"only": inputs, "os": "windows-latest"}'
} | jq -sc
)
echo "include=$MATRIX_INCLUDE" >> $GITHUB_OUTPUT
build-wheels:
name: Build ${{ matrix.only }}
needs: build-wheels-matrix
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include: ${{ fromJson(needs.build-wheels-matrix.outputs.include) }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up QEMU
if: runner.os == 'Linux'
uses: docker/setup-qemu-action@v3
- uses: pypa/[email protected] # sync version with pip install cibuildwheel above
timeout-minutes: 10
with:
only: ${{ matrix.only }}
env:
CIBW_BUILD_VERBOSITY: 1
CIBW_BEFORE_BUILD: bash -c "make install_libmagic"
CIBW_TEST_COMMAND: python -c "import magic; assert magic.Magic(mime=True).from_buffer(b'\x00\x00\x00\x1cftypisom\x00\x00\x02\x00isomiso2mp41\x00') == 'video/mp4'"
- uses: actions/upload-artifact@v4
with:
name: dist
path: wheelhouse/*.whl
publish:
if: github.event_name == 'release'
needs: [build-sdist, build-wheels]
runs-on: ubuntu-latest
permissions:
contents: write # softprops/action-gh-release
id-token: write # pypa/gh-action-pypi-publish
steps:
- uses: actions/setup-python@v5
with:
python-version: 3.x
- uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- run: ls -ltra dist/
- run: pip install -U python-magic --find-links ./dist
- name: Smoketest
run: python -c "import magic; magic.Magic()"
- name: Upload release assets
uses: softprops/[email protected]
with:
files: dist/*
- name: Publish package distributions to PyPI
uses: pypa/[email protected]