-
Notifications
You must be signed in to change notification settings - Fork 1
155 lines (134 loc) · 5.42 KB
/
Copy pathpython-publish.yml
File metadata and controls
155 lines (134 loc) · 5.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#.github/workflows/python-publish.yml
name: Build and Publish Python Package
# Workflow Triggers:
# 1. On push to any branch (e.g., main, feature/xyz): triggers build.
# 2. On push of tags starting with 'v' (e.g., v1.2.3): triggers build and publish.
# 3. On pull request to main branch: triggers build.
# 4. Manual trigger via GitHub Actions UI.
on:
push:
tags:
- 'v*'
workflow_dispatch:
jobs:
# --- Job 1: Build Cross-Platform Wheels ---
# This job runs on all triggers and builds binary wheels for multiple platforms.
build_wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
arch: x86_64
name: "Linux x86_64"
- os: ubuntu-24.04-arm # ARM64 Linux
arch: aarch64
name: "Linux ARM64"
- os: macos-15-intel # Intel Mac (x86_64)
arch: "x86_64" # Build only x86_64
name: "macOS Intel"
- os: macos-14 # M1/M2 Mac (ARM64)
arch: "arm64" # Build only arm64
name: "macOS Silicon"
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: 'recursive'
fetch-depth: 0
- name: Export Compiler Paths (macOS)
if: runner.os == 'macOS'
run: |
GMP=$(brew --prefix gmp)
MPFR=$(brew --prefix mpfr)
if [[ "${{ matrix.os }}" == "macos-14" ]]; then
echo "CIBW_ENVIRONMENT_MACOS=MACOSX_DEPLOYMENT_TARGET=14.0 CFLAGS=\"-I$GMP/include -I$MPFR/include\" LDFLAGS=\"-L$GMP/lib -Wl,-rpath,$GMP/lib -L$MPFR/lib -Wl,-rpath,$MPFR/lib\" CMAKE_PREFIX_PATH=\"$GMP;$MPFR\"" >> $GITHUB_ENV
else
echo "CIBW_ENVIRONMENT_MACOS=MACOSX_DEPLOYMENT_TARGET=15.0 CFLAGS=\"-I$GMP/include -I$MPFR/include\" LDFLAGS=\"-L$GMP/lib -Wl,-rpath,$GMP/lib -L$MPFR/lib -Wl,-rpath,$MPFR/lib\" CMAKE_PREFIX_PATH=\"$GMP;$MPFR\"" >> $GITHUB_ENV
fi
- name: Build wheels
uses: pypa/cibuildwheel@v3.3.1
env:
CIBW_ARCHS: ${{ matrix.arch }}
CIBW_TEST_REQUIRES: pytest
CIBW_BEFORE_TEST: "pip install \".[dev]\""
CIBW_TEST_COMMAND: pytest -n auto -k "not (Feynman or MQT)" {project}/test
- name: Upload wheel artifacts (for all builds - general purpose)
uses: actions/upload-artifact@v4
with:
name: all-builds-dist-wheels-${{ matrix.os }}
path: ./wheelhouse/*.whl
- name: Upload wheel artifacts (for PyPI release - only on tags)
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
uses: actions/upload-artifact@v4
with:
name: pypi-release-wheels-${{ matrix.os }}
path: ./wheelhouse/*.whl
# --- Job 2: Build Source Distribution (Sdist) ---
# This job runs on all triggers and builds the source distribution.
build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: 'recursive'
fetch-depth: 0
- name: Install build tool
run: pip install build maturin
- name: Clean up existing dist directory
run: rm -rf dist/
- name: Build sdist with build module
run: python -m build --sdist
- name: Upload sdist artifact (for all builds - general purpose)
uses: actions/upload-artifact@v4
with:
name: all-builds-dist-sdist
path: dist/*.tar.gz
- name: Upload sdist artifact (for PyPI release - only on tags)
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
uses: actions/upload-artifact@v4
with:
name: pypi-release-sdist
path: dist/*.tar.gz
# --- Job 3: Publish to PyPI and Create GitHub Release ---
# This job runs only when a 'v*' tag is pushed.
# It publishes all built artifacts to PyPI and creates a GitHub Release.
publish:
name: Publish to PyPI and Create Release
# 'needs' ensures this job runs only after all build jobs succeed.
needs: [build_wheels, build_sdist]
# Condition: Only run when a 'v*' tag is pushed.
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
# Uses PyPI Trusted Publishing (OIDC) for secure publishing.
permissions:
# id-token: write is required for OIDC Trusted Publishing.
id-token: write
# contents: write is required to create a GitHub Release.
contents: write
steps:
- name: Download all release artifacts
uses: actions/download-artifact@v4
with:
pattern: pypi-release-*
path: dist
merge-multiple: true
- name: List files in dist directory (for debugging)
run: ls -R dist
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: Release ${{ github.ref_name }}
body: |
## 🚀 Release Notes
* **📦 Version:** `${{ github.ref_name }}`
* **🔗 PyPI Link:** https://pypi.org/project/QuPRS/${{ github.ref_name }}
* 🛠️ This release was automatically generated by GitHub Actions.
files: dist/*