Simplified the Python version detection. Now all builds include dev information.

This commit is contained in:
Kevin Dewald 2025-04-13 22:37:14 -07:00
parent e1934d8551
commit e25007d62a
11 changed files with 55 additions and 437 deletions

View File

@ -1,139 +0,0 @@
name: CI Linux
on:
workflow_dispatch:
workflow_call: # This allows it to be called from ci_main.yml
jobs:
# tests:
# runs-on: ubuntu-22.04
# steps:
# - name: Clone Repository
# uses: actions/checkout@v4
# - name: Install Dependencies
# env:
# DEBIAN_FRONTEND: noninteractive
# run: |
# sudo -H apt-get update -y
# sudo -H apt-get install -y dbus libdbus-1-dev python3-dev
# - name: Setup cmake
# uses: ./.github/actions/setup-cmake
# - name: Setup gtest
# uses: ./.github/actions/setup-gtest
# - name: Start DBus
# run: |
# echo "DBUS_SESSION_BUS_ADDRESS=$(dbus-daemon --config-file=/usr/share/dbus-1/session.conf --print-address --fork | cut -d, -f1)" >> $GITHUB_ENV
# - name: SimpleBLE Unit Tests
# run: |
# cmake -B $GITHUB_WORKSPACE/build_unit_simpleble -DCMAKE_BUILD_TYPE=Release -DGTEST_ROOT=$GITHUB_WORKSPACE/googletest/install -S $GITHUB_WORKSPACE/simpleble -DSIMPLEBLE_TEST=ON
# cmake --build $GITHUB_WORKSPACE/build_unit_simpleble --config Release --parallel 4
# $GITHUB_WORKSPACE/build_unit_simpleble/bin/simpleble_test
examples:
runs-on: ubuntu-22.04
steps:
- name: Clone Repository
uses: actions/checkout@v4
- name: Install Dependencies
run: |
sudo -H apt-get update -y
sudo -H apt-get install -y libdbus-1-dev
env:
DEBIAN_FRONTEND: noninteractive
- name: Setup cmake
uses: ./.github/actions/setup-cmake
- name: Compile SimpleBLE Examples for Ubuntu
run: |
cmake -B $GITHUB_WORKSPACE/build_simpleble_examples -DCMAKE_BUILD_TYPE=Release -S $GITHUB_WORKSPACE/examples/simpleble
cmake --build $GITHUB_WORKSPACE/build_simpleble_examples --config Release --parallel 4
# build:
# runs-on: ubuntu-22.04
# needs: [tests, examples]
# strategy:
# fail-fast: false
# max-parallel: 4
# matrix:
# # For testing purposes only static libraries are built to reduce run time.
# # In release workflow all combinations are build.
# options: [
# {container: dockcross/linux-x64, target: linux-x64},
# {container: dockcross/linux-x86, target: linux-x86},
# {container: dockcross/linux-armv6-lts, target: linux-armv6},
# ]
# type: [static]
# container:
# image: ${{ matrix.options.container }}
# steps:
# - name: Clone repository
# uses: actions/checkout@v4
# - name: Build DBus
# uses: ./.github/actions/build-dbus
# with:
# os: ${{ runner.os }}
# arch: ${{ matrix.options.target }}
# - name: Build SimpleBLE Library using Action
# uses: ./.github/actions/build-native-linux
# with:
# source-dir: "$(pwd)/simpleble"
# build-dir: "$(pwd)/build_simpleble"
# install-prefix: "$(pwd)/build_simpleble/install"
# library-type: ${{ matrix.type }}
# build-config: 'Release'
# target-name: 'simpleble'
# # NOTE: The build step requires us to extend the CMAKE_FIND_ROOT_PATH to include the dbus install path,
# # as cross-compilation environments will ignore CMAKE_PREFIX_PATH.
# cmake-options: "-DCMAKE_FIND_ROOT_PATH='${CMAKE_FIND_ROOT_PATH};/tmp/install/dbus'"
# - name: Package Artifact
# shell: bash
# run: |
# mkdir -p {{ github.workspace }}/artifacts
# zip -r {{ github.workspace }}/artifacts/simpleble_${{ matrix.type }}_${{ matrix.options.target }}.zip {{ github.workspace }}/build_simpleble/install
# - name: Upload binaries to job
# uses: actions/upload-artifact@v4
# with:
# name: simpleble_${{ matrix.type }}_${{ matrix.options.target }}
# path: artifacts/simpleble_${{ matrix.type }}_${{ matrix.options.target }}.zip
# python:
# needs: [tests, examples]
# uses: ./.github/workflows/ci_wheels.yml
# secrets: inherit
# with:
# os: ubuntu-22.04
# rust:
# runs-on: ${{ matrix.os }}
# needs: [tests, examples]
# strategy:
# fail-fast: false
# max-parallel: 4
# matrix:
# os: [ubuntu-20.04, ubuntu-22.04]
# steps:
# - name: Clone Repository
# uses: actions/checkout@v4
# - name: Install Dependencies
# run: |
# sudo -H apt-get update -y
# sudo -H apt-get install -y libdbus-1-dev
# env:
# DEBIAN_FRONTEND: noninteractive
# - name: Setup cmake
# uses: ./.github/actions/setup-cmake
# - name: Install Rust
# uses: dtolnay/rust-toolchain@stable
# - name: Compile SimpleBLE
# run: cargo build

