Skip to content

Commit d6d71bc

Browse files
chore(python): workflow for python package
1 parent 92890f0 commit d6d71bc

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Build and Publish Python Package
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: "Version to use for the Python package (e.g. 0.9.9)"
8+
required: true
9+
type: string
10+
release:
11+
types: [published]
12+
13+
jobs:
14+
build-and-publish:
15+
runs-on: ${{ matrix.os }}
16+
permissions:
17+
id-token: write # mandatory for Pypi trusted publishing
18+
strategy:
19+
matrix:
20+
include:
21+
- os: ubuntu-latest
22+
platform: linux
23+
python-version: "3.10"
24+
arch: x86_64
25+
plat_name: manylinux2014_x86_64
26+
- os: ubuntu-latest
27+
platform: linux
28+
python-version: "3.10"
29+
arch: arm64
30+
plat_name: manylinux2014_aarch64
31+
- os: ubuntu-latest
32+
platform: windows
33+
python-version: "3.10"
34+
arch: x86_64
35+
plat_name: win_amd64
36+
- os: ubuntu-latest
37+
platform: macos
38+
python-version: "3.10"
39+
arch: x86_64
40+
plat_name: macosx_10_9_x86_64
41+
- os: ubuntu-latest
42+
platform: macos
43+
python-version: "3.10"
44+
arch: arm64
45+
plat_name: macosx_11_0_arm64
46+
defaults:
47+
run:
48+
shell: bash
49+
steps:
50+
- uses: actions/checkout@v4
51+
with:
52+
submodules: false
53+
54+
- name: Set up Python
55+
uses: actions/setup-python@v5
56+
with:
57+
python-version: ${{ matrix.python-version }}
58+
59+
- name: Install build dependencies
60+
run: |
61+
cd packages/python
62+
python3 -m pip install --upgrade pip
63+
python3 -m pip install -r requirements-dev.txt
64+
65+
- name: Get version
66+
id: get_version
67+
run: |
68+
if [[ "${{ github.event_name }}" == "release" ]]; then
69+
VERSION="${{ github.event.release.tag_name }}"
70+
else
71+
VERSION="${{ github.event.inputs.version }}"
72+
fi
73+
VERSION=${VERSION#v}
74+
echo "version=$VERSION" >> $GITHUB_OUTPUT
75+
76+
- name: Download artifacts for current platform
77+
run: |
78+
cd packages/python
79+
python3 download_artifacts.py "${{ matrix.plat_name }}" "${{ steps.get_version.outputs.version }}"
80+
81+
- name: Build wheel
82+
env:
83+
PACKAGE_VERSION: ${{ steps.get_version.outputs.version }}
84+
run: |
85+
cd packages/python
86+
python setup.py bdist_wheel --plat-name "${{ matrix.plat_name }}"
87+
88+
- name: Publish to PyPI
89+
uses: pypa/gh-action-pypi-publish@release/v1
90+
with:
91+
packages-dir: packages/python/dist
92+
verbose: true
93+
# Avoid workflow to fail if the version has already been published
94+
skip-existing: true
95+
# Upload to Test Pypi for testing
96+
repository-url: https://test.pypi.org/legacy/

0 commit comments

Comments
 (0)