unitree_sdk2_python/.github/workflows/python-package-action.yml

127 lines
5.3 KiB
YAML

# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: Python package
run-name: ${{ github.actor }} package
on:
workflow_dispatch:
inputs:
c_cyclonedds_version:
description: 'clang cyclonedds version'
required: false
default: 'releases/0.10.x'
cyclonedds_python_version:
description: cyclonedds_python的版本
required: false
default: 'releases/0.10.x'
jobs:
build:
# 输入参数定义部分
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: ["3.11"]
os: [macos-latest, windows-latest, ubuntu-latest]
steps:
# 初始化
- uses: actions/checkout@v4
# 配置python
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
# 初始化制品收集目录
- name: init dist
run: |
mkdir dist
# 准备构建python wheel包
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
# 由于cyclonedds-python暂时没有提供python3.11 顺带也编译了 issue:https://github.com/eclipse-cyclonedds/cyclonedds-python/issues/221
- name: build cyclonedds-python in windows
if: startsWith(runner.os, 'Windows')
run: |
git clone https://github.com/eclipse-cyclonedds/cyclonedds-python -b ${{ github.event.inputs.cyclonedds_python_version }} --depth=1
cd cyclonedds-python
(Get-Content pyproject.toml) -replace 'https://github.com/eclipse-cyclonedds/cyclonedds.git','https://github.com/eclipse-cyclonedds/cyclonedds -b ${{ github.event.inputs.c_cyclonedds_version }} --depth=1' | Set-Content pyproject.toml
(Get-Content pyproject.toml) -replace '(?<=^skip = ")','cp3{6..10}-* ' | Set-Content pyproject.toml
(Get-Content pyproject.toml) -replace 'delvewheel==0.0.18','delvewheel==1.6.0' | Set-Content pyproject.toml
(Get-Content setup.py) -replace '(?<="Programming Language :: Python :: 3.10",.*?)', "`n `"Programming Language :: Python :: 3.11`",`n `"Programming Language :: Python :: 3.12`",`n `"Programming Language :: Python :: 3.13`"," | Set-Content setup.py
pip install --user cibuildwheel==2.18.*
python -m cibuildwheel --output-dir wheelhouse .
tar zcvf cyclonedds.tar.gz -C cyclonedds-build .
shell: pwsh
# 兼容sed see:https://gist.github.com/andre3k1/e3a1a7133fded5de5a9ee99c87c6fa0d
- name: install GNU sed in mac
if: startsWith(runner.os, 'macOS')
run: |
brew install gnu-sed
- name: build cyclonedds-python in unix
if: startsWith(runner.os, 'Linux') || startsWith(runner.os, 'macOS')
run: |
if [ "${{ startsWith(runner.os, 'macOS') }}" ]; then
PATH="/opt/homebrew/opt/gnu-sed/libexec/gnubin:$PATH"
fi
git clone https://github.com/eclipse-cyclonedds/cyclonedds-python -b ${{ github.event.inputs.c_cyclonedds_version }} --depth=1
cd cyclonedds-python
sed -i "s~https://github.com/eclipse-cyclonedds/cyclonedds.git~https://github.com/eclipse-cyclonedds/cyclonedds -b ${{ github.event.inputs.c_cyclonedds_version }} --depth=1~g" pyproject.toml
echo "debugprintpoint1"
sed -i 's/\(^skip = "\)/\1cp3{6..10}-* /g' pyproject.toml
echo "printpoint2"
sed -i 's/delvewheel==0\.0\.18/delvewheel==1\.6\.0/g' pyproject.toml
echo "printpoint3"
sed -i 's/(?<="Programming Language :: Python :: 3.10",.*?)/\n "Programming Language :: Python :: 3.11",\n "Programming Language :: Python :: 3.12",\n "Programming Language :: Python :: 3.13",/g' setup.py
pip install --user cibuildwheel==2.18.*
python -m cibuildwheel --output-dir wheelhouse .
shell: bash
# 构建宇树python sdk本身
- name: build package unix
if: startsWith(runner.os, 'Linux') || startsWith(runner.os, 'macOS')
run: |
export CYCLONEDDS_HOME=${{ github.workspace }}/cyclonedds/install
python -m build --wheel
shell: bash
- name: build package windows
if: startsWith(runner.os, 'Windows')
run: |
set CYCLONEDDS_HOME=${{ github.workspace }}/cyclonedds/install
python -m build --wheel
shell: cmd
# 收集构建产物
- name: collect binary
if: startsWith(runner.os, 'Windows')
run: |
mv ${{ github.workspace }}/cyclonedds-python/wheelhouse/* dist/
mv ${{ github.workspace }}/dist/* dist/
- name: collect binary
if: startsWith(runner.os, 'Linux') || startsWith(runner.os, 'macOS')
run: |
# 对复杂的不同平台目录机制信息收集
find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g' > dist/${{runner.os}}_${{runner.arch}}.txt
mv -f ${{ github.workspace }}/cyclonedds-python/wheelhouse/* dist/
# mv -f ${{ github.workspace }}/dist/* dist/
# 上传到工作流制品库
- name: upload package and dependency
uses: actions/upload-artifact@v4
with:
name: unitree_sdk2_python${{ matrix.python-version }}_${{runner.os}}_${{runner.arch}}
path: |
dist/*