Skip to content

Build and Publish Python Package #4

Build and Publish Python Package

Build and Publish Python Package #4

name: Build Python Wheel
# For now, just trigger this workflow manually.
on:
workflow_dispatch:
inputs:
upload_to_pypi:
description: "Upload wheels to PyPI"
required: true
type: boolean
use_test_pypi:
description: "Use https://test.pypi.org/"
required: false
type: boolean
jobs:
build_wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
#os: [ubuntu-20.04, windows-latest, macos-latest]
os: [ubuntu-20.04, windows-latest]
# We're using third party actions (not just the official GitHub-maintained actions),
# so it's very important to minimise the ability for this workflow to do anything dangerous.
# Grant it only read access to the repository content (which is public anyway); it shouldn't
# need anything else.
# Be very careful granting extra permissions here, as this workflow uses third party actions.
# Prefer to pin to exact commits for third-party actions. I'm making an exception for actions
# maintained by GitHub itself.
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Build wheels
uses: pypa/cibuildwheel@ee63bf16da6cddfb925f542f2c7b59ad50e93969 # v2.22.0
env:
# Skip PyPy, 32-bit Windows, 32-bit Linux, and CPython before 3.9.
# See https://cibuildwheel.readthedocs.io/en/stable/options/#examples_1
CIBW_SKIP: "*-win32 pp* *-manylinux_i686 *-musllinux_i686 cp36-* cp37-* cp38-*"
CIBW_TEST_COMMAND: >
python {package}/python/_jsonnet_test.py
- uses: actions/upload-artifact@v4
with:
name: cibw-wheels-${{ matrix.os }}
path: ./wheelhouse/*.whl
if-no-files-found: error
upload_to_pypi:
name: Upload wheels to TEST PyPI
needs: build_wheels
runs-on: ubuntu-24.04
if: "${{ inputs.upload_to_pypi && inputs.use_test_pypi }}"
permissions:
contents: read
id-token: write # Needed for PyPI Trusted Publishing
environment:
name: testpypi
url: https://test.pypi.org/p/jpab-test-jsonnet
steps:
- uses: actions/download-artifact@v4
with:
path: cibw-wheels
pattern: cibw-wheels-*
- name: Experiment
run: |
echo "Hello, world!"
ls -lR cibw-wheels/
# - name: Publish
# uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4
# with:
# print-hash: true
# repository-url: https://test.pypi.org/legacy/