Skip to content

Commit 4444fdf

Browse files
LemurPwnedcursoragentCopilot
authored
Configure cibuildwheel for manual release dispatch (#116)
* Refactor CI to trigger on push and workflow_dispatch Co-authored-by: jakub.mojsiejuk <jakub.mojsiejuk@gmail.com> * Update tests/test_imports.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add shell: bash to workflow steps Co-authored-by: jakub.mojsiejuk <jakub.mojsiejuk@gmail.com> * Update setup.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Feat: Use setuptools_scm for versioning Co-authored-by: jakub.mojsiejuk <jakub.mojsiejuk@gmail.com> * Fix: Use bracket notation for workflow dispatch inputs Co-authored-by: jakub.mojsiejuk <jakub.mojsiejuk@gmail.com> * Refactor: Simplify wheel artifact naming in CI Co-authored-by: jakub.mojsiejuk <jakub.mojsiejuk@gmail.com> * Consolidate pull request workflow runs (#118) * feat: Trigger CI on PR open, sync, and reopen Co-authored-by: jakub.mojsiejuk <jakub.mojsiejuk@gmail.com> * feat: Setuptools SCM version for sdist build Co-authored-by: jakub.mojsiejuk <jakub.mojsiejuk@gmail.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 73726ce commit 4444fdf

File tree

4 files changed

+68
-14
lines changed

4 files changed

+68
-14
lines changed

.github/workflows/cibuildwheel.yml

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Build wheels with cibuildwheel
22

33
on:
4-
pull_request:
4+
push:
55
branches: [master]
66
paths:
77
- '**.cpp'
@@ -12,8 +12,8 @@ on:
1212
- 'pyproject.toml'
1313
- '**.yml'
1414

15-
pull_request_target:
16-
types: [closed]
15+
pull_request:
16+
types: [opened, synchronize, reopened]
1717
branches: [master]
1818
paths:
1919
- '**.cpp'
@@ -22,13 +22,18 @@ on:
2222
- 'setup.py'
2323
- 'setup.cfg'
2424
- 'pyproject.toml'
25+
- '**.yml'
2526

2627
workflow_dispatch:
2728
inputs:
2829
dry-run:
2930
description: 'Dry run (no actual upload to PyPI)'
3031
type: boolean
3132
default: true
33+
version:
34+
description: 'Version to release (required if not dry run, e.g., 1.2.3)'
35+
type: string
36+
required: false
3237

3338
jobs:
3439
build_wheels:
@@ -39,18 +44,33 @@ jobs:
3944
os: [ubuntu-latest, macos-latest, windows-latest]
4045
env:
4146
TWINE_USERNAME: __token__
42-
IS_DRY_RUN: ${{ !(github.event_name == 'pull_request_target' && github.event.pull_request.merged == true) }}
47+
IS_DRY_RUN: ${{ github.event_name != 'workflow_dispatch' || inputs['dry-run'] == true }}
4348

4449
steps:
4550
- uses: actions/checkout@v4
4651
with:
4752
submodules: 'true'
53+
fetch-depth: 0
54+
55+
- name: Validate version input
56+
if: github.event_name == 'workflow_dispatch' && inputs['dry-run'] == false
57+
shell: bash
58+
run: |
59+
if [ -z "${{ inputs.version }}" ]; then
60+
echo "Error: Version is required when dry-run is false"
61+
exit 1
62+
fi
4863
4964
- name: Get version
5065
id: get_version
66+
shell: bash
5167
run: |
5268
python -m pip install setuptools-scm
53-
echo "version=$(python -c "import setuptools_scm; print(setuptools_scm.get_version())")" >> $GITHUB_OUTPUT
69+
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ inputs['dry-run'] }}" = "false" ]; then
70+
echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT
71+
else
72+
echo "version=$(python -c "import setuptools_scm; print(setuptools_scm.get_version())")" >> $GITHUB_OUTPUT
73+
fi
5474
5575
- name: Set up Python
5676
uses: actions/setup-python@v5
@@ -87,6 +107,7 @@ jobs:
87107

88108
- name: Upload wheels to Test PyPI (dry run)
89109
if: env.IS_DRY_RUN == 'true'
110+
shell: bash
90111
env:
91112
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_TOKEN }}
92113
run: |
@@ -95,6 +116,7 @@ jobs:
95116

