name: Zvec LinuxX64 CI on: push: branches: [ "main" ] pull_request: branches: [ "main" ] workflow_dispatch: concurrency: group: pr-${{ github.workflow }}-${{ github.event.pull_request.number }} cancel-in-progress: true permissions: contents: read jobs: build: name: Zvec LinuxX64 CI runs-on: linux_x64 strategy: matrix: python-version: ['3.10'] fail-fast: false container: image: zvec-registry.cn-hongkong.cr.aliyuncs.com/zvec/zvec:0.0.2 options: --user root steps: - name: Activate Conda environment run: | # Map version to env name if [[ "${{ matrix.python-version }}" == "3.10" ]]; then ENV_NAME="py310" elif [[ "${{ matrix.python-version }}" == "3.11" ]]; then ENV_NAME="py311" elif [[ "${{ matrix.python-version }}" == "3.12" ]]; then ENV_NAME="py312" else echo "Unsupported Python version" exit 1 fi echo "CONDA_ENV_NAME=$ENV_NAME" >> $GITHUB_ENV source /opt/miniforge3/bin/activate $ENV_NAME pip install --upgrade pip pytest pytest-cov ruff python --version shell: bash - name: Prepare clean build directory run: | export CLEAN_WORKSPACE="/tmp/zvec" 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.pull_request.head.sha }}" ]; then git checkout "${{ github.event.pull_request.head.sha }}" else git checkout "${{ github.sha }}" fi echo "CLEAN_WORKSPACE=$CLEAN_WORKSPACE" >> $GITHUB_ENV env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} shell: bash - name: Run Ruff Linter run: | source /opt/miniforge3/bin/activate ${{ env.CONDA_ENV_NAME }} cd "$CLEAN_WORKSPACE" ruff check . shell: bash - name: Run Ruff Formatter Check (ensure code is formatted) run: | source /opt/miniforge3/bin/activate ${{ env.CONDA_ENV_NAME }} cd "$CLEAN_WORKSPACE" ruff format --check . shell: bash - name: Run clang-format Check run: | source /opt/miniforge3/bin/activate ${{ env.CONDA_ENV_NAME }} 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/*" \ ! -path "./scripts/*" \ ! -path "./python/*" \ ! -path "./thirdparty/*" \ ! -path "./.git/*") if [ -z "$CPP_FILES" ]; then echo "No C++ files found to check." exit 0 fi clang-format-18 --dry-run --Werror $CPP_FILES shell: bash - name: Install Python dependencies and build package run: | source /opt/miniforge3/bin/activate ${{ env.CONDA_ENV_NAME }} cd "$CLEAN_WORKSPACE" NPROC=$(nproc 2>/dev/null || echo $(getconf _NPROCESSORS_ONLN 2>/dev/null || echo 2)) echo "ParallelGroup: Using $NPROC parallel jobs for build" CMAKE_GENERATOR="Unix Makefiles" \ CMAKE_BUILD_PARALLEL_LEVEL="$NPROC" \ pip install -v . \ --config-settings='cmake.define.BUILD_TOOLS="ON"' shell: bash - name: Run Python Tests with Coverage run: | source /opt/miniforge3/bin/activate ${{ env.CONDA_ENV_NAME }} cd "$CLEAN_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$(nproc) shell: bash