Skip to content

Build Mergin Plugin Packages #1273

Build Mergin Plugin Packages

Build Mergin Plugin Packages #1273

Workflow file for this run

name: Build Package
on:
push:
workflow_dispatch:
inputs:
REQUESTED_PYTHON_API_CLIENT_VER:
description: 'Python API Client version (tag, release, branch)'
required: true
default: 'master'
type: string
REQUESTED_GEODIFF_VER:
description: 'Geodiff version'
default: '2.1.1'
type: string
env:
PYTHON_API_CLIENT_VER: ${{ inputs.REQUESTED_PYTHON_API_CLIENT_VER || '0.12.0' }}
GEODIFF_VER: ${{ inputs.REQUESTED_GEODIFF_VER || '2.1.1' }}
PYTHON_VER: "38"
jobs:
build_linux_binary:
name: Extract geodiff binary linux
runs-on: ubuntu-latest
env:
PY_PLATFORM: "manylinux_2_28_x86_64"
steps:
- uses: actions/setup-python@v4
name: Install Python
- name: Download pygeodiff binaries
run: |
pip3 download --only-binary=:all: \
--python-version ${PYTHON_VER} \
--no-deps --platform ${PY_PLATFORM} \
--implementation cp \
--abi cp${PYTHON_VER} pygeodiff==${GEODIFF_VER}
unzip -o pygeodiff-$GEODIFF_VER-cp${PYTHON_VER}-cp${PYTHON_VER}-${PY_PLATFORM}.whl -d tmp || true
mkdir pygeodiff-binaries
cp tmp/pygeodiff/libpygeodiff-${GEODIFF_VER}-python.so ./pygeodiff-binaries/
- name: Patching pygeodiff binaries
run: |
# get exact name of the linked library (e.g. libsqlite3-d9e27dab.so.0.8.6)
SQLITE_LINE=$(ldd ./pygeodiff-binaries/libpygeodiff-${GEODIFF_VER}-python.so | grep libsqlite3)
SQLITE_LIB=$(echo ${SQLITE_LINE} | sed -E "s/.*(libsqlite3-[a-z0-9]+.so[\\.0-9]+).*/\\1/")
patchelf --replace-needed ${SQLITE_LIB} libsqlite3.so.0 ./pygeodiff-binaries/libpygeodiff-${GEODIFF_VER}-python.so
patchelf --remove-rpath ./pygeodiff-binaries/libpygeodiff-${GEODIFF_VER}-python.so
- uses: actions/upload-artifact@v4
with:
name: artifact-pygeodiff-linux
path: ./pygeodiff-binaries/*.so
build_windows_binaries:
name: Extract geodiff binary windows
runs-on: windows-latest
steps:
- uses: actions/setup-python@v4
name: Install Python
- name: Install deps
run: |
choco install unzip
- name: Download pygeodiff 32 binaries
run: |
pip3 download --only-binary=:all: --no-deps --platform "win32" --python-version $env:PYTHON_VER pygeodiff==$env:GEODIFF_VER
unzip -o pygeodiff-$env:GEODIFF_VER-cp$env:PYTHON_VER-cp$env:PYTHON_VER-win32.whl -d tmp32
mkdir pygeodiff-binaries
copy tmp32\pygeodiff\*.pyd pygeodiff-binaries\
- name: Download pygeodiff 64 binaries
run: |
pip3 download --only-binary=:all: --no-deps --platform "win_amd64" --python-version $env:PYTHON_VER pygeodiff==$env:GEODIFF_VER
unzip -o pygeodiff-$env:GEODIFF_VER-cp$env:PYTHON_VER-cp$env:PYTHON_VER-win_amd64.whl -d tmp64
copy tmp64\pygeodiff\*.pyd pygeodiff-binaries\
- uses: actions/upload-artifact@v4
with:
name: artifact-pygeodiff-windows
path: ./pygeodiff-binaries/*.pyd
build_macos_binaries:
name: Extract geodiff binary macos
runs-on: macos-latest
steps:
- uses: actions/setup-python@v4
name: Install Python
- name: Install deps
run: |
brew install unzip
- name: Download pygeodiff binaries (Intel)
env:
PY_PLATFORM: "macosx_10_9_x86_64"
run: |
pip3 download --only-binary=:all: --no-deps --platform ${PY_PLATFORM} --python-version ${PYTHON_VER} --implementation cp --abi cp${PYTHON_VER} pygeodiff==$GEODIFF_VER
unzip -o pygeodiff-$GEODIFF_VER-cp${PYTHON_VER}-cp${PYTHON_VER}-${PY_PLATFORM}.whl -d tmp
mkdir pygeodiff-binaries
cp tmp/pygeodiff/*.dylib ./pygeodiff-binaries/
- name: Patching pygeodiff binaries (Intel)
run: |
install_name_tool -change @loader_path/.dylibs/libsqlite3.0.dylib @rpath/libsqlite3.dylib ./pygeodiff-binaries/libpygeodiff-$GEODIFF_VER-python.dylib
OTOOL_L=$(otool -L ./pygeodiff-binaries/libpygeodiff-$GEODIFF_VER-python.dylib)
if echo "${OTOOL_L}" | grep -q loader_path
then
echo "libpygeodiff-$GEODIFF_VER-python.dylib was not patched correctly, maybe sqlite version changed??"
exit 1
fi
- name: Download pygeodiff binaries (arm64)
env:
PY_PLATFORM: "macosx_14_0_arm64"
run: |
pip3 download --only-binary=:all: --no-deps --platform ${PY_PLATFORM} --python-version ${PYTHON_VER} --implementation cp --abi cp${PYTHON_VER} pygeodiff==$GEODIFF_VER
unzip -o pygeodiff-$GEODIFF_VER-cp${PYTHON_VER}-cp${PYTHON_VER}-${PY_PLATFORM}.whl -d tmp
cp tmp/pygeodiff/libpygeodiff-$GEODIFF_VER-python.dylib ./pygeodiff-binaries/libpygeodiff-$GEODIFF_VER-python-arm64.dylib # expects that the folder is created before in the intel job
- name: Patching pygeodiff binaries (arm64)
run: |
install_name_tool -change @loader_path/.dylibs/libsqlite3.0.dylib @rpath/libsqlite3.dylib ./pygeodiff-binaries/libpygeodiff-$GEODIFF_VER-python-arm64.dylib
codesign --force --sign - ./pygeodiff-binaries/libpygeodiff-$GEODIFF_VER-python-arm64.dylib
OTOOL_L=$(otool -L ./pygeodiff-binaries/libpygeodiff-$GEODIFF_VER-python-arm64.dylib)
if echo "${OTOOL_L}" | grep -q loader_path
then
echo "libpygeodiff-$GEODIFF_VER-python-arm64.dylib was not patched correctly, maybe sqlite version changed??"
exit 1
fi
- uses: actions/upload-artifact@v4
with:
name: artifact-pygeodiff-macos
path: ./pygeodiff-binaries/*.dylib
create_plugin_package:
needs: [build_windows_binaries, build_linux_binary, build_macos_binaries]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
repository: MerginMaps/python-api-client
ref: ${{ env.PYTHON_API_CLIENT_VER }}
path: python-api-client
- name: prepare py-client dependencies
run: |
cd python-api-client
python3 setup.py sdist bdist_wheel
mkdir -p mergin/deps
# without __init__.py the deps dir may get recognized as "namespace package" in python
# and it can break qgis plugin unloading mechanism - see #126
touch mergin/deps/__init__.py
pip3 wheel -r mergin_client.egg-info/requires.txt -w mergin/deps
# special care for pygeodiff
unzip mergin/deps/pygeodiff-*.whl -d mergin/deps
# remove unncesessary files
rm -rf mergin/deps/*.dist-info
rm -rf mergin/deps/*.data
rm -rf mergin/deps/pygeodiff.libs
rm -rf mergin/deps/pygeodiff-*.whl
- name: check geodiff version in sync with python-api-client
run: |
GEODIFF_VER_FROM_CLIENT="$(geodiff="$(cat python-api-client/mergin_client.egg-info/requires.txt | grep pygeodiff)";echo ${geodiff#pygeodiff==})"
if [ "$GEODIFF_VER" != "$GEODIFF_VER_FROM_CLIENT" ]; then
echo "geodiff version defined in python-api-client requires.txt $GEODIFF_VER_FROM_CLIENT does not equal $GEODIFF_VER from the workpackage file"
exit 1; # or just warning??
fi
- name: Merge Artifacts
uses: actions/upload-artifact/merge@v4
with:
name: artifact
pattern: artifact-pygeodiff-*
delete-merged: true
- uses: actions/download-artifact@v4
with:
name: artifact
path: pygeodiff-binaries
- name: include pygeodiff deps
run: |
cp pygeodiff-binaries/* python-api-client/mergin/deps/pygeodiff
- uses: actions/checkout@v3
with:
path: qgis-mergin-plugin
- name: Calculate build number
env:
OFFFSET: 10 # offset for build number - due to previous builds ~ new builds must always have a higher number
run: |
BUILD_NUM=$GITHUB_RUN_NUMBER$((GITHUB_RUN_ATTEMPT + OFFFSET))
echo "BUILD_NUM=${BUILD_NUM}" >> $GITHUB_ENV
echo "Build number: ${BUILD_NUM}"
- name: create package
run: |
cp -r python-api-client/mergin qgis-mergin-plugin/Mergin
rsync -av --exclude='test' --exclude='/__pycache__/' --exclude='*/__pycache__/' qgis-mergin-plugin/Mergin output
# from 1 June 2024, plugins are required to include LICENSE file
cp qgis-mergin-plugin/LICENSE.txt output/Mergin/LICENSE
(cd output && zip -r9 ../mergin.zip Mergin/)
- uses: actions/upload-artifact@v4
with:
name: MM Plugin d-${{ env.BUILD_NUM }}
path: output/
- name: upload asset on tagged release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: MM Plugin r-${{ env.BUILD_NUM }}.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}