Repository navigation
213 lines (190 loc) · 7.64 KB
/
Copy pathrelease.yml
File metadata and controls
213 lines (190 loc) · 7.64 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# .github/workflows/release.yml
# Release workflow that builds and publishes packages to PyPI
# - Builds wheels for all supported Python versions and platforms
# - Builds source distribution
# - Uses __init__.py version as source of truth (supports any valid PEP 440 version)
# - For test builds: adds .devN suffix (e.g., 2.1.0.dev1 or 2.1.0a1.dev1)
# - For production: uses base version, adds .postN only if rebuild needed
# See https://github.com/pypa/cibuildwheel for details
name: Release
on:
workflow_dispatch:
inputs:
is_test:
description: 'Push to TestPyPI'
type: boolean
default: true
required: true
build_number:
description: 'Build number (adds .devN for test, .postN for production rebuild if > 1)'
type: string
required: true
default: '1'
jobs:
validate-version:
name: Validate package version
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get-version.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Need full history for tags
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.13'
- name: Get version from __init__.py
id: get-version
run: |
# Extract version from __init__.py
# This supports any valid PEP 440 version including pre-releases (e.g., 2.1.0a1)
VERSION=$(sed -n "s/^__version__ = '\(.*\)'/\1/p" primer3/__init__.py)
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "Base version from __init__.py: ${VERSION}"
# If this is a tagged commit, validate tag matches version
# For pre-releases: tag should match exactly (e.g., v2.1.0a1)
GIT_TAG=$(git describe --exact-match --tags HEAD 2>/dev/null || echo "")
if [[ -n "$GIT_TAG" ]]; then
# Remove 'v' prefix if present
TAG_VERSION=${GIT_TAG#v}
if [[ "$VERSION" != "$TAG_VERSION" ]]; then
echo "Error: __init__.py version ${VERSION} does not match git tag ${TAG_VERSION}"
exit 1
fi
echo "Version matches git tag"
fi
build-wheels:
name: Build wheel for ${{ matrix.os }} / Python ${{ matrix.python-version }}
needs: validate-version
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-22.04, macos-latest, windows-2022]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14", "3.15"]
fail-fast: false
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Configure version
shell: bash
run: |
# Get base version from validate job
BASE_VERSION="${{ needs.validate-version.outputs.version }}"
if [[ "${{ inputs.is_test }}" == "true" ]]; then
# Test builds always use .devN
VERSION="${BASE_VERSION}.dev${{ inputs.build_number }}"
else
# Production builds only use .postN if build_number > 1
if [[ "${{ inputs.build_number }}" == "1" ]]; then
VERSION="${BASE_VERSION}"
else
# Subtract 1 from build_number for post suffix (so first retry is post1)
POST_NUM=$((${{ inputs.build_number }} - 1))
VERSION="${BASE_VERSION}.post${POST_NUM}"
fi
fi
echo "PACKAGE_VERSION=${VERSION}" >> $GITHUB_ENV
# Update the version in primer3/__init__.py (the single source of
# truth; pyproject.toml resolves its dynamic version from
# primer3.__version__, so patching setup.py here is a no-op)
sed -i.bak "s/^__version__ = '.*'/__version__ = '${VERSION}'/" primer3/__init__.py
- name: Build wheels
uses: pypa/cibuildwheel@v4.2.0
env:
CIBW_PROJECT_REQUIRES_PYTHON: "==${{ matrix.python-version }}.*"
CIBW_SKIP: "{*-musllinux_*,pp*}" # Skip musl linux and PyPy versions
CIBW_ARCHS_MACOS: "x86_64 arm64"
CIBW_ARCHS_LINUX: "auto64"
CIBW_ARCHS_WINDOWS: "auto64"
MACOSX_DEPLOYMENT_TARGET: "10.14"
CIBW_BEFORE_BUILD: >-
python -m pip install --upgrade pip setuptools wheel &&
cd {project} &&
python -m pip install -e ".[dev]"
CIBW_TEST_COMMAND_MACOS: "pytest {project}/tests/test_thermoanalysis.py -v"
CIBW_TEST_COMMAND_LINUX: "pytest {project}/tests/test_thermoanalysis.py -v"
CIBW_TEST_COMMAND_WINDOWS: "pytest {project}\\tests\\test_thermoanalysis.py"
CIBW_BUILD_VERBOSITY: 1
- name: Upload wheel artifacts
uses: actions/upload-artifact@v4
with:
name: dist-${{ matrix.python-version }}-${{ matrix.os }}
path: ./wheelhouse/*.whl
build-sdist:
name: Build source distribution
needs: validate-version
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Configure version
shell: bash
run: |
# Get base version from validate job
BASE_VERSION="${{ needs.validate-version.outputs.version }}"
if [[ "${{ inputs.is_test }}" == "true" ]]; then
# Test builds always use .devN
VERSION="${BASE_VERSION}.dev${{ inputs.build_number }}"
else
# Production builds only use .postN if build_number > 1
if [[ "${{ inputs.build_number }}" == "1" ]]; then
VERSION="${BASE_VERSION}"
else
# Subtract 1 from build_number for post suffix (so first retry is post1)
POST_NUM=$((${{ inputs.build_number }} - 1))
VERSION="${BASE_VERSION}.post${POST_NUM}"
fi
fi
echo "PACKAGE_VERSION=${VERSION}" >> $GITHUB_ENV
# Update the version in primer3/__init__.py (the single source of
# truth; pyproject.toml resolves its dynamic version from
# primer3.__version__, so patching setup.py here is a no-op)
sed -i.bak "s/^__version__ = '.*'/__version__ = '${VERSION}'/" primer3/__init__.py
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.13'
cache: 'pip'
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
python -m pip install build "setuptools>=67.1.0" "Cython~=3.3.0" wheel
- name: Build sdist
run: python -m build --sdist
- name: Upload sdist artifact
uses: actions/upload-artifact@v4
with:
name: dist-sdist
path: dist/*.tar.gz
publish:
name: Publish to ${{ inputs.is_test && 'TestPyPI' || 'PyPI' }}
needs: [validate-version, build-wheels, build-sdist]
runs-on: ubuntu-latest
permissions:
id-token: write # Required for trusted publishing
steps:
- name: Download distribution artifacts
uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- name: Verify distribution files
run: ls -lR dist/
- name: Publish to PyPI
if: inputs.is_test == false
uses: pypa/gh-action-pypi-publish@v1.14.3
with:
password: ${{ secrets.PRIMER3_PYPI_API_TOKEN }}
verify-metadata: true
verbose: true
- name: Publish to TestPyPI
if: inputs.is_test == true
uses: pypa/gh-action-pypi-publish@v1.14.3
with:
password: ${{ secrets.PRIMER3_TEST_PYPI_API_TOKEN }}
repository-url: https://test.pypi.org/legacy/
verify-metadata: true
verbose: true
skip-existing: false