Skip to content

Merge pull request #236 from dimagi/dm/auto-pypi #1

Merge pull request #236 from dimagi/dm/auto-pypi

Merge pull request #236 from dimagi/dm/auto-pypi #1

Workflow file for this run

name: Build wheels and publish to PyPI
on:
push:
branches:
- master
tags:
- "v*"
workflow_dispatch:
jobs:
configure:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Read Python versions from pyproject.toml
id: read-versions
# produces output like: python_versions=39,310,311,312,313
run: >-
echo "python_versions=$(
grep -oP '(?<=Language :: Python :: )\d.\d+' pyproject.toml
| sed 's/\.//'
| tr '\n' ','
| sed 's/,$//'
)" >> $GITHUB_OUTPUT
outputs:
python_versions: ${{ steps.read-versions.outputs.python_versions }}
build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check version
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
run: python version.py check "${{ github.ref }}"
- name: Add untagged version suffix
if: ${{ ! startsWith(github.ref, 'refs/tags/v') }}
run: python version.py update
- name: Build sdist
run: pipx run build --sdist
- uses: actions/upload-artifact@v4
with:
name: sdist
path: dist
choose_linux_wheel_types:
name: Decide which wheel types to build
runs-on: ubuntu-latest
steps:
- id: manylinux_x86_64
run: echo "wheel_types=manylinux_x86_64" >> $GITHUB_OUTPUT
- id: musllinux_x86_64
run: echo "wheel_types=musllinux_x86_64" >> $GITHUB_OUTPUT
outputs:
wheel_types: ${{ toJSON(steps.*.outputs.wheel_types) }}
build_linux_wheels:
needs: [configure, choose_linux_wheel_types, build_sdist]
name: ${{ matrix.wheel_type }} wheels
runs-on: ubuntu-latest
strategy:
matrix:
wheel_type: ${{ fromJSON(needs.choose_linux_wheel_types.outputs.wheel_types) }}
steps:
- uses: actions/download-artifact@v4
with:
name: sdist
path: dist
- name: Extract sdist
run: |
tar zxvf dist/*.tar.gz --strip-components=1
- uses: docker/setup-qemu-action@v3
if: runner.os == 'Linux'
name: Set up QEMU
- name: Build wheels
uses: pypa/[email protected]
env:
CIBW_BUILD: cp{${{ needs.configure.outputs.python_versions }}}-${{ matrix.wheel_type }}
CIBW_ARCHS_LINUX: auto
CIBW_BEFORE_BUILD: cd {project}; pip install -e . # is there a better way to build the .so files?
CIBW_TEST_COMMAND: cd {project}; python -m unittest
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.wheel_type }}-wheels
path: ./wheelhouse/*.whl
pypi-publish:
name: Upload release to PyPI
needs: [build_sdist, build_linux_wheels]
runs-on: ubuntu-latest
#if: startsWith(github.ref, 'refs/tags/v') # removed until pypi-test-publish is working
environment:
name: pypi
url: https://pypi.org/p/jsonobject
permissions:
id-token: write
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
# with no name set, it downloads all of the artifacts
path: dist/
- run: |
mv dist/sdist/*.tar.gz dist/
mv dist/*-wheels/*.whl dist/
rmdir dist/{sdist,*-wheels}
ls -R dist
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
# https://github.com/finpassbr/json-object/issues/1
#pypi-test-publish:
# name: Upload release to test PyPI
# needs: [build_sdist, build_linux_wheels]
# runs-on: ubuntu-latest
# environment:
# name: testpypi
# url: https://test.pypi.org/p/jsonobject
# permissions:
# id-token: write
# steps:
# - name: Download all the dists
# uses: actions/download-artifact@v4
# with:
# # with no name set, it downloads all of the artifacts
# path: dist/
# - run: |
# mv dist/sdist/*.tar.gz dist/
# mv dist/*-wheels/*.whl dist/
# rmdir dist/{sdist,*-wheels}
# ls -R dist
# - name: Publish package distributions to PyPI
# uses: pypa/gh-action-pypi-publish@release/v1
# with:
# repository-url: https://test.pypi.org/legacy/