Skip to content

Commit f0aac96

Browse files
committed
add pgo builds for release artifacts on ubuntu
1 parent 985f097 commit f0aac96

File tree

1 file changed

+99
-15
lines changed

1 file changed

+99
-15
lines changed

.github/workflows/ci.yml

+99-15
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,25 @@ jobs:
288288
jobs: ${{ toJSON(needs) }}
289289
allowed-failures: coverage
290290

291+
build-sdist:
292+
name: build sdist
293+
runs-on: ubuntu-latest
294+
steps:
295+
- uses: actions/checkout@v3
296+
- uses: PyO3/maturin-action@v1
297+
with:
298+
command: sdist
299+
args: --out dist
300+
rust-toolchain: stable
301+
- uses: actions/upload-artifact@v3
302+
with:
303+
name: pypi_files
304+
path: dist
305+
291306
build:
292307
name: build on ${{ matrix.platform || matrix.os }} (${{ matrix.target }} - ${{ matrix.manylinux || 'auto' }})
293308
# only run on push to main and on release
294-
if: "success() && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'Full Build'))"
309+
if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'Full Build')
295310
strategy:
296311
fail-fast: false
297312
matrix:
@@ -346,6 +361,11 @@ jobs:
346361
container: messense/manylinux_2_24-cross:s390x
347362
interpreter: 3.7 3.8 3.9 3.10 3.11
348363
exclude:
364+
# Optimized PGO builds for manylinux follow a different matrix, maybe in future
365+
# maturin-action can support this automatically
366+
- os: ubuntu
367+
target: x86_64
368+
manylinux: auto
349369
# Windows on arm64 only supports Python 3.11+
350370
- os: windows
351371
target: aarch64
@@ -360,19 +380,11 @@ jobs:
360380
python-version: '3.11'
361381
architecture: ${{ matrix.python-architecture || 'x64' }}
362382

363-
- run: pip install -U twine 'black>=22.3.0,<23' typing_extensions
383+
- run: pip install -U 'black>=22.3.0,<23' typing_extensions
364384

365385
# generate self-schema now, so we don't have to do so inside docker in maturin build
366386
- run: python generate_self_schema.py
367387

368-
- name: build sdist
369-
if: ${{ matrix.os == 'ubuntu' && matrix.target == 'x86_64' && matrix.manylinux == 'auto' }}
370-
uses: PyO3/maturin-action@v1
371-
with:
372-
command: sdist
373-
args: --out dist
374-
rust-toolchain: stable
375-
376388
- name: build wheels
377389
uses: PyO3/maturin-action@v1
378390
with:
@@ -385,15 +397,87 @@ jobs:
385397

386398
- run: ${{ matrix.ls || 'ls -lh' }} dist/
387399

388-
- run: twine check --strict dist/*
400+
- uses: actions/upload-artifact@v3
401+
with:
402+
name: pypi_files
403+
path: dist
404+
405+
build-pgo:
406+
name: build pgo-optimized on ${{ matrix.platform || matrix.os }} (${{ matrix.interpreter}} - ${{ matrix.target }} - ${{ matrix.manylinux || 'auto' }})
407+
# only run on push to main and on release
408+
if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'Full Build')
409+
strategy:
410+
fail-fast: false
411+
matrix:
412+
os: [ubuntu]
413+
platform: [linux]
414+
target: [x86_64]
415+
manylinux: [auto]
416+
interpreter: ["3.7", "3.8", "3.9", "3.10", "3.11", "pypy3.7", "pypy3.8", "pypy3.9"]
417+
418+
runs-on: ${{ matrix.os }}-latest
419+
steps:
420+
- uses: actions/checkout@v3
421+
422+
- name: set up python
423+
uses: actions/setup-python@v4
424+
with:
425+
python-version: ${{ matrix.interpreter }}
426+
architecture: ${{ matrix.python-architecture || 'x64' }}
427+
428+
- name: install rust stable
429+
id: rust-toolchain
430+
uses: dtolnay/rust-toolchain@stable
431+
with:
432+
components: llvm-tools
433+
434+
- run: pip install -U 'black>=22.3.0,<23' typing_extensions
435+
436+
# generate self-schema now, so we don't have to do so inside docker in maturin build
437+
- run: python generate_self_schema.py
438+
439+
- name: build initial wheel
440+
uses: PyO3/maturin-action@v1
441+
with:
442+
target: ${{ matrix.target }}
443+
manylinux: ${{ matrix.manylinux || 'auto' }}
444+
args: >
445+
--release
446+
--out pgo-wheel
447+
--interpreter ${{ matrix.interpreter }}
448+
-- -Cprofile-generate=${{ github.workspace }}/profdata
449+
rust-toolchain: stable
450+
451+
- name: generate pgo data
452+
run: |
453+
pip install -U pip
454+
pip install -r tests/requirements.txt
455+
pip install pydantic-core --no-index --no-deps --find-links pgo-wheel --force-reinstall
456+
cd tests # change directory to avoid importing local pydantic_core source
457+
pytest tests/benchmarks
458+
rustup run stable bash -c '$RUSTUP_HOME/toolchains/$RUSTUP_TOOLCHAIN/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-profdata merge -o ${{ github.workspace }}/merged.profdata ${{ github.workspace }}/profdata'
459+
460+
- name: build pgo-optimized wheel
461+
uses: PyO3/maturin-action@v1
462+
with:
463+
target: ${{ matrix.target }}
464+
manylinux: ${{ matrix.manylinux || 'auto' }}
465+
args: >
466+
--release
467+
--out dist
468+
--interpreter ${{ matrix.interpreter }}
469+
-- -Cprofile-use=${{ github.workspace }}/merged.profdata
470+
rust-toolchain: stable
471+
472+
- run: ${{ matrix.ls || 'ls -lh' }} dist/
389473

390474
- uses: actions/upload-artifact@v3
391475
with:
392476
name: pypi_files
393477
path: dist
394478

395479
inspect-pypi-assets:
396-
needs: [build]
480+
needs: [build, build-sdist, build-pgo]
397481
runs-on: ubuntu-latest
398482

399483
steps:
@@ -477,7 +561,7 @@ jobs:
477561
478562
test-builds-os:
479563
name: test build on ${{ matrix.os }}
480-
needs: [build]
564+
needs: [build, build-pgo]
481565

482566
strategy:
483567
fail-fast: false
@@ -506,8 +590,8 @@ jobs:
506590
- run: pytest --ignore=tests/test_docstrings.py
507591

508592
release:
509-
needs: [test-builds-arch, test-builds-os, check]
510-
if: "success() && startsWith(github.ref, 'refs/tags/')"
593+
needs: [test-builds-arch, test-builds-os, build-sdist, check]
594+
if: success() && startsWith(github.ref, 'refs/tags/')
511595
runs-on: ubuntu-latest
512596

513597
steps:

0 commit comments

Comments
 (0)