-
Notifications
You must be signed in to change notification settings - Fork 28
276 lines (267 loc) · 9.71 KB
/
build.yml
File metadata and controls
276 lines (267 loc) · 9.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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# Reusable workflow for building binaries
name: Binaries
on:
workflow_call:
inputs:
linux_builder_repo_and_digest:
# Use .github/find-container-digest action to get this
description: |
Docker repo and image digest of the Linux builder container, or
empty to skip Linux build
required: false
type: string
macos_enable:
description: Build macOS binaries
required: false
type: boolean
default: false
openslide_repo:
description: Override OpenSlide with this repo
required: false
type: string
openslide_ref:
description: Override OpenSlide with this openslide_repo ref
required: false
type: string
openslide_bin_repo:
description: Use openslide-bin from this repo
required: false
type: string
default: openslide/openslide-bin
openslide_bin_ref:
description: Use openslide-bin from this ref
required: false
type: string
default: main
suffix:
description: Set package version suffix
required: true
type: string
werror:
description: Fail on build warnings in OpenSlide packages
required: false
type: boolean
default: false
windows_builder_repo_and_digest:
# Use .github/find-container-digest action to get this
description: |
Docker repo and image digest of the Windows builder container
required: true
type: string
outputs:
version:
description: The version of the output artifacts
value: ${{ jobs.sdist.outputs.version }}
permissions:
contents: read
jobs:
sdist:
name: Source tarball
runs-on: ubuntu-latest
container: ${{ inputs.windows_builder_repo_and_digest }}
outputs:
archive_base: ${{ steps.prep.outputs.archive_base }}
archive: ${{ steps.prep.outputs.archive }}
systems: ${{ steps.systems.outputs.systems }}
version: ${{ steps.prep.outputs.version }}
steps:
- name: Check out repo
uses: actions/checkout@v6
with:
repository: ${{ inputs.openslide_bin_repo }}
ref: ${{ inputs.openslide_bin_ref }}
- name: Check out OpenSlide
if: inputs.openslide_repo != ''
uses: actions/checkout@v6
with:
repository: ${{ inputs.openslide_repo }}
ref: ${{ inputs.openslide_ref }}
# make sure "git describe" works
fetch-depth: 0
path: override/openslide
persist-credentials: false
- name: Collect overrides
if: inputs.openslide_repo != ''
run: tar cf build-overrides.tar.zst --zstd override
- name: Upload overrides
if: inputs.openslide_repo != ''
uses: actions/upload-artifact@v7
with:
path: build-overrides.tar.zst
archive: false
- name: Calculate cache key
id: cache-key
run: |
# glob results are sorted
sha256=$(cat subprojects/*.wrap | sha256sum - | cut -c1-20)
echo "sha256=${sha256}" >> $GITHUB_OUTPUT
# use a fresh cache every year to flush out old sources
echo "year=$(date +%Y)" >> $GITHUB_OUTPUT
- name: Cache sources
uses: actions/cache@v5
with:
key: build-packagecache-${{ steps.cache-key.outputs.year }}-${{ steps.cache-key.outputs.sha256 }}
restore-keys: build-packagecache-${{ steps.cache-key.outputs.year }}-
path: subprojects/packagecache
- name: Build source tarball
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
./bintool sdist -x "${{ inputs.suffix }}"
- name: Prep archive
id: prep
run: |
version=$(./bintool version -x "${{ inputs.suffix }}")
echo "version=$version" >> $GITHUB_OUTPUT
archive_base="openslide-bin-${version}"
echo "archive_base=$archive_base" >> $GITHUB_OUTPUT
echo "archive=${archive_base}.tar.gz" >> $GITHUB_OUTPUT
- name: Upload archive
uses: actions/upload-artifact@v7
with:
path: ${{ steps.prep.outputs.archive }}
archive: false
- name: Check source tarball size
# check after uploading, to aid debugging
run: |
size=$(stat -c "%s" "${{ steps.prep.outputs.archive }}")
if [ $size -gt 104857600 ]; then
# https://github.com/pypi/warehouse/blob/cf94b41/warehouse/forklift/legacy.py#L77
echo "Source tarball is $size bytes, which is larger than 100 MiB."
echo "Reduce the source tarball size, or if needed, maintainers will need to"
echo "request a larger PyPI file size limit."
echo "https://pypi.org/help/#file-size-limit"
exit 1
fi
- name: Compute bdist systems
id: systems
shell: python
run: |
import json, os
systems = []
if '${{ inputs.linux_builder_repo_and_digest }}':
for (arch, runner) in (
('aarch64', 'ubuntu-24.04-arm'),
('x86_64', 'ubuntu-latest')
):
systems.append({
'os': 'linux',
'arch': arch,
'runner': runner,
'container': '${{ inputs.linux_builder_repo_and_digest }}',
})
if ${{ inputs.macos_enable && 1 || 0 }}:
systems.append({
'os': 'macos',
'arch': 'arm64-x86_64',
'runner': 'macos-latest',
})
if '${{ inputs.windows_builder_repo_and_digest }}':
systems.append({
'os': 'windows',
'arch': 'x64',
'runner': 'ubuntu-latest',
'container': '${{ inputs.windows_builder_repo_and_digest }}',
})
with open(os.environ['GITHUB_OUTPUT'], 'a') as fh:
fh.write(f'systems={json.dumps(systems)}\n')
bdist:
name: Binaries (${{ matrix.os }}, ${{ matrix.arch }})
needs: sdist
strategy:
matrix:
include: ${{ fromJson(needs.sdist.outputs.systems) }}
runs-on: ${{ matrix.runner }}
container: ${{ matrix.container }}
steps:
- name: Install dependencies (macOS)
if: matrix.os == 'macos'
run: |
# https://github.com/actions/setup-python/issues/577
# https://github.com/q3aiml/ledger/commit/f53b35ae
brew list -1 | grep python@ | while read formula; do
brew unlink $formula
brew link --overwrite $formula
done
brew update
brew install meson nasm
python3 -m pip install --break-system-packages license-expression
- name: Download source tarball
uses: actions/download-artifact@v8
with:
name: ${{ needs.sdist.outputs.archive }}
- name: Unpack source tarball
run: |
tar xf "${{ needs.sdist.outputs.archive }}"
mv "${{ needs.sdist.outputs.archive_base }}"/* .
rm -r "${{ needs.sdist.outputs.archive_base }}" \
"${{ needs.sdist.outputs.archive }}"
- name: Download overrides
if: inputs.openslide_repo != ''
uses: actions/download-artifact@v8
with:
name: build-overrides.tar.zst
- name: Unpack overrides
if: inputs.openslide_repo != ''
run: |
if [ "${{ matrix.os }}" = linux ]; then
# EL 8 tar can't autodetect zstd compression
zstd="-I zstd"
fi
tar xf build-overrides.tar.zst $zstd && rm build-overrides.tar.zst
- name: Build
id: build
run: |
werror=
if [ "${{ inputs.werror }}" = true ]; then
werror="-w"
fi
./bintool bdist -x "${{ inputs.suffix }}" $werror
archive=$(echo openslide-bin-"${{ needs.sdist.outputs.version }}"-*)
echo "archive=$archive" >> $GITHUB_OUTPUT
wheel=$(echo openslide_bin-"${{ needs.sdist.outputs.version }}"-*-*-*.whl)
echo "wheel=$wheel" >> $GITHUB_OUTPUT
- name: Upload archive
uses: actions/upload-artifact@v7
with:
path: ${{ steps.build.outputs.archive }}
archive: false
- name: Upload wheel
uses: actions/upload-artifact@v7
with:
path: ${{ steps.build.outputs.wheel }}
archive: false
finalize:
name: Finalize
needs: [sdist, bdist]
runs-on: windows-latest
steps:
- name: Update Python
uses: actions/setup-python@v6
with:
python-version: 3.14
- name: Download archives
uses: actions/download-artifact@v8
with:
pattern: "openslide[-_]bin-${{ needs.sdist.outputs.version }}*"
path: archives
merge-multiple: true
skip-decompress: true
- name: Unpack source tarball
shell: bash
run: |
tar xf "archives/openslide-bin-${{ needs.sdist.outputs.version }}.tar.gz"
mv "openslide-bin-${{ needs.sdist.outputs.version }}"/* .
rm -r "openslide-bin-${{ needs.sdist.outputs.version }}"
- name: Report package versions
shell: bash
run: |
shopt -s nullglob
./bintool versions \
"archives/openslide-bin-${{ needs.sdist.outputs.version }}"-*.{tar.xz,zip} \
>> $GITHUB_STEP_SUMMARY
- name: Windows smoke test
shell: bash
run: |
./bintool smoke \
"archives/openslide-bin-${{ needs.sdist.outputs.version }}-windows-x64.zip" \
"archives/openslide_bin-${{ needs.sdist.outputs.version }}-py3-none-win_amd64.whl"