forked from libcsp/libcsp
-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (88 loc) · 3.96 KB
/
build-test-publish-python.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
name: Build and test python
on: [push, pull_request]
jobs:
build-test-python:
strategy:
fail-fast: false
matrix:
os:
- ubuntu-24.04
arch:
- posix
buildsystem:
- cmake
runs-on: ${{ matrix.os }}
steps:
- name: Setup packages on Linux
run: |
sudo apt-get update
sudo apt-get install libzmq3-dev libsocketcan-dev
- name: Setup build system packages on Linux
run: |
sudo apt-get install ninja-build cmake
- name: Checkout
uses: actions/checkout@v4
- name: Build libcsp examples
run: python3 examples/buildall.py ${{ matrix.arch }} --build-system=${{ matrix.buildsystem }}
- name: Build libcsp with python binding
run: |
cmake -GNinja -B buildBinding -DCSP_ENABLE_PYTHON3_BINDINGS=1 -DCSP_USE_RTABLE=1 -DCMAKE_POSITION_INDEPENDENT_CODE=ON && ninja -C buildBinding
- name: Run ZMQ Python binding Test
run: |
build/examples/zmqproxy &
LD_LIBRARY_PATH=buildBinding PYTHONPATH=buildBinding python3 examples/python_bindings_example_server.py &
LD_LIBRARY_PATH=buildBinding PYTHONPATH=buildBinding python3 examples/python_bindings_example_client.py -z localhost -s 27 -a 2
pkill zmqproxy
- name: Prepare Python binding for packaging
run: |
mkdir -p libcsp_py3/
cp buildBinding/libcsp_py3*.so libcsp_py3/libcsp_py3-${{ matrix.os }}.so
- name: Set up Python environment
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Create and activate virtual environment
run: |
python -m venv venv
source venv/bin/activate
python -m pip install --upgrade pip
python -m pip install setuptools wheel build
- name: Build the Python package
run: |
source venv/bin/activate
python3 -m build
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
if: github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags/')
# Install the package from PyPI and run tests again
- name: Install package from PyPI
run: |
source venv/bin/activate
pip install -i https://test.pypi.org/simple/ csp-moonlight
# Verify the .so file is installed correctly
# Verify the package installation
pip show csp-moonlight
# Verify the .so file is installed correctly
# Assuming the .so file is installed in the site-packages directory
find venv/lib/python*/site-packages/ -name 'libcsp_py3*.so'
pip install -i https://test.pypi.org/simple/ csp-moonlight
find venv/lib/python*/site-packages/csp-moonlight -name '*.py'
find venv/lib/python*/site-packages/csp_moonlight -name '*.py'
find venv/lib/python*/site-packages/libcsp_py3 -name '*.py'
ls -l home/runner/work/libcsp/libcsp/venv/lib/python3.12/site-packages/libcsp_py3
ls -l home/runner/work/libcsp/libcsp/venv/lib/python3.12/site-packages/csp_moonlight
ls -l home/runner/work/libcsp/libcsp/venv/lib/python3.12/site-packages/csp-moonlight
# Test import in Python
python -c "import csp_moonlight as libcsp; print('libcsp_py3 imported successfully')"
python -c "from csp_moonlight import libcsp_py3 as libcsp; print('libcsp_py3 imported successfully')"
python -c "import libcsp_py3 as libcsp; print('libcsp_py3 imported successfully')"
continue_on_error: true
# Run again tests to test the uploaded package
#- name: Run ZMQ Python binding test with PyPI package
# run: |
# build/examples/zmqproxy &
# python3 examples/python_bindings_example_server.py &
# python3 examples/python_bindings_example_client.py -z localhost -s 27 -a 2
# pkill zmqproxy