Skip to content

Commit b4140c7

Browse files
authored
Merge pull request #165 from openzim/cibuildwheel
Better build system
2 parents cd8766f + 4054038 commit b4140c7

File tree

14 files changed

+733
-371
lines changed

14 files changed

+733
-371
lines changed

.github/workflows/release.yaml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
name: Build and upload to PyPI
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
8+
env:
9+
LIBZIM_DL_VERSION: "8.2.0"
10+
MACOSX_DEPLOYMENT_TARGET: "11.0"
11+
CIBW_ENVIRONMENT_PASS_LINUX: "LIBZIM_DL_VERSION"
12+
# APPLE_SIGNING_KEYCHAIN_PATH set in prepare keychain step
13+
APPLE_SIGNING_KEYCHAIN_PROFILE: "build-profile"
14+
APPLE_SIGNING_IDENTITY: "${{ secrets.APPLE_SIGNING_IDENTITY }}"
15+
SIGN_APPLE: "yes"
16+
17+
18+
jobs:
19+
build_wheels:
20+
environment: release
21+
name: Build wheels on ${{ matrix.os }}
22+
runs-on: ${{ matrix.os }}
23+
strategy:
24+
matrix:
25+
os: [ubuntu-20.04, macos-12] # macos-11, windows-2019
26+
27+
steps:
28+
- uses: actions/checkout@v3
29+
30+
- name: Set up QEMU
31+
if: runner.os == 'Linux'
32+
uses: docker/setup-qemu-action@v2
33+
with:
34+
platforms: all
35+
36+
- name: Prepare Apple Keychain for Signing
37+
if: matrix.os == 'macos-12'
38+
shell: bash
39+
run: |
40+
# store certificate on filesystem
41+
export CERTIFICATE="$(mktemp -d)/wmch-devid.p12"
42+
echo "${{ secrets.APPLE_SIGNING_CERTIFICATE }}" | base64 --decode -o $CERTIFICATE
43+
44+
# create a dedicated keychain
45+
export APPLE_SIGNING_KEYCHAIN_PATH="$(mktemp -d)/build.keychain"
46+
echo "APPLE_SIGNING_KEYCHAIN_PATH=${APPLE_SIGNING_KEYCHAIN_PATH}" >> "$GITHUB_ENV"
47+
security create-keychain -p mysecretpassword ${APPLE_SIGNING_KEYCHAIN_PATH}
48+
security default-keychain -s ${APPLE_SIGNING_KEYCHAIN_PATH}
49+
security unlock-keychain -p mysecretpassword ${APPLE_SIGNING_KEYCHAIN_PATH}
50+
51+
# import certificate into keychain then remove from filesystem
52+
security import ${CERTIFICATE} -k ${APPLE_SIGNING_KEYCHAIN_PATH} -P "${{ secrets.APPLE_SIGNING_P12_PASSWORD }}" -A
53+
rm $CERTIFICATE
54+
55+
# store signing credentials into the keychain
56+
security set-key-partition-list -S "apple-tool:,apple:" -s -k mysecretpassword ${APPLE_SIGNING_KEYCHAIN_PATH}
57+
security find-identity -v
58+
xcrun notarytool store-credentials \
59+
--apple-id "${{ secrets.APPLE_SIGNING_ALTOOL_USERNAME }}" \
60+
--password "${{ secrets.APPLE_SIGNING_ALTOOL_PASSWORD }}" \
61+
--team-id "${{ secrets.APPLE_SIGNING_TEAM }}" \
62+
--validate \
63+
--keychain ${APPLE_SIGNING_KEYCHAIN_PATH} \
64+
${APPLE_SIGNING_KEYCHAIN_PROFILE}
65+
66+
# disable auto-locking of keychain
67+
security set-keychain-settings ${APPLE_SIGNING_KEYCHAIN_PATH}
68+
security unlock-keychain -p mysecretpassword ${APPLE_SIGNING_KEYCHAIN_PATH}
69+
70+
- name: Build wheels
71+
uses: pypa/[email protected]
72+
73+
- name: Cleanup Apple Keychain
74+
if: matrix.os == 'macos-12'
75+
shell: bash
76+
run: |
77+
security lock-keychain ${APPLE_SIGNING_KEYCHAIN_PATH}
78+
security delete-keychain ${APPLE_SIGNING_KEYCHAIN_PATH}
79+
rm -f ${APPLE_SIGNING_KEYCHAIN_PATH}
80+
81+
- uses: actions/upload-artifact@v3
82+
with:
83+
path: ./wheelhouse/*.whl
84+
85+
build_sdist:
86+
name: Build source distribution
87+
runs-on: ubuntu-latest
88+
steps:
89+
- uses: actions/checkout@v3
90+
91+
- name: Build sdist
92+
run: pipx run build --sdist
93+
94+
- uses: actions/upload-artifact@v3
95+
with:
96+
path: dist/*.tar.gz
97+
98+
upload_pypi:
99+
needs: [build_wheels, build_sdist]
100+
runs-on: ubuntu-latest
101+
environment: release
102+
steps:
103+
- uses: actions/download-artifact@v3
104+
with:
105+
# unpacks default artifact into dist/
106+
# if `name: artifact` is omitted, the action will create extra parent dir
107+
name: artifact
108+
path: dist
109+
110+
- uses: pypa/[email protected]
111+
with:
112+
user: __token__
113+
# password: ${{ secrets.PYPI_TEST_API_TOKEN }}
114+
password: ${{ secrets.PYPI_API_TOKEN }}
115+
# uncomment for test
116+
# repository_url: https://test.pypi.org/legacy/

.github/workflows/release.yml

Lines changed: 0 additions & 157 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 17 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ name: test
22
on: [push]
33

44
env:
5-
LIBZIM_VERSION: 8.1.0
6-
LIBZIM_INCLUDE_PATH: include/zim
7-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
8-
PROFILE: 1
5+
LIBZIM_DL_VERSION: "8.2.0"
96

107
jobs:
118
lint:
@@ -16,7 +13,7 @@ jobs:
1613
- name: Set up Python ${{ matrix.python }}
1714
uses: actions/[email protected]
1815
with:
19-
python-version: "3.10"
16+
python-version: "3.11"
2017
architecture: x64
2118

2219
- name: Check formatting and linting
@@ -29,8 +26,8 @@ jobs:
2926
runs-on: ${{ matrix.os }}
3027
strategy:
3128
matrix:
32-
os: [ubuntu-20.04, macos-12]
33-
python: ["3.6.15", "3.7", "3.8", "3.9", "3.10", "3.11"]
29+
os: [ubuntu-22.04, macos-12]
30+
python: ["3.7", "3.8", "3.9", "3.10", "3.11"]
3431

3532
steps:
3633
- uses: actions/[email protected]
@@ -41,60 +38,21 @@ jobs:
4138
python-version: ${{ matrix.python }}
4239
architecture: x64
4340

44-
- name: set macOS environ
45-
if: matrix.os == 'macos-12'
46-
run: |
47-
echo LIBZIM_EXT=dylib >> $GITHUB_ENV
48-
echo LIBZIM_RELEASE=libzim_macos-x86_64-$LIBZIM_VERSION >> $GITHUB_ENV
49-
echo LIBZIM_LIBRARY_PATH=lib/libzim.8.dylib >> $GITHUB_ENV
50-
51-
- name: set linux environ
52-
if: matrix.os == 'ubuntu-20.04'
53-
run: |
54-
echo LIBZIM_EXT=so >> $GITHUB_ENV
55-
echo LIBZIM_RELEASE=libzim_linux-x86_64-$LIBZIM_VERSION >> $GITHUB_ENV
56-
echo LIBZIM_LIBRARY_PATH=lib/x86_64-linux-gnu/libzim.so.$LIBZIM_VERSION >> $GITHUB_ENV
57-
58-
- name: Cache libzim dylib & headers
59-
uses: actions/[email protected]
60-
id: cache-libzim
61-
with:
62-
path: libzim_dist
63-
key: ${{ env.LIBZIM_RELEASE }}-libzim-cache
64-
65-
- name: Download libzim dylib & headers from OpenZIM.org releases
66-
if: steps.cache-libzim.outputs.cache-hit != 'true'
67-
run: |
68-
wget -q https://download.openzim.org/release/libzim/$LIBZIM_RELEASE.tar.gz
69-
tar --extract --file=$LIBZIM_RELEASE.tar.gz
70-
mv $LIBZIM_RELEASE libzim_dist
41+
- name: Installing dependencies
42+
run: pip install -U pip setuptools build
7143

72-
- name: Link libzim dylib & headers into workspace lib and include folders
73-
run: |
74-
cp -p $GITHUB_WORKSPACE/libzim_dist/$LIBZIM_LIBRARY_PATH lib/libzim.$LIBZIM_EXT
75-
cp -p $GITHUB_WORKSPACE/libzim_dist/$LIBZIM_LIBRARY_PATH lib/
76-
ln -s $GITHUB_WORKSPACE/libzim_dist/$LIBZIM_INCLUDE_PATH include/zim
77-
export LD_LIBRARY_PATH="$PWD/lib:$LD_LIBRARY_PATH"
78-
79-
- name: update Linux shared objects cache
80-
if: matrix.os == 'ubuntu-20.04'
81-
run: |
82-
sudo ldconfig $PWD/lib
44+
- name: Building & installing for tests (with profiling)
45+
env:
46+
PROFILE: 1
47+
run: pip install -e .
8348

84-
- name: Build cython, sdist, and bdist_wheel
49+
- name: Testing
8550
run: |
86-
pip install --upgrade pip install "cython>=0.29.32,<3.0" setuptools pip wheel
87-
python3 setup.py build_ext --inplace
88-
python3 setup.py sdist bdist_wheel
89-
90-
- name: Test built package with pytest
91-
run: |
92-
pip install pytest pytest-cov
93-
pip install -e .
94-
export DYLD_LIBRARY_PATH="$PWD:$PWD/lib:$DYLD_LIBRARY_PATH"
95-
pytest --cov=libzim --cov-report=term --cov-report term-missing .
51+
pip install pytest pytest-cov cython
52+
py.test --cov=libzim --cov-report=term --cov-report term-missing .
9653
9754
- name: Upload coverage report to codecov
98-
run: |
99-
pip install codecov
100-
codecov
55+
if: matrix.os == 'ubuntu-22.04' && matrix.python == '3.11'
56+
uses: codecov/codecov-action@v3
57+
with:
58+
token: ${{ secrets.CODECOV_TOKEN }}

0 commit comments

Comments
 (0)