From e60ae09e5acb42d2b6e7cf085e61fccd5e263035 Mon Sep 17 00:00:00 2001 From: Cuiys Date: Fri, 13 Feb 2026 14:41:57 +0800 Subject: [PATCH] feat(ci): macos ci with github-runner (#94) --- .github/workflows/build_test_wheel.yml | 2 +- .github/workflows/linux_arm64_docker_ci.yml | 19 +++- .github/workflows/linux_x64_docker_ci.yml | 42 +++++--- .github/workflows/mac_arm64_ci.yml | 111 ++++++++++++-------- pyproject.toml | 11 +- tests/ailego/parallel/thread_queue_test.cc | 2 +- 6 files changed, 118 insertions(+), 69 deletions(-) diff --git a/.github/workflows/build_test_wheel.yml b/.github/workflows/build_test_wheel.yml index 65362db..918a3da 100644 --- a/.github/workflows/build_test_wheel.yml +++ b/.github/workflows/build_test_wheel.yml @@ -101,4 +101,4 @@ jobs: pip install --index-url https://test.pypi.org/simple/ zvec # Run a simple smoke test python -c "import zvec; print('Import OK:', zvec.__version__)" - shell: bash + shell: bash \ No newline at end of file diff --git a/.github/workflows/linux_arm64_docker_ci.yml b/.github/workflows/linux_arm64_docker_ci.yml index 5e02a95..4e6b61c 100644 --- a/.github/workflows/linux_arm64_docker_ci.yml +++ b/.github/workflows/linux_arm64_docker_ci.yml @@ -71,7 +71,16 @@ jobs: - name: Install dependencies run: | - ${{ env.PIP_BIN }} install --upgrade pip ruff==v0.14.4 clang-format==18.1.8 pybind11==3.0 pytest pytest-cov + ${{ env.PIP_BIN }} install --upgrade pip \ + ruff==v0.14.4 \ + clang-format==18.1.8 \ + pybind11==3.0 \ + cmake==3.30.0 \ + ninja==1.11.1 \ + pytest \ + pytest-cov \ + scikit-build-core \ + setuptools_scm shell: bash - name: Run Ruff Linter @@ -112,11 +121,11 @@ jobs: cd "$CLEAN_WORKSPACE" NPROC=$(nproc 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || echo 2) - ${{ env.PIP_BIN }} install cmake ninja - CMAKE_GENERATOR="Unix Makefiles" \ CMAKE_BUILD_PARALLEL_LEVEL="$NPROC" \ - ${{ env.PIP_BIN }} install -v . --config-settings='cmake.define.BUILD_TOOLS="ON"' + ${{ env.PIP_BIN }} install -v . \ + --no-build-isolation \ + --config-settings='cmake.define.BUILD_TOOLS="ON"' shell: bash - name: Run Python Tests with Coverage @@ -136,4 +145,4 @@ jobs: cd "$CLEAN_WORKSPACE/examples/c++" mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release make -j $(nproc) && ./db-example && ./core-example && ./ailego-example - shell: bash + shell: bash \ No newline at end of file diff --git a/.github/workflows/linux_x64_docker_ci.yml b/.github/workflows/linux_x64_docker_ci.yml index 2c5bb2f..f1fc3c7 100644 --- a/.github/workflows/linux_x64_docker_ci.yml +++ b/.github/workflows/linux_x64_docker_ci.yml @@ -46,6 +46,28 @@ jobs: echo "PIP_BIN=$PY_PATH/bin/pip" >> $GITHUB_ENV echo "CLANG_FORMATTER_BIN=$PY_PATH/bin/clang-format" >> $GITHUB_ENV $PY_PATH/bin/python --version + + # Set number of processors for parallel builds + NPROC=$(nproc 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || echo 2) + echo "NPROC=$NPROC" >> $GITHUB_ENV + echo "Using $NPROC parallel jobs for builds" + + # Add Python user base bin to PATH for pip-installed CLI tools + echo "$(python -c 'import site; print(site.USER_BASE)')/bin" >> $GITHUB_PATH + shell: bash + + - name: Install dependencies + run: | + ${{ env.PYTHON_BIN }} -m pip install --upgrade pip \ + ruff==v0.14.4 \ + clang-format==18.1.8 \ + pybind11==3.0 \ + cmake==3.30.0 \ + ninja==1.11.1 \ + pytest \ + pytest-cov \ + scikit-build-core \ + setuptools_scm shell: bash - name: Prepare clean build directory @@ -69,11 +91,6 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} shell: bash - - name: Install dependencies - run: | - ${{ env.PIP_BIN }} install --upgrade pip ruff==v0.14.4 clang-format==18.1.8 pybind11==3.0 pytest pytest-cov - shell: bash - - name: Run Ruff Linter run: | cd "$CLEAN_WORKSPACE" @@ -90,7 +107,6 @@ jobs: run: | cd "$CLEAN_WORKSPACE" - CPP_FILES=$(find . -type f \( -name "*.cpp" -o -name "*.h" -o -name "*.hpp" -o -name "*.cc" -o -name "*.cxx" \) \ ! -path "./build/*" \ ! -path "./tests/*" \ @@ -110,13 +126,11 @@ jobs: - name: Install Python dependencies and build package run: | cd "$CLEAN_WORKSPACE" - NPROC=$(nproc 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || echo 2) - - ${{ env.PIP_BIN }} install cmake ninja - CMAKE_GENERATOR="Unix Makefiles" \ CMAKE_BUILD_PARALLEL_LEVEL="$NPROC" \ - ${{ env.PIP_BIN }} install -v . --config-settings='cmake.define.BUILD_TOOLS="ON"' + ${{ env.PYTHON_BIN }} -m pip install -v . \ + --no-build-isolation \ + --config-settings='cmake.define.BUILD_TOOLS="ON"' shell: bash - name: Run Python Tests with Coverage @@ -128,12 +142,12 @@ jobs: - name: Run Cpp Tests run: | cd "$CLEAN_WORKSPACE/build" - make unittest -j$(nproc) + make unittest -j$NPROC shell: bash - name: Run Cpp Examples run: | cd "$CLEAN_WORKSPACE/examples/c++" mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release - make -j $(nproc) && ./db-example && ./core-example && ./ailego-example - shell: bash + make -j $NPROC && ./db-example && ./core-example && ./ailego-example + shell: bash \ No newline at end of file diff --git a/.github/workflows/mac_arm64_ci.yml b/.github/workflows/mac_arm64_ci.yml index 73aa922..3d549c2 100644 --- a/.github/workflows/mac_arm64_ci.yml +++ b/.github/workflows/mac_arm64_ci.yml @@ -22,24 +22,66 @@ permissions: jobs: build: name: Zvec MacArm64 CI - runs-on: mac_m1_arm + runs-on: macos-15 + + strategy: + matrix: + python-version: ['3.10'] + fail-fast: false steps: - - name: Run Ruff Linter + - name: Checkout code + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + cache: 'pip' + cache-dependency-path: 'pyproject.toml' + + - name: Set up environment variables run: | - cd "$CLEAN_WORKSPACE" - ruff check . + # Set number of processors for parallel builds + NPROC=$(sysctl -n hw.ncpu 2>/dev/null || echo 2) + echo "NPROC=$NPROC" >> $GITHUB_ENV + echo "Using $NPROC parallel jobs for builds" + + # Add Python user base bin to PATH for pip-installed CLI tools + echo "$(python -c 'import site; print(site.USER_BASE)')/bin" >> $GITHUB_PATH shell: bash - - name: Run Ruff Formatter Check (ensure code is formatted) + - name: Install dependencies run: | - cd "$CLEAN_WORKSPACE" - ruff format --check . + python -m pip install --upgrade pip \ + ruff==v0.14.4 \ + clang-format==18.1.8 \ + pybind11==3.0 \ + cmake==3.30.0 \ + ninja==1.11.1 \ + pytest \ + pytest-cov \ + scikit-build-core \ + setuptools_scm + shell: bash + + - name: Run Ruff Linter + run: | + cd "$GITHUB_WORKSPACE" + python -m ruff check . + shell: bash + + - name: Run Ruff Formatter Check + run: | + cd "$GITHUB_WORKSPACE" + python -m ruff format --check . shell: bash - name: Run clang-format Check run: | - cd "$CLEAN_WORKSPACE" + cd "$GITHUB_WORKSPACE" CPP_FILES=$(find . -type f \( -name "*.cpp" -o -name "*.h" -o -name "*.hpp" -o -name "*.cc" -o -name "*.cxx" \) \ ! -path "./build/*" \ @@ -57,57 +99,34 @@ jobs: clang-format --dry-run --Werror $CPP_FILES shell: bash - - name: Prepare clean build directory + - name: Build from source run: | - export CLEAN_WORKSPACE="/tmp/zvec" - rm -rf "$CLEAN_WORKSPACE" - mkdir -p "$CLEAN_WORKSPACE" - cd "$CLEAN_WORKSPACE" - - git config --global --add safe.directory "$CLEAN_WORKSPACE" - git clone --recursive "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" . - - if [ -n "${{ github.event.number }}" ]; then - git fetch origin "pull/${{ github.event.number }}/head" - git checkout FETCH_HEAD - else - git checkout "${{ github.sha }}" - fi - - echo "CLEAN_WORKSPACE=$CLEAN_WORKSPACE" >> $GITHUB_ENV - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - shell: bash - - - name: Install Python dependencies and build package - run: | - cd "$CLEAN_WORKSPACE" - pip install --upgrade pip pytest pytest-cov ruff - - NPROC=$(nproc 2>/dev/null || echo $(getconf _NPROCESSORS_ONLN 2>/dev/null || echo 2)) - echo "ParallelGroup: Using $NPROC parallel jobs for build" + cd "$GITHUB_WORKSPACE" CMAKE_GENERATOR="Unix Makefiles" \ CMAKE_BUILD_PARALLEL_LEVEL="$NPROC" \ - pip install -v . \ + python -m pip install -v . \ + --no-build-isolation \ --config-settings='cmake.define.BUILD_TOOLS="ON"' shell: bash + - name: Run Cpp Tests + run: | + cd "$GITHUB_WORKSPACE/build" + make unittest -j$NPROC + shell: bash + - name: Run Python Tests with Coverage run: | - cd "$CLEAN_WORKSPACE" + cd "$GITHUB_WORKSPACE" python -m pytest python/tests/ --cov=zvec --cov-report=xml --no-cov-on-fail shell: bash - - name: Run Cpp Tests with Coverage - run: | - cd "$CLEAN_WORKSPACE/build" - make unittest -j 16 - shell: bash - name: Run Cpp Examples run: | - cd "$CLEAN_WORKSPACE/examples/c++" - mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release - make -j 16 && ./db-example && ./core-example && ./ailego-example + cd "$GITHUB_WORKSPACE/examples/c++" + mkdir build && cd build + cmake .. -DCMAKE_BUILD_TYPE=Release + make -j $NPROC && ./db-example && ./core-example && ./ailego-example shell: bash diff --git a/pyproject.toml b/pyproject.toml index de14714..d77eeab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -80,7 +80,13 @@ dev = [ # BUILD SYSTEM CONFIGURATION (scikit-build-core) ###################################################################################################### [build-system] -requires = ["scikit-build-core >=0.11", "pybind11 >=3.0", "setuptools_scm>=8.0"] +requires = [ + "scikit-build-core >=0.11", + "pybind11 >=3.0", + "setuptools_scm>=8.0", + "cmake>=3.26,<4.0", + "ninja>=1.11", +] build-backend = "scikit_build_core.build" [tool.scikit-build] @@ -165,7 +171,8 @@ archs = ["auto"] test-command = "cd {project} && pytest python/tests -v --tb=short" manylinux-x86_64-image = "manylinux_2_28" manylinux-aarch64-image = "manylinux_2_28" -skip = "*musllinux*" +# Skip 32-bit builds and musllinux +skip = ["*-manylinux_i686", "*-musllinux*"] [tool.cibuildwheel.macos] archs = ["arm64"] diff --git a/tests/ailego/parallel/thread_queue_test.cc b/tests/ailego/parallel/thread_queue_test.cc index 6a18b4e..a700018 100644 --- a/tests/ailego/parallel/thread_queue_test.cc +++ b/tests/ailego/parallel/thread_queue_test.cc @@ -103,7 +103,7 @@ TEST(ThreadQueue, MultiThreadWithHighPriority) { } // Wait for all tasks to complete - std::this_thread::sleep_for(std::chrono::seconds(1)); + std::this_thread::sleep_for(std::chrono::seconds(3)); EXPECT_EQ(count, 1000); EXPECT_EQ(high_priority_count, 1000);