View File

@ -1,105 +0,0 @@
name: CI Macos
on:
workflow_dispatch:
workflow_call: # This allows it to be called from ci_main.yml
jobs:
# tests:
# runs-on: macos-14
# steps:
# - name: Clone Repository
# uses: actions/checkout@v4
# - name: Setup cmake
# uses: ./.github/actions/setup-cmake
# - name: Setup gtest
# uses: ./.github/actions/setup-gtest
# - name: Compile Tests for MacOS arm64
# run: |
# cmake -B $GITHUB_WORKSPACE/build_test -DCMAKE_OSX_DEPLOYMENT_TARGET=11 -DCMAKE_BUILD_TYPE=Release -DGTEST_ROOT=$GITHUB_WORKSPACE/googletest/install -S $GITHUB_WORKSPACE/simpleble -DSIMPLEBLE_TEST=ON
# cmake --build $GITHUB_WORKSPACE/build_test --config Release --parallel 4
# $GITHUB_WORKSPACE/build_test/bin/simpleble_test
examples:
runs-on: macos-14
steps:
- name: Clone Repository
uses: actions/checkout@v4
- name: Setup Cmake
uses: ./.github/actions/setup-cmake
- name: Compile Examples
run: |
cmake -B $GITHUB_WORKSPACE/build -DCMAKE_BUILD_TYPE=Release -S $GITHUB_WORKSPACE/examples/simpleble
cmake --build $GITHUB_WORKSPACE/build --config Release --parallel 4
# build:
# runs-on: macos-14
# needs: [tests, examples]
# strategy:
# fail-fast: false
# max-parallel: 4
# matrix:
# # For testing purposes only static libraries are built to reduce run time.
# # In release workflow all combinations are build.
# type: [static]
# arch: [arm64, x86_64]
# steps:
# - name: Clone repository
# uses: actions/checkout@v4
# - name: Setup CMake
# uses: ./.github/actions/setup-cmake
# - name: Compile SimpleBLE
# run: |
# if [ "${{ matrix.type }}" == "shared" ]; then
# BUILD_SHARED_LIBS=ON
# else
# BUILD_SHARED_LIBS=OFF
# fi
# cmake -B $GITHUB_WORKSPACE/build -DCMAKE_OSX_ARCHITECTURES="${{ matrix.arch }}" -DCMAKE_BUILD_TYPE=Release -S $GITHUB_WORKSPACE/simpleble -DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS
# cmake --build $GITHUB_WORKSPACE/build --config Release --parallel 4
# cmake --install $GITHUB_WORKSPACE/build --prefix $GITHUB_WORKSPACE/build/install
# mkdir -p $GITHUB_WORKSPACE/artifacts
# zip -r $GITHUB_WORKSPACE/artifacts/simpleble_${{ matrix.type }}_macos-${{ matrix.arch }}.zip $GITHUB_WORKSPACE/build/install
# - name: Upload binaries to job
# uses: actions/upload-artifact@v4
# with:
# name: simpleble_${{ matrix.type }}_macos-${{ matrix.arch }}
# path: artifacts/simpleble_${{ matrix.type }}_macos-${{ matrix.arch }}.zip
# python:
# needs: [tests, examples]
# uses: ./.github/workflows/ci_wheels.yml
# secrets: inherit
# with:
# os: macos-14
# rust:
# runs-on: ${{ matrix.os }}
# needs: [tests, examples]
# strategy:
# fail-fast: false
# max-parallel: 4
# matrix:
# os: [macos-14]
# arch: [arm64, x86_64]
# steps:
# - name: Clone Repository
# uses: actions/checkout@v4
# - name: Setup cmake
# uses: ./.github/actions/setup-cmake
# - name: Install Rust
# uses: dtolnay/rust-toolchain@stable
# - name: Compile SimpleBLE
# run: cargo build