96117
- name: Upload wheels to PyPI (production)
97118
if: env.IS_DRY_RUN == 'false'
119+
shell: bash
98120
env:
99121
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
100122
run: |
@@ -103,7 +125,7 @@ jobs:
103125
- name: Upload wheels as artifacts
104126
uses: actions/upload-artifact@v4
105127
with:
106-
name: wheels-${{ matrix.os }}-${{ strategy.job-index }}
128+
name: wheels-${{ matrix.os }}
107129
path: wheelhouse/*.whl
108130
retention-days: 30
109131

@@ -112,18 +134,33 @@ jobs:
112134
runs-on: ubuntu-latest
113135
env:
114136
TWINE_USERNAME: __token__
115-
IS_DRY_RUN: ${{ !(github.event_name == 'pull_request_target' && github.event.pull_request.merged == true) }}
137+
IS_DRY_RUN: ${{ github.event_name != 'workflow_dispatch' || inputs['dry-run'] == true }}
116138

117139
steps:
118140
- uses: actions/checkout@v4
119141
with:
120142
submodules: 'true'
143+
fetch-depth: 0
144+
145+
- name: Validate version input
146+
if: github.event_name == 'workflow_dispatch' && inputs['dry-run'] == false
147+
shell: bash
148+
run: |
149+
if [ -z "${{ inputs.version }}" ]; then
150+
echo "Error: Version is required when dry-run is false"
151+
exit 1
152+
fi
121153
122154
- name: Get version
123155
id: get_version
156+
shell: bash
124157
run: |
125158
python -m pip install setuptools-scm
126-
echo "version=$(python -c "import setuptools_scm; print(setuptools_scm.get_version())")" >> $GITHUB_OUTPUT
159+
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ inputs['dry-run'] }}" = "false" ]; then
160+
echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT
161+
else
162+
echo "version=$(python -c "import setuptools_scm; print(setuptools_scm.get_version())")" >> $GITHUB_OUTPUT
163+
fi
127164
128165
- name: Set up Python
129166
uses: actions/setup-python@v5
@@ -134,6 +171,8 @@ jobs:
134171
run: |
135172
python -m pip install build
136173
python -m build --sdist
174+
env:
175+
SETUPTOOLS_SCM_PRETEND_VERSION: ${{ steps.get_version.outputs.version }}
137176

138177
- name: Install twine
139178
run: python -m pip install twine
@@ -143,6 +182,7 @@ jobs:
143182

144183
- name: Upload sdist to Test PyPI (dry run)
145184
if: env.IS_DRY_RUN == 'true'
185+
shell: bash
146186
env:
147187
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_TOKEN }}
148188
run: |
@@ -151,6 +191,7 @@ jobs:
151191

152192
- name: Upload sdist to PyPI (production)
153193
if: env.IS_DRY_RUN == 'false'
194+
shell: bash
154195
env:
155196
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
156197
run: |
@@ -166,23 +207,26 @@ jobs:
166207
release-build:
167208
name: Create GitHub Release
168209
needs: [build_wheels, build_sdist]
169-
if: (github.event_name == 'pull_request_target' && github.event.pull_request.merged == true)
210+
if: github.event_name == 'workflow_dispatch' && inputs['dry-run'] == false
170211
runs-on: ubuntu-latest
171212
steps:
172213
- uses: actions/checkout@v4
214+
with:
215+
fetch-depth: 0
173216

174217
- name: Get version
175218
id: get_version
219+
shell: bash
176220
run: |
177-
python -m pip install setuptools-scm
178-
echo "version=$(python -c "import setuptools_scm; print(setuptools_scm.get_version())")" >> $GITHUB_OUTPUT
221+
echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT
179222
180223
- name: Download all artifacts
181224
uses: actions/download-artifact@v4
182225
with:
183226
path: artifacts
184227

185228
- name: Create release
229+
shell: bash
186230
env:
187231
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
188232
run: |

.github/workflows/python-test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ on:
1515
- tests/*.py
1616

1717
pull_request:
18+
types: [opened, synchronize, reopened]
1819
branches: [ "master" ]
1920
paths-ignore:
2021
- '**.yaml'

setup.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,25 @@
22
Modern setup.py for CMTJ using pybind11 helpers
33
"""
44
import sys
5-
import os
65
from pathlib import Path
76
from pybind11.setup_helpers import Pybind11Extension, build_ext
87
from setuptools import setup, find_packages
98

9+
# Get version from setuptools_scm
10+
try:
11+
from setuptools_scm import get_version
12+
version = get_version(root=".", relative_to=__file__)
13+
except (ImportError, LookupError):
14+
# Fallback: try to read from _version.py if it exists
15+
try:
16+
from cmtj._version import version
17+
except ImportError:
18+
version = "dev"
19+
1020
# Handle platform-specific compilation issues
1121
extra_compile_args = []
1222
extra_link_args = []
13-
define_macros = [("VERSION_INFO", '"dev"')]
23+
define_macros = [("VERSION_INFO", f'"{version}"')]
1424

1525
if sys.platform == 'darwin':
1626
# macOS-specific flags

tests/test_imports.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import importlib
21

32
def test_import_cvector():
43
from cmtj import CVector

0 commit comments

Comments
 (0)