Send heartbeat to start MAVLink #66
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow will upload a Python Package using Twine when a release is created | |
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries | |
name: Build and Optionally Publish | |
on: | |
push: | |
pull_request: | |
workflow_dispatch: | |
release: | |
types: [published] | |
concurrency: | |
group: ci-${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
prepare: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
steps: | |
# This allows us to save the more expensive full build for the main branch | |
# and releases, while using a lighter build for PRs | |
- name: Set build matrix | |
id: set-matrix | |
shell: python | |
run: | | |
import json | |
import os | |
ref = os.environ.get("GITHUB_REF", "") | |
event = os.environ.get("GITHUB_EVENT_NAME", "") | |
if ref in ("refs/heads/main", "refs/heads/master") or event in ("release", "workflow_dispatch"): | |
machines = [ | |
("linux", "ubuntu-latest", "auto"), | |
("linux-arm", "ubuntu-24.04-arm", "auto"), | |
("macos", "macos-latest", "arm64 x86_64 universal2"), | |
("windows", "windows-latest", "auto"), | |
# ("windows-arm", "windows-11-arm", "auto"), # Can't do this one yet, as lxml doesn't have Windows ARM wheels, and the runner doesn't have libxml2 pre-installed | |
] | |
py_versions = ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] | |
else: | |
machines = [ | |
("linux", "ubuntu-latest", "native"), | |
("windows", "windows-latest", "native"), | |
] | |
py_versions = ["3.8", "3.13"] # Chosing the two most likely to break in PRs | |
matrix = {"include": []} | |
for (name, runner, cibw_archs) in machines: | |
for py in py_versions: | |
matrix["include"].append({ | |
"name": f"python{py}-{name}", | |
"os": runner, | |
"python_version": py, | |
"cibw_build": f"cp{py.replace('.', '')}-*", | |
"cibw_archs": cibw_archs, | |
}) | |
with open(os.environ["GITHUB_OUTPUT"], "a") as f: | |
f.write(f"matrix={json.dumps(matrix)}\n") | |
build-wheels: | |
needs: prepare | |
strategy: | |
fail-fast: false | |
matrix: ${{ fromJson(needs.prepare.outputs.matrix) }} | |
name: ${{ matrix.name }} | |
runs-on: ${{ matrix.os }} | |
env: | |
PYTHON_VERSION: ${{ matrix.python_version }} | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Install mavlink definitions | |
shell: bash | |
run: | | |
git clone https://github.com/ArduPilot/mavlink.git | |
ln -s $PWD/mavlink/message_definitions | |
- name: Set CIBW_BUILD | |
shell: bash | |
run: echo "CIBW_BUILD=cp${PYTHON_VERSION/./}-*" >> $GITHUB_ENV | |
- name: Build wheels | |
uses: pypa/[email protected] | |
env: | |
PYMAVLINK_FAST_INDEX: "1" | |
CIBW_BUILD: ${{ matrix.cibw_build }} | |
CIBW_ARCHS: ${{ matrix.cibw_archs }} | |
CIBW_BEFORE_BUILD_LINUX: > | |
if [ "$(uname -m)" = "i686" ] && grep -q musl /lib/libc.musl-*; then | |
apk add --no-cache libxml2-dev libxslt-dev; | |
fi | |
- name: Upload wheels | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ matrix.name }} | |
path: wheelhouse/*.whl | |
if-no-files-found: error | |
build-sdist: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: "3.9" | |
- name: Install mavlink messages | |
run: | | |
git clone https://github.com/ArduPilot/mavlink.git | |
ln -s $PWD/mavlink/message_definitions | |
- name: Install dependencies | |
run: | | |
python3 -m pip install -U pip | |
python3 -m pip install -U wheel | |
python3 -m pip install build | |
python3 -m pip install -U . | |
- name: Build sdist | |
run: pipx run build --sdist | |
- name: Upload sdist | |
uses: actions/upload-artifact@v4 | |
with: | |
name: sdist | |
path: dist/*.tar.gz | |
if-no-files-found: error | |
publish: | |
needs: [build-wheels, build-sdist] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download all artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
path: dist | |
merge-multiple: true | |
- name: Verify dist contents | |
run: ls -lh dist/ | |
- name: Upload final dist artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: dist | |
path: dist/* | |
if-no-files-found: error | |
- name: Publish package | |
if: github.event_name == 'release' && github.event.action == 'published' | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
user: __token__ | |
password: ${{ secrets.PYPI_API_TOKEN }} |