View File

@ -225,16 +225,6 @@ jobs:
needs: [smoketest]
uses: ./.github/workflows/ci_simplersble.yml
# windows:
# needs: [smoketest]
# if: needs.targets.outputs.windows == 'true'
# uses: ./.github/workflows/ci_windows.yml
# linux:
# needs: [smoketest]
# if: needs.targets.outputs.linux == 'true'
# uses: ./.github/workflows/ci_linux.yml
linux-internals:
needs: [smoketest]
if: needs.targets.outputs.linux == 'true'
@ -242,11 +232,6 @@ jobs:
with:
libraries: ${{ needs.libraries.outputs.values }}
# macos:
# needs: [smoketest]
# if: needs.targets.outputs.macos == 'true'
# uses: ./.github/workflows/ci_macos.yml
python:
needs: [smoketest]
if: needs.targets.outputs.python == 'true'

View File

@ -25,6 +25,12 @@ jobs:
steps:
- name: Clone Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Add Version Suffix
uses: ./.github/actions/setup-version
- name: Build SimpleBLE Library (Static)
uses: ./.github/actions/build-native
@ -76,6 +82,12 @@ jobs:
steps:
- name: Clone Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Add Version Suffix
uses: ./.github/actions/setup-version
- name: Build SimpleBLE Examples
uses: ./.github/actions/build-native

View File

@ -25,6 +25,12 @@ jobs:
steps:
- name: Clone Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Add Version Suffix
uses: ./.github/actions/setup-version
- name: Build SimpleCBLE Library (Static)
uses: ./.github/actions/build-native

View File

@ -21,6 +21,12 @@ jobs:
steps:
- name: Clone Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Add Version Suffix
uses: ./.github/actions/setup-version
- name: Set up JDK 17
uses: actions/setup-java@v4
@ -59,6 +65,12 @@ jobs:
steps:
- name: Clone Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Add Version Suffix
uses: ./.github/actions/setup-version
- name: Set up JDK 17
uses: actions/setup-java@v4

View File

@ -16,6 +16,9 @@ jobs:
fetch-depth: 0
fetch-tags: true
- name: Add Version Suffix
uses: ./.github/actions/setup-version
- name: Set up Python
uses: actions/setup-python@v5
with:
@ -59,6 +62,9 @@ jobs:
fetch-depth: 0
fetch-tags: true
- name: Add Version Suffix
uses: ./.github/actions/setup-version
- name: Set up QEMU
if: matrix.config.os == 'linux'
uses: docker/setup-qemu-action@v2

