Skip to content

Build and Test

Build and Test #118

Workflow file for this run

name: Build and Test
on:
push:
branches:
- testing
- main
release:
types:
- created
workflow_dispatch:
jobs:
build_wheels:
name: Build wheels on ${{ matrix.os }}-${{ matrix.arch }}
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- runner: macos-latest
os: macos-latest
arch: arm64
deployment-target: '11.0'
extensions: pgvector pgvectorscale pgtextsearch pg_duckdb
- runner: ubuntu-latest
os: ubuntu-latest
arch: x86_64
deployment-target: ''
extensions: pgvector pgvectorscale pgtextsearch pg_duckdb
- runner: ubuntu-24.04-arm
os: ubuntu-latest
arch: aarch64
deployment-target: ''
extensions: pgvector pgvectorscale pgtextsearch pg_duckdb
- runner: windows-2022
os: windows-2022
arch: AMD64
deployment-target: ''
extensions: pgvector
steps:
- name: Configure git for LF line endings (Windows)
if: matrix.os == 'windows-2022'
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- name: Disable Windows Defender (Windows)
if: matrix.os == 'windows-2022'
run: |
Set-MpPreference -DisableRealtimeMonitoring $true
shell: powershell
continue-on-error: true
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
if: matrix.os != 'ubuntu-latest'
with:
python-version: '3.12'
- uses: actions/setup-python@v4
if: matrix.os == 'ubuntu-latest'
# for testing due to docker env issues
with:
python-version: '3.12'
- name: Install cibuildwheel
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade cibuildwheel
- name: Restore postgres build from cache
if: ${{ matrix.os != 'ubuntu-latest' }}
id: restore-postgres
uses: actions/cache/restore@v3
env:
cache-name: cache-postgres
with:
path: |
pgbuild
src/pgembed/pginstall
key: ${{ runner.os }}-${{ runner.arch }}-build-${{ env.cache-name }}-${{
hashFiles('Makefile', 'pgbuild/Makefile', '.github/workflows/build-and-test.yml') }}
- name: Install bison (Windows)
if: matrix.os == 'windows-2022'
run: |
choco install winflexbison3
echo "C:\\ProgramData\\chocolatey\\lib\\winflexbison3\\tools" >> $env:GITHUB_PATH
# Create symlinks so build tools can find bison/flex
New-Item -ItemType SymbolicLink -Path "C:\\ProgramData\\chocolatey\\bin\\bison.exe" -Target "C:\\ProgramData\\chocolatey\\lib\\winflexbison3\\tools\\win_bison.exe"
New-Item -ItemType SymbolicLink -Path "C:\\ProgramData\\chocolatey\\bin\\flex.exe" -Target "C:\\ProgramData\\chocolatey\\lib\\winflexbison3\\tools\\win_flex.exe"
# Set BISON_PKGDATADIR to the correct data directory
echo "BISON_PKGDATADIR=C:\\ProgramData\\chocolatey\\lib\\winflexbison3\\tools\\data" >> $env:GITHUB_ENV
- name: Install Rust
if: matrix.os != 'ubuntu-latest'
run: |
rustup install 1.88.0
rustup default 1.88.0
- name: Install ccache
if: matrix.os != 'ubuntu-latest'
shell: bash
run: |
if [ "${{ matrix.os }}" = "macos-latest" ]; then
brew install ccache
elif [ "${{ matrix.os }}" = "windows-2022" ]; then
choco install ccache
fi
- name: Install tools and libs (macOS)
if: matrix.os == 'macos-latest'
run: |
brew install jq lz4 openssl
- name: Install tools and libs (Windows)
if: matrix.os == 'windows-2022'
run: |
choco install jq
- name: Build postgres and base extensions
if: ${{ matrix.os != 'ubuntu-latest' && ! steps.restore-postgres.outputs.cache-hit }}
shell: bash
env:
MACOSX_DEPLOYMENT_TARGET: ${{ matrix.deployment-target }}
EXTENSIONS: ${{ matrix.extensions }}
run: |
INSTALL_BIN="$(pwd)/src/pgembed/pginstall/bin"
if [ "${{ matrix.os }}" = "macos-latest" ]; then
export PATH="$INSTALL_BIN:$HOME/.cargo/bin:/opt/homebrew/opt/ccache/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/lib -lssl -lcrypto"
export IS_MUSL=0
cargo install cargo-pgrx --version 0.16.1 --locked
elif [ "${{ matrix.os }}" = "windows-2022" ]; then
export PATH="$INSTALL_BIN:$USERPROFILE/.cargo/bin:C:\ProgramData\chocolatey\lib\ccache\tools\ccache-${{ matrix.arch }}-windows:$PATH"
export IS_MUSL=0
fi
make
- name: Save postgres build
if: ${{ matrix.os != 'ubuntu-latest' && ! steps.restore-postgres.outputs.cache-hit }}
id: cache-postgres
uses: actions/cache/save@v3
env:
cache-name: cache-postgres
with:
path: |
pgbuild
src/pgembed/pginstall
key: ${{ runner.os }}-${{ runner.arch }}-build-${{ env.cache-name }}-${{
hashFiles('Makefile', 'pgbuild/Makefile', '.github/workflows/build-and-test.yml') }}
- name: Build wheels
env:
CIBW_ARCHS: ${{ matrix.arch }}
CIBW_BUILD: cp310-* cp311-* cp312-* cp313-* cp314-*
CIBW_MANYLINUX: manylinux_2_39
CIBW_BEFORE_ALL_WINDOWS: |
choco install llvm cmake ninja
export IS_MUSL=0
cargo install cargo-pgrx --version 0.16.1 --locked
make
make EXTENSIONS=pg_search
CIBW_BEFORE_ALL_MACOS: |
brew install jq llvm cmake ninja lz4 openssl
export IS_MUSL=0
cargo install cargo-pgrx --version 0.16.1 --locked
make
make EXTENSIONS=pg_search
CIBW_BEFORE_ALL_LINUX: |
set -e
if command -v apk &> /dev/null; then
apk add --no-cache ccache jq gcc openssl openssl-dev openssl-libs-static llvm-dev clang-dev clang-libs clang-static pkgconfig flex bison
apk add --no-cache cmake ninja build-base lz4-dev lz4-static curl-dev curl-static glib-dev glib-static zlib-static bzip2-static findutils
elif command -v yum &> /dev/null; then
yum install -y ccache jq gcc openssl-devel llvm-devel clang-devel pkg-config
yum install -y cmake ninja-build lz4-devel libcurl-devel glib2-devel
elif command -v apt-get &> /dev/null; then
apt-get update
apt-get install -y ccache jq gcc libssl-dev llvm-dev clang-dev pkg-config
apt-get install -y cmake ninja-build liblz4-dev libcurl4-openssl-dev libglib2.0-dev
fi
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.88.0
export PATH="$HOME/.cargo/bin:/usr/lib/ccache:$PATH"
rustup default 1.88.0
cargo install cargo-pgrx --version 0.16.1 --locked
if command -v ldd &> /dev/null && ldd --version 2>&1 | grep -qi musl; then
export IS_MUSL=1
else
export IS_MUSL=0
fi
if [ "$(uname -m)" = "x86_64" ]; then
export RUSTFLAGS="-C target-feature=+avx2,+fma"
fi
make
if [ "$IS_MUSL" != "1" ]; then
make EXTENSIONS=pg_search
else
echo "Skipping pg_search build on musl libc"
fi
CIBW_ENVIRONMENT_LINUX: PATH="$HOME/.cargo/bin:$PATH:/project/src/pgembed/pginstall/bin"
CIBW_ENVIRONMENT_MUSLLINUX: LIBCLANG_STATIC_PATH=/usr/lib
CIBW_ENVIRONMENT_MANYLINUX: LIBCLANG_PATH=/usr/lib64
CIBW_ENVIRONMENT_MACOS: PATH="$PWD/src/pgembed/pginstall/bin:$HOME/.cargo/bin:/opt/homebrew/opt/ccache/bin:$PATH" LDFLAGS="-L/opt/homebrew/lib -lssl -lcrypto" MACOSX_DEPLOYMENT_TARGET=15.0 BINDGEN_EXTRA_CLANG_ARGS="$(pg_config --cppflags) -I$(xcrun --show-sdk-path)/usr/include -I/opt/homebrew/include"
CIBW_TEST_COMMAND_WINDOWS: true # Tests disabled pending issues with executing binaries built
CIBW_ENVIRONMENT_WINDOWS: PATH="$PWD\\src\\pgembed\\pginstall\\bin;$USERPROFILE\\.cargo\\bin;C:\\ProgramData\\chocolatey\\lib\\ccache\\tools\\ccache-AMD64-windows;$PATH" LIBCLANG_PATH="C:\\Program Files\\LLVM\\bin"
MACOSX_DEPLOYMENT_TARGET: ${{ matrix.deployment-target }}
run: python -m cibuildwheel --output-dir wheelhouse
- name: Save postgres build
if: ${{ matrix.os == 'ubuntu-latest' && ! steps.restore-postgres.outputs.cache-hit }}
id: cache-postgres2
uses: actions/cache/save@v3
env:
cache-name: cache-postgres
with:
path: |
pgbuild
src/pgembed/pginstall
key: ${{ runner.os }}-${{ runner.arch }}-build-${{ env.cache-name }}-${{
hashFiles('Makefile', 'pgbuild/Makefile', '.github/workflows/build-and-test.yml') }}
- uses: actions/upload-artifact@v4
with:
path: wheelhouse/*.whl
name: python-package-distributions-${{ matrix.os }}-${{ matrix.arch }}
overwrite: true
publish-to-pypi:
if: ${{ startsWith(github.ref, 'refs/tags/') }}
name: Publish Python dist to PyPI
needs:
- build_wheels
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/pgembed
permissions:
id-token: write
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
pattern: python-package-distributions-*
path: dist/
merge-multiple: true
- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1