Skip to content

Commit 3966211

Browse files
committed
chore(ci): update GHA workflows to more closely match Pillow's
This fixes issues with outdated action versions and runner images in our CI workflows, and integrates cibuildwheel in a manner similar to Pillow. This increases the number of platforms and python versions for which we can build wheels and reduces the overall build time. winbuild/build_prepare.py has likewise been updated to more closely resemble the version of that file in the Pillow repository.
1 parent edb3ad3 commit 3966211

11 files changed

+589
-427
lines changed

.ci/requirements-cibw.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cibuildwheel==2.23.0

.github/workflows/lint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88

99
steps:
10-
- uses: actions/checkout@v3
10+
- uses: actions/checkout@v4
1111

1212
- uses: reviewdog/action-setup@v1
1313

.github/workflows/test.yml

+15-17
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
os: [
13-
"ubuntu-20.04",
13+
"ubuntu-22.04",
1414
"macos-13",
1515
]
1616
python-version: [
@@ -26,14 +26,14 @@ jobs:
2626
libavif-version: [ "0.11.0" ]
2727
include:
2828
- python-version: "3.9"
29-
os: "ubuntu-20.04"
29+
os: "ubuntu-22.04"
3030
libavif-version: "88d3dccda111f6ccbcccd925179f67e7d6fdf4ff"
3131
- python-version: "3.7"
3232
PYTHONOPTIMIZE: 1
3333
- python-version: "3.8"
3434
PYTHONOPTIMIZE: 2
3535
# Include new variables for Codecov
36-
- os: ubuntu-20.04
36+
- os: ubuntu-22.04
3737
codecov-flag: GHA_Ubuntu
3838
- os: macos-13
3939
codecov-flag: GHA_macOS
@@ -50,7 +50,7 @@ jobs:
5050
LIBAVIF_VERSION: ${{ matrix.libavif-version }}
5151

5252
steps:
53-
- uses: actions/checkout@v3
53+
- uses: actions/checkout@v4
5454

5555
- name: Set up Python ${{ matrix.python-version }}
5656
if: matrix.python-version != '2.7'
@@ -89,7 +89,7 @@ jobs:
8989
mkdir -p tests/errors
9090
9191
- name: Upload errors
92-
uses: actions/upload-artifact@v3
92+
uses: actions/upload-artifact@v4
9393
if: failure()
9494
with:
9595
name: errors
@@ -101,9 +101,9 @@ jobs:
101101
CODECOV_NAME: ${{ matrix.os }} Python ${{ matrix.python-version }}
102102

103103
- name: Upload coverage
104-
uses: codecov/codecov-action@v3
104+
uses: codecov/codecov-action@v5
105105
with:
106-
file: ./coverage.xml
106+
files: ./coverage.xml
107107

108108
msys:
109109
runs-on: windows-latest
@@ -117,12 +117,11 @@ jobs:
117117
env:
118118
MSYSTEM: MINGW64
119119
CHERE_INVOKING: 1
120-
SETUPTOOLS_USE_DISTUTILS: stdlib
121120

122121
timeout-minutes: 30
123122

124123
steps:
125-
- uses: actions/checkout@v3
124+
- uses: actions/checkout@v4
126125

127126
- name: Set up shell
128127
run: echo "C:\msys64\usr\bin\" >> $env:GITHUB_PATH
@@ -135,19 +134,18 @@ jobs:
135134
git \
136135
mingw-w64-x86_64-gcc \
137136
mingw-w64-x86_64-toolchain \
138-
mingw-w64-x86_64-python3-pip \
139-
mingw-w64-x86_64-python3-setuptools \
137+
mingw-w64-x86_64-python-pip \
138+
mingw-w64-x86_64-python-setuptools \
139+
mingw-w64-x86_64-python-pillow \
140+
mingw-w64-x86_64-python-pytest \
141+
mingw-w64-x86_64-python-pytest-cov \
140142
mingw-w64-x86_64-libjpeg-turbo \
141143
mingw-w64-x86_64-libtiff \
142144
mingw-w64-x86_64-libpng \
143145
mingw-w64-x86_64-openjpeg2 \
144146
mingw-w64-x86_64-zlib \
145147
mingw-w64-x86_64-libavif
146148
147-
- name: Install Dependencies
148-
run: |
149-
python3 -m pip install pytest pytest-cov pillow mock
150-
151149
- name: Build pillow-avif-plugin
152150
run: CFLAGS="-coverage" python3 -m pip install .
153151

@@ -156,9 +154,9 @@ jobs:
156154
python3 -m pytest -vx --cov pillow_avif --cov tests --cov-report term --cov-report xml tests
157155
158156
- name: Upload coverage
159-
uses: codecov/codecov-action@v3
157+
uses: codecov/codecov-action@v5
160158
with:
161-
file: ./coverage.xml
159+
files: ./coverage.xml
162160
flags: GHA_Windows
163161
name: "MSYS2 MinGW"
164162
success:
+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/bin/bash
2+
# Define custom utilities
3+
# Setup that needs to be done before multibuild utils are invoked
4+
PROJECTDIR=$(pwd)
5+
if [[ "$(uname -s)" == "Darwin" ]]; then
6+
# Safety check - macOS builds require that CIBW_ARCHS is set, and that it
7+
# only contains a single value (even though cibuildwheel allows multiple
8+
# values in CIBW_ARCHS).
9+
if [[ -z "$CIBW_ARCHS" ]]; then
10+
echo "ERROR: Pillow macOS builds require CIBW_ARCHS be defined."
11+
exit 1
12+
fi
13+
if [[ "$CIBW_ARCHS" == *" "* ]]; then
14+
echo "ERROR: Pillow macOS builds only support a single architecture in CIBW_ARCHS."
15+
exit 1
16+
fi
17+
18+
# Build macOS dependencies in `build/darwin`
19+
# Install them into `build/deps/darwin`
20+
export WORKDIR=$(pwd)/build/darwin
21+
export BUILD_PREFIX=$(pwd)/build/deps/darwin
22+
else
23+
# Build prefix will default to /usr/local
24+
export WORKDIR=$(pwd)/build
25+
export MB_ML_LIBC=${AUDITWHEEL_POLICY::9}
26+
export MB_ML_VER=${AUDITWHEEL_POLICY:9}
27+
fi
28+
export PLAT="${CIBW_ARCHS:-$AUDITWHEEL_ARCH}"
29+
30+
source multibuild/common_utils.sh
31+
source multibuild/library_builders.sh
32+
if [ -z "$IS_MACOS" ]; then
33+
source multibuild/manylinux_utils.sh
34+
fi
35+
36+
source wheelbuild/config.sh
37+
38+
function build_pkg_config {
39+
if [ -e pkg-config-stamp ]; then return; fi
40+
# This essentially duplicates the Homebrew recipe
41+
CFLAGS="$CFLAGS -Wno-int-conversion" build_simple pkg-config 0.29.2 https://pkg-config.freedesktop.org/releases tar.gz \
42+
--disable-debug --disable-host-tool --with-internal-glib \
43+
--with-pc-path=$BUILD_PREFIX/share/pkgconfig:$BUILD_PREFIX/lib/pkgconfig \
44+
--with-system-include-path=$(xcrun --show-sdk-path --sdk macosx)/usr/include
45+
export PKG_CONFIG=$BUILD_PREFIX/bin/pkg-config
46+
touch pkg-config-stamp
47+
}
48+
49+
function build {
50+
if [[ -n "$IS_MACOS" ]] && [[ "$CIBW_ARCHS" == "arm64" ]]; then
51+
sudo chown -R runner /usr/local
52+
fi
53+
pre_build
54+
}
55+
56+
if [[ -n "$IS_MACOS" ]]; then
57+
# Homebrew (or similar packaging environments) install can contain some of
58+
# the libraries that we're going to build. However, they may be compiled
59+
# with a MACOSX_DEPLOYMENT_TARGET that doesn't match what we want to use,
60+
# and they may bring in other dependencies that we don't want. The same will
61+
# be true of any other locations on the path. To avoid conflicts, strip the
62+
# path down to the bare minimum (which, on macOS, won't include any
63+
# development dependencies).
64+
export PATH="$BUILD_PREFIX/bin:$(dirname $(which python3)):/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin"
65+
export CMAKE_PREFIX_PATH=$BUILD_PREFIX
66+
67+
# Ensure the basic structure of the build prefix directory exists.
68+
mkdir -p "$BUILD_PREFIX/bin"
69+
mkdir -p "$BUILD_PREFIX/lib"
70+
71+
# Ensure pkg-config is available
72+
build_pkg_config
73+
# Ensure cmake is available
74+
python3 -m pip install cmake
75+
fi
76+
77+
# Perform all dependency builds in the build subfolder.
78+
mkdir -p $WORKDIR
79+
pushd $WORKDIR > /dev/null
80+
81+
wrap_wheel_builder build
82+
83+
# Return to the project root to finish the build
84+
popd > /dev/null

.github/workflows/wheels-test.ps1

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
param ([string]$venv, [string]$pillow_avif_plugin="C:\pillow-avif-plugin")
2+
$ErrorActionPreference = 'Stop'
3+
$ProgressPreference = 'SilentlyContinue'
4+
Set-PSDebug -Trace 1
5+
if ("$venv" -like "*\cibw-run-*\pp*-win_amd64\*") {
6+
# unlike CPython, PyPy requires Visual C++ Redistributable to be installed
7+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
8+
Invoke-WebRequest -Uri 'https://aka.ms/vs/15/release/vc_redist.x64.exe' -OutFile 'vc_redist.x64.exe'
9+
C:\vc_redist.x64.exe /install /quiet /norestart | Out-Null
10+
}
11+
$env:path += ";$pillow_avif_plugin\winbuild\build\bin\"
12+
& "$venv\Scripts\activate.ps1"
13+
& reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\python.exe" /v "GlobalFlag" /t REG_SZ /d "0x02000000" /f
14+
cd $pillow_avif_plugin
15+
& python -VV
16+
if (!$?) { exit $LASTEXITCODE }
17+
& python -m pytest -vx tests
18+
if (!$?) { exit $LASTEXITCODE }

.github/workflows/wheels-test.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
set -e
3+
4+
python3 -m pytest

0 commit comments

Comments
 (0)