View File

@ -25,6 +25,12 @@ jobs:
steps:
- name: Clone Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Add Version Suffix
uses: ./.github/actions/setup-version
- name: Install Dependencies
run: |

View File

@ -20,6 +20,12 @@ jobs:
steps:
- name: Clone Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Add Version Suffix
uses: ./.github/actions/setup-version
- name: Build SimpleBLE Library
uses: ./.github/actions/build-native
@ -45,6 +51,12 @@ jobs:
- name: Clone Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Add Version Suffix
uses: ./.github/actions/setup-version
- name: Set up JDK 17
uses: actions/setup-java@v4

View File

@ -1,87 +0,0 @@
name: CI Windows
on:
workflow_dispatch:
workflow_call: # This allows it to be called from ci_main.yml
jobs:
# tests:
# runs-on: windows-2022
# steps:
# - name: Clone Repository
# uses: actions/checkout@v4
# - name: Add msbuild to PATH
# uses: microsoft/setup-msbuild@v1.1
# - name: Setup gtest
# uses: ./.github/actions/setup-gtest
# - name: Compile Tests for Windows x86
# run: |
# cmake -B %GITHUB_WORKSPACE%\build_test -G "Visual Studio 17 2022" -DCMAKE_SYSTEM_VERSION=10.0.22000.0 -DGTEST_ROOT=%GITHUB_WORKSPACE%\googletest\install -S %GITHUB_WORKSPACE%/simpleble -DSIMPLEBLE_TEST=ON
# cmake --build %GITHUB_WORKSPACE%\build_test --config Release --parallel 4
# %GITHUB_WORKSPACE%\build_test\bin\Release\simpleble_test.exe
# shell: cmd
examples:
runs-on: windows-2022
steps:
- name: Clone Repository
uses: actions/checkout@v4
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.1
- name: Compile Examples
run: |
cmake -B %GITHUB_WORKSPACE%\build -G "Visual Studio 17 2022" -DCMAKE_SYSTEM_VERSION=10.0.22000.0 -S %GITHUB_WORKSPACE%/examples/simpleble
cmake --build %GITHUB_WORKSPACE%\build --config Release --parallel 4
shell: cmd
# build:
# runs-on: windows-2022
# needs: [tests, examples]
# strategy:
# fail-fast: false
# max-parallel: 4
# matrix:
# # For testing purposes only static libraries are built to reduce run time.
# # In release workflow all combinations are build.
# arch: [Win32, x64]
# type: [static]
# steps:
# - name: Clone repository
# uses: actions/checkout@v4
# - name: Add msbuild to PATH
# uses: microsoft/setup-msbuild@v1.1
# - name: Compile SimpleBLE
# shell: cmd
# run: |
# if "${{ matrix.type }}" == "shared" (
# set BUILD_SHARED_LIBS=ON
# ) else (
# set BUILD_SHARED_LIBS=OFF
# )
# cmake -B %GITHUB_WORKSPACE%\build -G "Visual Studio 17 2022" -A ${{ matrix.arch }} -DCMAKE_SYSTEM_VERSION="10.0.19041.0" -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=%BUILD_SHARED_LIBS% -S %GITHUB_WORKSPACE%/simpleble
# cmake --build %GITHUB_WORKSPACE%\build --config Release --parallel 4
# cmake --install %GITHUB_WORKSPACE%\build --prefix %GITHUB_WORKSPACE%\build\install
# mkdir -p $GITHUB_WORKSPACE\artifacts
# 7z a -tzip %GITHUB_WORKSPACE%\artifacts\simpleble_${{ matrix.type }}_windows-${{ matrix.arch }}.zip %GITHUB_WORKSPACE%\build\install
# - name: Upload binaries to job
# uses: actions/upload-artifact@v4
# with:
# name: simpleble_${{ matrix.type }}_windows-${{ matrix.arch }}
# path: artifacts/simpleble_${{ matrix.type }}_windows-${{ matrix.arch }}.zip
# python:
# needs: [tests, examples]
# uses: ./.github/workflows/ci_wheels.yml
# secrets: inherit
# with:
# os: windows-2022

