Skip to content

fix: 修复 CI 中 PyCANDYAlgo 导入测试的语法错误 #41

fix: 修复 CI 中 PyCANDYAlgo 导入测试的语法错误

fix: 修复 CI 中 PyCANDYAlgo 导入测试的语法错误 #41

Workflow file for this run

name: Build and Test
on:
push:
branches: [ main, main-dev, test ]
pull_request:
branches: [ main, main-dev, test ]
workflow_dispatch: # 允许手动触发
jobs:
test-deployment:
runs-on: ubuntu-22.04
# test 分支做快速测试,main 和 main-dev 做完整测试
# 所有分支都跳过 VSAG(通过 CI 环境变量自动处理)
env:
FAST_BUILD: ${{ github.ref == 'refs/heads/test' && 'true' || 'false' }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive # 初始化所有 submodules
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Cache pip packages
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Cache CMake build
uses: actions/cache@v4
with:
path: |
algorithms_impl/build
algorithms_impl/faiss/build
algorithms_impl/SPTAG/Release
algorithms_impl/DiskANN/build
key: ${{ runner.os }}-cmake-${{ hashFiles('algorithms_impl/CMakeLists.txt', 'algorithms_impl/**/*.cmake') }}
restore-keys: |
${{ runner.os }}-cmake-
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
build-essential \
cmake \
git \
pkg-config \
libgflags-dev \
libboost-all-dev \
libomp-dev \
wget \
curl
- name: Clean old build artifacts
run: |
# 只清理 .so 文件,保留 build 缓存
rm -rf algorithms_impl/PyCANDYAlgo*.so
- name: Run deployment script
run: |
chmod +x deploy.sh
# 设置并行编译数量
export MAKEFLAGS="-j$(nproc)"
export CMAKE_BUILD_PARALLEL_LEVEL=$(nproc)
# CI 环境变量已设置,deploy.sh 会自动跳过 VSAG
# test 分支:快速构建
# main/main-dev 分支:完整构建
if [ "${{ env.FAST_BUILD }}" = "true" ]; then
echo "🚀 快速构建模式(test 分支,跳过 VSAG)"
else
echo "🔨 完整构建模式(main/main-dev 分支,跳过 VSAG)"
fi
./deploy.sh
timeout-minutes: 60
env:
# 加速 pip 安装
PIP_NO_CACHE_DIR: false
PIP_DISABLE_PIP_VERSION_CHECK: 1
- name: Verify Python packages
run: |
source sage-db-bench/bin/activate
# 确认使用正确的 Python
which python3
python3 --version
# 设置库路径
TORCH_LIB=$(python3 -c "import torch; import os; print(os.path.join(os.path.dirname(torch.__file__), 'lib'))")
export LD_LIBRARY_PATH="$TORCH_LIB:$LD_LIBRARY_PATH"
# 测试导入 PyCANDYAlgo(所有分支)
cd algorithms_impl && python3 -c "import PyCANDYAlgo; print('✓ PyCANDYAlgo imported'); print(f' Version: {PyCANDYAlgo.__version__}'); print(f' Compiled: {PyCANDYAlgo.__compiled_time__}')" && cd ..
# 跳过 pyvsag 测试(所有分支都不构建 VSAG)
# python3 -c "import pyvsag; print('✓ pyvsag imported')"
python3 -c "import numpy, torch, yaml; print('✓ Core dependencies OK')"
- name: Run unit tests
run: |
source sage-db-bench/bin/activate
# test 分支:快速测试(排除性能测试)
if [ "${{ env.FAST_BUILD }}" = "true" ]; then
echo "🧪 快速测试模式"
pytest tests/ -v --tb=short --ignore=tests/test_performance.py -m "not slow" || true
else
echo "🧪 完整测试模式"
pytest tests/ -v --tb=short || true
fi
- name: Check algorithm availability
run: |
source sage-db-bench/bin/activate
python -c "
from bench.algorithms import get_available_algorithms
algos = get_available_algorithms()
print(f'Available algorithms: {len(algos)}')
for algo in algos:
print(f' - {algo}')
" || echo "Algorithm check skipped"
- name: Upload build logs on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: build-logs
path: |
algorithms_impl/build.log
algorithms_impl/build/CMakeFiles/*.log
retention-days: 7
lint-and-format:
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install linting tools
run: |
pip install flake8 black isort mypy
- name: Run flake8
run: |
flake8 bench/ datasets/ --count --select=E9,F63,F7,F82 --show-source --statistics || true
- name: Check code formatting
run: |
black --check bench/ datasets/ || true
- name: Check import sorting
run: |
isort --check-only bench/ datasets/ || true