Skip to content

Commit

Permalink
ci: build macOS packages using cibuildwheel
Browse files Browse the repository at this point in the history
Close #1558.
  • Loading branch information
dvarrazzo committed Mar 30, 2023
1 parent daeec37 commit 97df29a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 98 deletions.
33 changes: 17 additions & 16 deletions .github/workflows/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ jobs:
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: packages_sdist
path: |
dist/*/*.tar.gz
Expand Down Expand Up @@ -95,7 +94,6 @@ jobs:
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: packages_${{ matrix.tag }}_${{ matrix.arch }}
path: |
dist/*/*${{ matrix.tag }}_${{ matrix.arch }}.whl
Expand All @@ -117,30 +115,33 @@ jobs:
build-macos:
runs-on: macos-latest
if: true

strategy:
fail-fast: false
matrix:
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10', '3.11']
# These archs require an Apple M1 runner: [arm64, universal2]
arch: [x86_64]
pyver: [cp37, cp38, cp39, cp310, cp311]

steps:
- name: Checkout repos
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Build packages
run: ./scripts/build/build_macos.sh
- name: Build wheels
uses: pypa/[email protected]
env:
PACKAGE_NAME: psycopg2-binary
PSYCOPG2_TESTDB: postgres
PSYCOPG2_TEST_FAST: 1
CIBW_BUILD: ${{matrix.pyver}}-macosx_${{matrix.arch}}
CIBW_ARCHS_MACOS: x86_64
CIBW_BEFORE_ALL_MACOS: ./scripts/build/wheel_macos_before_all.sh
CIBW_TEST_COMMAND: >-
export PYTHONPATH={project} &&
python -c "import tests; tests.unittest.main(defaultTest='tests.test_suite')"
CIBW_ENVIRONMENT: >-
PACKAGE_NAME=psycopg2-binary
PSYCOPG2_TESTDB=postgres
PSYCOPG2_TEST_FAST=1
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: packages_macos
path: |
dist/*/*${{ matrix.platform }}.whl
path: ./wheelhouse/*.whl
82 changes: 0 additions & 82 deletions scripts/build/build_macos.sh

This file was deleted.

32 changes: 32 additions & 0 deletions scripts/build/wheel_macos_before_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

# Configure the environment needed to build wheel packages on Mac OS.
# This script is designed to be used by cibuildwheel as CIBW_BEFORE_ALL_MACOS

set -euo pipefail
set -x

dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
prjdir="$( cd "${dir}/../.." && pwd )"

brew install gnu-sed postgresql@15

# Start the database for testing
brew services start postgresql

# Wait for postgres to come up
for i in $(seq 10 -1 0); do
eval pg_isready && break
if [ $i == 0 ]; then
echo "PostgreSQL service not ready, giving up"
exit 1
fi
echo "PostgreSQL service not ready, waiting a bit, attempts left: $i"
sleep 5
done

# Replace the package name
if [[ "${PACKAGE_NAME:-}" ]]; then
gsed -i "s/^setup(name=\"psycopg2\"/setup(name=\"${PACKAGE_NAME}\"/" \
"${prjdir}/setup.py"
fi

0 comments on commit 97df29a

Please sign in to comment.