Repository navigation
477 lines (472 loc) · 22.4 KB
/
Copy pathbuild-distributions.yml
File metadata and controls
477 lines (472 loc) · 22.4 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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
name: Build Distributions
# The single owner of the wheel platform matrix, the maturin settings and the distribution smoke
# tests. Distributions builds the wheels for pull requests that touch packaging, Release
# Distributions builds and keeps every distribution for a release pull request, and Publish either
# smoke tests and reuses those distributions or builds them here from the release tag.
on:
workflow_call:
inputs:
ref:
description: "Commit, tag or branch to build; empty builds the triggering commit"
required: false
type: string
default: ""
sdist:
description: "Also build the source distributions"
required: false
type: boolean
default: true
upload:
description: "Upload the distributions and a manifest recording their source commit and tree"
required: false
type: boolean
default: false
prebuilt-run-id:
description: >-
Release Distributions run whose distributions are smoke tested and uploaded instead of
building; its manifest must record the tree of ref. The caller grants actions: read.
required: false
type: string
default: ""
retention-days:
description: "Retention of uploaded artifacts in days; 0 uses the repository default"
required: false
type: number
default: 0
platforms:
description: "Comma-separated wheel platforms to build, such as linux-x86_64; empty builds all"
required: false
type: string
default: ""
outputs:
sha:
description: "Commit the distributions were built from"
value: ${{ jobs.source.outputs.sha }}
tree:
description: "Tree of the commit the distributions were built from"
value: ${{ jobs.source.outputs.tree }}
jobs:
source:
name: Resolve source
runs-on: ubuntu-24.04
outputs:
sha: ${{ steps.source.outputs.sha }}
tree: ${{ steps.source.outputs.tree }}
platforms: ${{ steps.platforms.outputs.platforms }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- name: Pin the source commit
id: source
run: |
sha="$(git rev-parse HEAD)"
tree="$(git rev-parse 'HEAD^{tree}')"
echo "sha=${sha}" >> "${GITHUB_OUTPUT}"
echo "tree=${tree}" >> "${GITHUB_OUTPUT}"
echo "Distributions for commit ${sha} with tree ${tree}" >> "${GITHUB_STEP_SUMMARY}"
# The wheel platform matrix. DuckDB's C++ needs aligned deallocation, available from macOS 10.13.
# The Intel macOS wheels cross-compile on Apple silicon, which builds faster than the Intel
# runners, and are smoke tested there under Rosetta 2 with an Intel Python (`python-arch`).
- name: Choose the wheel platforms
id: platforms
env:
ONLY: ${{ inputs.platforms }}
run: |
all='[
{"name": "linux-x86_64", "runner": "ubuntu-24.04", "target": "x86_64"},
{"name": "linux-aarch64", "runner": "ubuntu-24.04-arm", "target": "aarch64"},
{"name": "macos-x86_64", "runner": "macos-15", "target": "x86_64", "macos-target": "10.15", "python-arch": "x64"},
{"name": "macos-arm64", "runner": "macos-15", "target": "aarch64", "macos-target": "11.0"},
{"name": "windows-x86_64", "runner": "windows-2025", "target": "x86_64"}
]'
chosen="$(jq -c --arg only "${ONLY}" \
'if $only == "" then . else [.[] | select(.name as $name | $only | split(",") | index($name))] end' \
<<< "${all}")"
if [[ "${chosen}" == "[]" ]]; then
echo "No wheel platform is named ${ONLY}" >&2
exit 1
fi
echo "platforms=${chosen}" >> "${GITHUB_OUTPUT}"
echo "Wheel platforms: $(jq -r 'map(.name) | join(", ")' <<< "${chosen}")" >> "${GITHUB_STEP_SUMMARY}"
- name: Download the prebuilt manifest
if: inputs.prebuilt-run-id != ''
uses: actions/download-artifact@v4
with:
name: release-manifest
path: ${{ runner.temp }}/prebuilt
run-id: ${{ inputs.prebuilt-run-id }}
github-token: ${{ github.token }}
- name: Require prebuilt distributions from this exact tree
if: inputs.prebuilt-run-id != ''
env:
MANIFEST: ${{ runner.temp }}/prebuilt/release-manifest.json
PREBUILT_RUN_ID: ${{ inputs.prebuilt-run-id }}
TREE: ${{ steps.source.outputs.tree }}
run: |
recorded="$(jq -r '.tree // empty' "${MANIFEST}")"
if [[ "${recorded}" != "${TREE}" ]]; then
echo "Run ${PREBUILT_RUN_ID} built tree ${recorded:-<none>}, not ${TREE}" >&2
exit 1
fi
echo "Reusing distributions of run ${PREBUILT_RUN_ID}, built from tree ${TREE}" \
>> "${GITHUB_STEP_SUMMARY}"
wheels:
name: Build wheels (${{ matrix.platform.name }})
needs: source
runs-on: ${{ matrix.platform.runner }}
timeout-minutes: 90
strategy:
fail-fast: false
matrix:
platform: ${{ fromJSON(needs.source.outputs.platforms) }}
env:
# sccache's object cache for DuckDB's C and C++, inside the workspace so the manylinux
# container, which mounts the workspace at the same path, reads and writes it too.
SCCACHE_DIR: ${{ github.workspace }}/.sccache-cache
SCCACHE_CACHE_SIZE: 4G
steps:
- uses: actions/checkout@v4
if: inputs.prebuilt-run-id == ''
with:
ref: ${{ needs.source.outputs.sha }}
- name: Install Rosetta 2 for the Intel Python
if: matrix.platform.python-arch == 'x64' && runner.os == 'macOS'
run: |
if ! arch -x86_64 /usr/bin/true 2> /dev/null; then
sudo softwareupdate --install-rosetta --agree-to-license
fi
arch -x86_64 /usr/bin/true
- uses: actions/setup-python@v5
with:
python-version: "3.12"
architecture: ${{ matrix.platform.python-arch }}
# Both maturin steps compile DuckDB's C and C++ through sccache, and the cache restored below,
# written from main at these same paths, serves both. Cargo builds DuckDB once per step: pyo3
# turns on syn features in the Python module's build that serde_derive, a build dependency of
# libduckdb-sys, is compiled with, so the command line hashes libduckdb-sys differently. On a
# cold cache the second step still reads the first one's objects for the sources DuckDB
# compiles in place, but not for the unity files CMake writes into each build directory.
# Compiler launchers need a Makefile or Ninja generator, so Windows builds DuckDB with Ninja
# instead of the default Visual Studio generator.
- name: Install sccache for DuckDB's C and C++
if: inputs.prebuilt-run-id == ''
shell: bash
env:
VERSION: v0.19.0
run: |
case "${RUNNER_OS}-${RUNNER_ARCH}" in
Linux-X64) asset=x86_64-unknown-linux-musl sum=aa73c7270c997894038c0d8f0d297865f57569e1687883322bc431713d4bb9dd ;;
Linux-ARM64) asset=aarch64-unknown-linux-musl sum=3e47fc4a71b1ddd1b4294a0de9d34498922fdf41e3cd0bda5df3954e3d6deb9d ;;
macOS-ARM64) asset=aarch64-apple-darwin sum=a35a0b7d622618774bc1bb8102d72562dfb21e619f88b153b370d7f89bc286af ;;
Windows-X64) asset=x86_64-pc-windows-msvc sum=130e4f8eb672e76590e9993c2ab890c4763b88238577bb11d8062158c7698353 ;;
*) echo "No pinned sccache for ${RUNNER_OS}-${RUNNER_ARCH}" >&2; exit 1 ;;
esac
sha256() { if command -v sha256sum > /dev/null; then sha256sum "$@"; else shasum -a 256 "$@"; fi; }
# Relative paths: Git Bash's tar reads a `D:\...` archive name as a remote host.
archive=".sccache-bin/sccache-${VERSION}-${asset}.tar.gz"
mkdir -p .sccache-bin
curl -fsSL -o "${archive}" \
"https://github.com/mozilla/sccache/releases/download/${VERSION}/${archive#.sccache-bin/}"
echo "${sum} ${archive}" | sha256 -c -
tar -xzf "${archive}" -C .sccache-bin --strip-components 1
rm "${archive}"
launcher="${GITHUB_WORKSPACE}/.sccache-bin/sccache"
if [[ "${RUNNER_OS}" == "Windows" ]]; then
launcher="$(cygpath -m "${launcher}.exe")"
python -m pip install --quiet "ninja==1.13.0"
echo "CMAKE_GENERATOR=Ninja" >> "${GITHUB_ENV}"
fi
"${launcher}" --version
echo "CMAKE_C_COMPILER_LAUNCHER=${launcher}" >> "${GITHUB_ENV}"
echo "CMAKE_CXX_COMPILER_LAUNCHER=${launcher}" >> "${GITHUB_ENV}"
# The cache key names DuckDB's sources, its version name, its features, the profile, the
# target and the CMake settings; sccache itself still checks every object's exact inputs.
duckdb="$(grep -m 1 -o 'duckdb-rs?rev=[0-9a-f]*' Cargo.lock)"
describe="$(grep -m 1 '^OVERRIDE_GIT_DESCRIBE' .cargo/config.toml)"
features="$(grep -E '^(bundled|extensions) =' crates/sqlquack-blocks/Cargo.toml)"
settings="${duckdb} ${describe} ${features} release ${{ matrix.platform.target }}"
settings="${settings} ${{ matrix.platform.macos-target }} ${RUNNER_OS} ${VERSION}"
key="$(sha256 <<< "${settings}" | cut -c 1-16)"
echo "DUCKDB_CACHE_KEY=duckdb-objects-v1-${{ matrix.platform.name }}-${key}" >> "${GITHUB_ENV}"
# Restored on every build, but saved only from main (below), so a release or publish build
# never reads objects another branch compiled. Main saves from the scheduled nightly build, and
# otherwise only when no saved objects match this DuckDB and its settings (a first fill or an
# upgrade), so the repository's cache space is not spent on a copy per push.
- name: Restore DuckDB's compiled objects
id: duckdb-cache
if: inputs.prebuilt-run-id == ''
uses: actions/cache/restore@v4
with:
path: .sccache-cache
key: ${{ env.DUCKDB_CACHE_KEY }}-${{ github.run_id }}
restore-keys: ${{ env.DUCKDB_CACHE_KEY }}-
# Both wheels compile DuckDB in (the `bundled` feature), so neither needs a system DuckDB.
- name: Set the oldest macOS the wheels support
if: matrix.platform.macos-target
shell: bash
run: echo "MACOSX_DEPLOYMENT_TARGET=${{ matrix.platform.macos-target }}" >> "$GITHUB_ENV"
# DuckDB's CMake build nests object paths deep enough to pass Windows' path limit under the
# default target directory, and MSVC then fails with C1083; a short target directory avoids it.
- name: Shorten the build path on Windows
if: runner.os == 'Windows'
shell: bash
run: echo "CARGO_TARGET_DIR=D:/t" >> "$GITHUB_ENV"
# The DuckDB sources checkout the workspace patches duckdb to, which changes only with the lock.
# Each entry is several hundred MB, so only main saves one, once per lock (below); every other
# build only restores.
- name: Restore Cargo's git checkouts
id: cargo-git-cache
if: inputs.prebuilt-run-id == ''
uses: actions/cache/restore@v4
with:
path: ~/.cargo/git/db
key: cargo-git-${{ matrix.platform.name }}-${{ hashFiles('Cargo.lock') }}
restore-keys: cargo-git-${{ matrix.platform.name }}-
# On Linux maturin builds in a manylinux container, whose cargo keeps its git checkouts under
# /root/.cargo; mounting the cached folder there lets both builds read and fill it.
- name: Share Cargo's git checkouts with the manylinux container
if: inputs.prebuilt-run-id == '' && runner.os == 'Linux'
run: |
mkdir -p "${HOME}/.cargo/git/db"
echo "MATURIN_DOCKER_OPTIONS=-v ${HOME}/.cargo/git/db:/root/.cargo/git/db" >> "${GITHUB_ENV}"
- uses: PyO3/maturin-action@v1
if: inputs.prebuilt-run-id == ''
with:
command: build
args: --release --locked --out ../dist
working-directory: python
target: ${{ matrix.platform.target }}
manylinux: "2_28"
docker-options: ${{ env.MATURIN_DOCKER_OPTIONS }}
- uses: PyO3/maturin-action@v1
if: inputs.prebuilt-run-id == ''
with:
command: build
args: --release --locked --out ../../dist
working-directory: crates/sqlquack
target: ${{ matrix.platform.target }}
manylinux: "2_28"
docker-options: ${{ env.MATURIN_DOCKER_OPTIONS }}
- name: Report sccache's hits
if: inputs.prebuilt-run-id == '' && runner.os != 'Linux'
shell: bash
run: '"${CMAKE_C_COMPILER_LAUNCHER}" --stop-server'
# The manylinux container writes the cache as root, and sccache keeps its files private.
- name: Give the runner the container's cache files
if: >-
runner.os == 'Linux' && inputs.prebuilt-run-id == '' && github.ref == 'refs/heads/main'
&& (github.event_name == 'schedule' || steps.duckdb-cache.outputs.cache-matched-key == '')
run: sudo chown -R "$(id -u):$(id -g)" .sccache-cache
- name: Save DuckDB's compiled objects from main
if: >-
inputs.prebuilt-run-id == '' && github.ref == 'refs/heads/main'
&& (github.event_name == 'schedule' || steps.duckdb-cache.outputs.cache-matched-key == '')
uses: actions/cache/save@v4
with:
path: .sccache-cache
key: ${{ env.DUCKDB_CACHE_KEY }}-${{ github.run_id }}
- name: Save Cargo's git checkouts from main
if: >-
inputs.prebuilt-run-id == '' && github.ref == 'refs/heads/main'
&& steps.cargo-git-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: ~/.cargo/git/db
key: cargo-git-${{ matrix.platform.name }}-${{ hashFiles('Cargo.lock') }}
- name: Download prebuilt wheels
if: inputs.prebuilt-run-id != ''
uses: actions/download-artifact@v4
with:
name: dist-wheel-${{ matrix.platform.name }}
path: dist
run-id: ${{ inputs.prebuilt-run-id }}
github-token: ${{ github.token }}
- name: Smoke test the installed wheels as the site's quick start runs them
shell: bash
env:
PYTHON_ARCH: ${{ matrix.platform.python-arch }}
run: |
python -m venv "${RUNNER_TEMP}/wheel-smoke"
if [[ -x "${RUNNER_TEMP}/wheel-smoke/Scripts/python.exe" ]]; then
bin="${RUNNER_TEMP}/wheel-smoke/Scripts"
else
bin="${RUNNER_TEMP}/wheel-smoke/bin"
fi
python=("${bin}/python")
# setup-python's x64 CPython for macOS is universal2 and runs as arm64 on Apple silicon,
# where pip would refuse the Intel wheels; run it as x86_64 under Rosetta 2 instead.
if [[ "${PYTHON_ARCH}" == "x64" && "${RUNNER_OS}" == "macOS" ]]; then
python=(arch -x86_64 "${bin}/python")
machine="$("${python[@]}" -c "import platform; print(platform.machine())")"
if [[ "${machine}" != "x86_64" ]]; then
echo "The smoke test Python runs as ${machine}, not x86_64" >&2
exit 1
fi
fi
ls -l dist | tee -a "${GITHUB_STEP_SUMMARY}"
# Only the wheels just built: sqlquack-cli must resolve from dist, never from an index.
"${python[@]}" -m pip install --no-index --find-links dist sqlquack
cd "${RUNNER_TEMP}"
"${bin}/sqlquack" --version
"${python[@]}" -c "import sqlquack.api"
set +e
check="$(echo "SELECT 1 QUALIFY TRUE" | "${bin}/sqlquack" check 2>&1)"
status=$?
set -e
echo "${check}"
if [[ ${status} -ne 1 ]] || ! grep -q 'error\[SQ0203\]' <<< "${check}"; then
echo "check should refuse QUALIFY without a window function with SQ0203 and exit 1" >&2
exit 1
fi
converted="$(echo "SELECT 1 AS total" | "${bin}/sqlquack" convert --no-config)"
echo "${converted}"
grep -qx 'SELECT CAST(1 AS DECIMAL(1, 0)) AS "TOTAL"' <<< "${converted}"
# A file converted in a project folder, with no sqlquack.toml in it: the built-in policy.
mkdir readme-smoke && cd readme-smoke
printf "SELECT customer_id, SUM(total) AS revenue\nFROM orders\nGROUP BY customer_id\n" > query.sql
mkdir sources
printf 'sources:\n - name: orders\n columns:\n - name: customer_id\n type: NUMBER(38,0)\n - name: total\n type: NUMBER(12,2)\n' > sources/orders.yml
"${bin}/sqlquack" check query.sql
converted="$("${bin}/sqlquack" convert query.sql)"
echo "${converted}"
grep -q 'CAST(sum("ORDERS"."TOTAL") AS DECIMAL(24, 2)) AS "REVENUE"' <<< "${converted}"
# run executes the conversion on the bundled DuckDB, over inline rows and over a CSV file.
"${bin}/sqlquack" run query.sql --fixture 'orders=[[1, 2.5], [1, 4]]' --expect '[[1, 6.5]]'
printf 'customer_id,total\n2,1.25\n' > orders.csv
ran="$("${bin}/sqlquack" run query.sql --fixture orders=./orders.csv)"
echo "${ran}"
grep -q '^2 *1.25$' <<< "${ran}"
# The README's Python example.
"${python[@]}" -c 'import sqlquack
result = sqlquack.convert(sql="SELECT 1 AS total", options=sqlquack.ConvertOptions(no_config=True))
assert result.sql == "SELECT CAST(1 AS DECIMAL(1, 0)) AS \"TOTAL\"", result.sql'
# Deep function-call nesting on a small thread stack, where Windows threads are smallest:
# 511 levels read at the 512 ceiling; 257 at the default is a clean error, not a crash.
"${python[@]}" -c 'import sqlquack, threading
def nested(levels):
return "SELECT " + "ABS(" * levels + "1" + ")" * levels
found = []
threading.stack_size(256 * 1024)
def check():
found.append(sqlquack.check(sql=nested(511), max_call_depth=512).ok)
found.append(sqlquack.check(sql=nested(257)).diagnostics[0].code)
thread = threading.Thread(target=check)
thread.start()
thread.join()
assert found == [True, "SQ0107"], found'
# A transient network error in the upload would otherwise cost the whole build, so it retries
# once, replacing any artifact the failed attempt left behind.
- id: upload-wheel
uses: actions/upload-artifact@v4
if: inputs.upload
continue-on-error: true
with:
name: dist-wheel-${{ matrix.platform.name }}
path: dist
if-no-files-found: error
retention-days: ${{ inputs.retention-days }}
- name: Retry the wheel upload
uses: actions/upload-artifact@v4
if: inputs.upload && steps.upload-wheel.outcome == 'failure'
with:
name: dist-wheel-${{ matrix.platform.name }}
path: dist
if-no-files-found: error
retention-days: ${{ inputs.retention-days }}
overwrite: true
sdist:
name: Build sdists
needs: source
if: inputs.sdist
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
if: inputs.prebuilt-run-id == ''
with:
ref: ${{ needs.source.outputs.sha }}
- uses: PyO3/maturin-action@v1
if: inputs.prebuilt-run-id == ''
with:
command: sdist
args: --out ../dist
working-directory: python
- uses: PyO3/maturin-action@v1
if: inputs.prebuilt-run-id == ''
with:
command: sdist
args: --out ../../dist
working-directory: crates/sqlquack
- name: Download prebuilt source distributions
if: inputs.prebuilt-run-id != ''
uses: actions/download-artifact@v4
with:
name: dist-sdist
path: dist
run-id: ${{ inputs.prebuilt-run-id }}
github-token: ${{ github.token }}
- name: Inspect source distribution contents
run: |
for archive in dist/*.tar.gz; do
tar -tzf "$archive" > "${RUNNER_TEMP}/archive-contents.txt"
if grep -E '(__pycache__/|\.pyc$|\.tmp$)' "${RUNNER_TEMP}/archive-contents.txt"; then
echo "Source distribution contains generated or temporary script files"
exit 1
fi
done
# A transient network error in the upload would otherwise cost the whole build, so it retries
# once, replacing any artifact the failed attempt left behind.
- id: upload-sdist
uses: actions/upload-artifact@v4
if: inputs.upload
continue-on-error: true
with:
name: dist-sdist
path: dist
if-no-files-found: error
retention-days: ${{ inputs.retention-days }}
- name: Retry the sdist upload
uses: actions/upload-artifact@v4
if: inputs.upload && steps.upload-sdist.outcome == 'failure'
with:
name: dist-sdist
path: dist
if-no-files-found: error
retention-days: ${{ inputs.retention-days }}
overwrite: true
manifest:
name: Record distribution source
needs: [source, wheels, sdist]
if: >-
${{ !cancelled() && inputs.upload && needs.wheels.result == 'success'
&& (needs.sdist.result == 'success' || needs.sdist.result == 'skipped') }}
runs-on: ubuntu-24.04
steps:
- name: Write the manifest
env:
SHA: ${{ needs.source.outputs.sha }}
TREE: ${{ needs.source.outputs.tree }}
run: |
jq -n --arg sha "${SHA}" --arg tree "${TREE}" --arg run_id "${GITHUB_RUN_ID}" \
'{sha: $sha, tree: $tree, run_id: $run_id}' \
> "${RUNNER_TEMP}/release-manifest.json"
cat "${RUNNER_TEMP}/release-manifest.json"
# A transient network error in the upload would otherwise cost the whole build, so it retries
# once, replacing any artifact the failed attempt left behind.
- id: upload-manifest
uses: actions/upload-artifact@v4
continue-on-error: true
with:
name: release-manifest
path: ${{ runner.temp }}/release-manifest.json
if-no-files-found: error
retention-days: ${{ inputs.retention-days }}
- name: Retry the manifest upload
uses: actions/upload-artifact@v4
if: steps.upload-manifest.outcome == 'failure'
with:
name: release-manifest
path: ${{ runner.temp }}/release-manifest.json
if-no-files-found: error
retention-days: ${{ inputs.retention-days }}
overwrite: true