Skip to content

Commit 6f82698

Browse files
ci: copy the publish-python.yml workflow from C++ jsonnet
1 parent 63ffeb8 commit 6f82698

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed

.github/workflows/publish-python.yml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
name: Build and Publish Python Package
2+
3+
# Be very careful granting extra permissions here, as this workflow uses third party actions.
4+
# Prefer to pin to exact commits for third-party actions. I'm making an exception for actions
5+
# maintained by GitHub itself.
6+
7+
# For now, just trigger this workflow manually.
8+
on:
9+
workflow_dispatch:
10+
inputs:
11+
upload_to_pypi:
12+
description: "Upload generate package files to PyPI"
13+
required: true
14+
type: boolean
15+
pypi_environment:
16+
description: "Which PyPI instance to publish to"
17+
required: true
18+
type: choice
19+
options:
20+
- testpypi
21+
- pypi
22+
23+
jobs:
24+
build_sdist:
25+
name: Build Python sdist
26+
runs-on: ubuntu-24.04
27+
permissions:
28+
contents: read
29+
30+
steps:
31+
- uses: actions/checkout@v4
32+
33+
- uses: actions/setup-python@v5
34+
with:
35+
python-version: "3.13"
36+
cache: "pip"
37+
38+
- run: pip install 'build==1.2.2'
39+
40+
- name: Build sdist
41+
run: python3 -m build --sdist
42+
43+
- uses: actions/upload-artifact@v4
44+
with:
45+
name: sdist
46+
path: ./dist/*.gz
47+
if-no-files-found: error
48+
49+
build_wheels:
50+
name: Build wheels on ${{ matrix.os }}
51+
runs-on: ${{ matrix.os }}
52+
strategy:
53+
matrix:
54+
#os: [ubuntu-22.04, windows-latest, macos-latest]
55+
os: [ubuntu-22.04, windows-latest]
56+
57+
permissions:
58+
contents: read
59+
60+
steps:
61+
- uses: actions/checkout@v4
62+
63+
- name: Build wheels
64+
uses: pypa/cibuildwheel@ee63bf16da6cddfb925f542f2c7b59ad50e93969 # v2.22.0
65+
env:
66+
# Skip PyPy, 32-bit Windows, 32-bit Linux, and CPython before 3.9.
67+
# See https://cibuildwheel.readthedocs.io/en/stable/options/#examples_1
68+
CIBW_SKIP: "*-win32 pp* *-manylinux_i686 *-musllinux_i686 cp36-* cp37-* cp38-*"
69+
CIBW_TEST_COMMAND: >
70+
python {package}/python/_jsonnet_test.py
71+
72+
- uses: actions/upload-artifact@v4
73+
with:
74+
name: cibw-wheels-${{ matrix.os }}
75+
path: ./wheelhouse/*.whl
76+
if-no-files-found: error
77+
78+
upload_to_pypi:
79+
name: "Upload packages to PyPI"
80+
needs: [build_sdist, build_wheels]
81+
runs-on: ubuntu-24.04
82+
if: "${{ inputs.upload_to_pypi }}"
83+
permissions:
84+
contents: read
85+
id-token: write # Needed for PyPI Trusted Publishing
86+
environment:
87+
name: "${{ inputs.pypi_environment }}"
88+
url: "${{ inputs.pypi_environment == 'pypi' && 'https://pypi.org/p/gosonnet' || 'https://test.pypi.org/p/gosonnet' }}"
89+
steps:
90+
- uses: actions/download-artifact@v4
91+
with:
92+
path: cibw-wheels
93+
pattern: cibw-wheels-*
94+
- uses: actions/download-artifact@v4
95+
with:
96+
path: sdist
97+
name: sdist
98+
- name: Flatten wheels to one directory
99+
run: |
100+
mkdir dist
101+
find cibw-wheels/ -type f -name '*.whl' -exec mv '{}' ./dist/ ';'
102+
find sdist/ -type f -name '*.gz' -exec mv '{}' ./dist/ ';'
103+
- name: Publish to PyPI
104+
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4
105+
with:
106+
verbose: true
107+
print-hash: true
108+
repository-url: "${{ inputs.pypi_environment == 'testpypi' && 'https://test.pypi.org/legacy/' || '' }}"

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["setuptools"]
3+
build-backend = "setuptools.build_meta"

0 commit comments

Comments
 (0)