View File

@ -1,13 +1,10 @@
import argparse
import os
import pathlib
import subprocess
import sys
from pathlib import Path
import pybind11
import skbuild
from setuptools.command.sdist import sdist
def exclude_unnecessary_files(cmake_manifest):
@ -23,72 +20,6 @@ def exclude_unnecessary_files(cmake_manifest):
return list(filter(is_necessary, cmake_manifest))
def is_git_repo():
try:
subprocess.check_output(
["git", "rev-parse", "--git-dir"], stderr=subprocess.DEVNULL
)
return True
except (subprocess.SubprocessError, FileNotFoundError):
return False
def get_commit_since_hash(hash_cmd):
result = subprocess.run(hash_cmd.split(" "), capture_output=True, text=True)
if result.returncode != 0:
raise RuntimeError(f"Failed to get hash: {result.stderr}")
hash = result.stdout.strip()
if not hash:
raise RuntimeError("Empty hash")
count_cmd = f"git rev-list --count {hash}..HEAD"
result = subprocess.run(count_cmd.split(" "), capture_output=True, text=True)
if result.returncode == 0:
return int(result.stdout.strip())
else:
raise RuntimeError(f"Failed to count commits since last hash: {result.stderr}")
def get_commits_since_last_tag():
return get_commit_since_hash("git describe --tags --abbrev=0")
def get_commits_since_version_bump():
return get_commit_since_hash("git log -1 --format=%H -- VERSION")
def is_current_commit_tagged():
result = subprocess.run(
["git", "describe", "--exact-match", "--tags", "HEAD"],
capture_output=True,
text=True,
)
if result.returncode == 0:
return True, result.stdout.strip()
else:
return False, None
def get_version():
root = Path(__file__).parent
version_str = (root / "VERSION").read_text(encoding="utf-8").strip()
if is_git_repo():
is_tagged, tag = is_current_commit_tagged()
if not is_tagged:
N = get_commits_since_version_bump()
if N > 0:
version_str += f".dev{N - 1}"
# If we are not in a git repo and running from a source distribution, the VERSION
# file has already been updated with the corresponding dev version if necessary.
return version_str
argparser = argparse.ArgumentParser(add_help=False)
argparser.add_argument(
"--plain", help="Use Plain SimpleBLE", required=False, action="store_true"
@ -97,7 +28,7 @@ args, unknown = argparser.parse_known_args()
sys.argv = [sys.argv[0]] + unknown
root = pathlib.Path(__file__).parent.resolve()
version_str = get_version()
version_str = (root / "VERSION").read_text(encoding="utf-8").strip()
# Get the long description from the README file
long_description = (root / "simplepyble" / "README.rst").read_text(encoding="utf-8")
@ -117,24 +48,6 @@ if args.plain:
if "PIWHEELS_BUILD" in os.environ:
cmake_options.append("-DLIBFMT_VENDORIZE=OFF")
class CustomSdist(sdist):
def make_release_tree(self, base_dir, files):
# First, let the parent class create the release tree
super().make_release_tree(base_dir, files)
version = get_version()
if "dev" in version:
# Dev versions are generated dynamically.
# Update the VERSION file in the release tree
# so it matches the one published on PyPi
version_file = Path(base_dir) / "VERSION"
if version_file.exists():
version_file.write_text(version + "\n", encoding="utf-8")
print(f"Updated VERSION file in sdist to: {version}")
skbuild.setup(
name="simplepyble",
version=version_str,
@ -173,7 +86,4 @@ skbuild.setup(
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3 :: Only",
],
cmdclass={
"sdist": CustomSdist,
},
)