-
Notifications
You must be signed in to change notification settings - Fork 3
230 lines (198 loc) · 6.71 KB
/
build-wheel-release.yml
File metadata and controls
230 lines (198 loc) · 6.71 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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
name: Build Wheels and Release
on:
workflow_dispatch:
push:
tags:
- "*"
env:
PYTHON_VERSIONS: '["3.11","3.12","3.13"]'
permissions:
contents: write
actions: read
packages: write
concurrency:
group: build-wheels-${{ github.ref }}
cancel-in-progress: true
defaults:
run:
shell: bash {0}
jobs:
get-python-versions:
runs-on: ubuntu-latest
outputs:
py_ver: ${{ steps.set.outputs.py_ver }}
py_last: ${{ steps.set.outputs.py_last }}
steps:
- id: set
run: |
echo py_ver=$PYTHON_VERSIONS >> $GITHUB_OUTPUT
echo "py_last=${{ fromJson(env.PYTHON_VERSIONS)[0] }}" >> $GITHUB_OUTPUT
check-tag-on-main:
runs-on: ubuntu-latest
steps:
- name: Checkout repository with full history
uses: actions/checkout@v4
with:
token: ${{ secrets.PAT_TOKEN }}
fetch-depth: 0
- name: Verify tag
run: |
git fetch origin main
TAG_COMMIT=$(git rev-parse ${{ github.ref_name }})
if git merge-base --is-ancestor "$TAG_COMMIT" origin/main; then
echo "Tag ${{ github.ref_name }} ($TAG_COMMIT) is contained in main"
else
echo "::error::Tag ${{ github.ref_name }} ($TAG_COMMIT) is not found in main. Please release from the main branch."
exit 1
fi
check-tag-privilege:
# No third party actions used
uses: scikit-package/release-scripts/.github/workflows/_check-tag-privilege.yml@v0
with:
maintainer_github_username: sbillinge
build-sdist:
needs: [check-tag-privilege, get-python-versions, check-tag-on-main]
runs-on: ubuntu-latest
steps:
- name: Checkout
# GitHub officially-maintained actions
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
# GitHub officially-maintained actions
uses: actions/setup-python@v5
with:
python-version: ${{ needs.get-python-versions.outputs.py_last }}
- name: Build docs and remove fonts that blow up the wheel size
run: |
python -m pip install Sphinx sphinx-rtd-theme sphinx-copybutton m2r
cd docs
make html
cd build/html/_static/css/fonts
find . -type f ! -name '*.ttf' -delete
cd ../..
rm -rf fonts
cd ..
rm -rf _sources
cd ..
rm -rf doctrees
cd ../..
- name: Make sdist
run: |
python -m pip install --upgrade pip build cython setuptools setuptools-git-versioning
python -m build --sdist --no-isolation
- name: Strip source codes
run: |
set -euo pipefail
tar xf dist/diffpy_distanceprinter-*.tar.gz
SRC_DIR=$(find . -maxdepth 1 -type d -name 'diffpy_distanceprinter-*' | head -n1)
find "$SRC_DIR" -type f -name '*.c' -print0 \
| xargs -0 perl -i.bak -0777 -pe 's{/\*.*?\*/}{}gs'
find "$SRC_DIR" -type f -name '*.c.bak' -delete
tar czf dist/"${SRC_DIR#./}".tar.gz "$SRC_DIR"
rm -rf "$SRC_DIR"
- name: Upload sdist
# GitHub officially-maintained actions
uses: actions/upload-artifact@v4
with:
name: sdist
path: dist/
retention-days: 1
- name: Upload INSTRUCTIONS.txt
uses: actions/upload-artifact@v4
with:
name: instructions
path: INSTRUCTIONS.txt
build-wheels:
needs: [build-sdist, get-python-versions]
name: Build wheels ${{ matrix.python }}-${{ matrix.buildplat }}
runs-on: ${{ matrix.buildplat }}
strategy:
fail-fast: false
matrix:
buildplat:
- ubuntu-latest
- macos-14
- windows-latest
python: ${{ fromJSON(needs.get-python-versions.outputs.py_ver) }}
steps:
- name: Download sdist
# GitHub officially-maintained actions
uses: actions/download-artifact@v4
with:
name: sdist
path: dist/
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: Build wheels
run: |
# setuptools-git-versioning only look into .git and PKG-INFO in the top directory
which python; python --version
which pip; pip --version
python -m pip install --upgrade pip build cython setuptools setuptools-git-versioning
tar xf dist/diffpy_distanceprinter-*.tar.gz
cd diffpy_distanceprinter-*
python -m pip wheel . --no-deps --no-build-isolation --wheel-dir ./../dist
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.python }}-${{ matrix.buildplat }}
path: dist/*.whl
test-wheels:
needs: [build-wheels, get-python-versions]
name: Test wheels ${{ matrix.python }}-${{ matrix.buildplat }}
runs-on: ${{ matrix.buildplat }}
strategy:
fail-fast: false
matrix:
buildplat:
- ubuntu-latest
- macos-14
- windows-latest
python: ${{ fromJson(needs.get-python-versions.outputs.py_ver) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download wheels
uses: actions/download-artifact@v4
with:
name: wheels-${{ matrix.python }}-${{ matrix.buildplat }}
path: dist/
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: Install wheels
run: |
python -m pip install --upgrade pip pytest setuptools-git-versioning
python -m pip install dist/*.whl
- name: Assert no source files in installed package
run: |
# For debugging
# touch $(python -c "import sysconfig, os; print(os.path.join(sysconfig.get_paths()['purelib'], 'diffpy/distanceprinter', 'fake.py'))")
python - << 'EOF'
import os, glob, sys, sysconfig
sp = sysconfig.get_paths()['purelib']
pkg = os.path.join(sp, 'diffpy', 'distanceprinter')
patterns = [os.path.join(pkg, '*.py'),
os.path.join(pkg, '*.c')]
bad = []
for p in patterns:
bad.extend(glob.glob(p))
if bad:
print("Found leftover source files in installed package:")
for f in bad:
print(" -", f)
sys.exit(1)
print("No .py or .c files present in diffpy/distanceprinter/")
EOF
- name: Run tests
run: python -m pytest
release:
needs: [test-wheels]
uses: ./.github/workflows/release-github.yml
secrets:
PAT_TOKEN: ${{ secrets.PAT_TOKEN }}