name: CI/CD Pipeline on: push: branches: [ main, develop ] pull_request: branches: [ main, develop ] release: types: [ published ] env: BUILD_TYPE: Release jobs: lint: name: Code Linting runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Install clang-format run: sudo apt-get update && sudo apt-get install -y clang-format - name: Check code formatting run: | find src include tests examples -name "*.cpp" -o -name "*.hpp" | \ xargs clang-format --dry-run --Werror build-and-test: name: Build and Test runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: os: [ubuntu-latest, ubuntu-20.04] build_type: [Release, Debug] compiler: [gcc, clang] exclude: # Reduce matrix size for faster CI - os: ubuntu-20.04 build_type: Debug steps: - uses: actions/checkout@v4 with: submodules: recursive - name: Cache dependencies uses: actions/cache@v3 with: path: | ~/.cache/pip build/_deps key: ${{ matrix.os }}-${{ matrix.compiler }}-${{ hashFiles('**/CMakeLists.txt') }} restore-keys: | ${{ matrix.os }}-${{ matrix.compiler }}- - name: Install system dependencies run: | sudo apt-get update sudo apt-get install -y \ build-essential \ cmake \ pkg-config \ libblas-dev \ liblapack-dev \ valgrind \ lcov - name: Setup Clang if: matrix.compiler == 'clang' run: | sudo apt-get install -y clang-12 echo "CC=clang-12" >> $GITHUB_ENV echo "CXX=clang++-12" >> $GITHUB_ENV - name: Setup GCC if: matrix.compiler == 'gcc' run: | echo "CC=gcc" >> $GITHUB_ENV echo "CXX=g++" >> $GITHUB_ENV - name: Install PyTorch C++ run: | cd /opt sudo wget -q https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-2.1.0%2Bcpu.zip sudo unzip -q libtorch-cxx11-abi-shared-with-deps-2.1.0+cpu.zip sudo rm libtorch-cxx11-abi-shared-with-deps-2.1.0+cpu.zip echo "Torch_DIR=/opt/libtorch" >> $GITHUB_ENV echo "LD_LIBRARY_PATH=/opt/libtorch/lib:$LD_LIBRARY_PATH" >> $GITHUB_ENV - name: Configure CMake run: | cmake -B build \ -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \ -DCMAKE_PREFIX_PATH=/opt/libtorch \ -DCMAKE_CXX_COMPILER=${{ env.CXX }} \ -DCMAKE_C_COMPILER=${{ env.CC }} - name: Build run: cmake --build build --config ${{ matrix.build_type }} -j$(nproc) - name: Run Tests working-directory: build run: | export LD_LIBRARY_PATH=/opt/libtorch/lib:$LD_LIBRARY_PATH ctest --output-on-failure --timeout 300 - name: Run Unit Tests working-directory: build run: | export LD_LIBRARY_PATH=/opt/libtorch/lib:$LD_LIBRARY_PATH make test_unit - name: Run Integration Tests working-directory: build run: | export LD_LIBRARY_PATH=/opt/libtorch/lib:$LD_LIBRARY_PATH make test_integration - name: Generate Coverage Report if: matrix.build_type == 'Debug' && matrix.compiler == 'gcc' working-directory: build run: | export LD_LIBRARY_PATH=/opt/libtorch/lib:$LD_LIBRARY_PATH make coverage - name: Upload Coverage to Codecov if: matrix.build_type == 'Debug' && matrix.compiler == 'gcc' uses: codecov/codecov-action@v3 with: file: build/coverage_filtered.info flags: unittests name: codecov-umbrella fail_ci_if_error: false - name: Memory Check with Valgrind if: matrix.build_type == 'Debug' && matrix.os == 'ubuntu-latest' working-directory: build run: | export LD_LIBRARY_PATH=/opt/libtorch/lib:$LD_LIBRARY_PATH make test_memcheck - name: Run Examples working-directory: build run: | export LD_LIBRARY_PATH=/opt/libtorch/lib:$LD_LIBRARY_PATH ./examples/basic_usage docker-build: name: Docker Build Test runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Build Docker Image run: | docker build -t svm-classifier:test --target runtime . - name: Test Docker Image run: | docker run --rm svm-classifier:test /usr/local/bin/examples/basic_usage performance-benchmark: name: Performance Benchmarks runs-on: ubuntu-latest if: github.event_name == 'pull_request' steps: - uses: actions/checkout@v4 with: submodules: recursive - name: Install dependencies run: | sudo apt-get update sudo apt-get install -y build-essential cmake pkg-config libblas-dev liblapack-dev - name: Install PyTorch C++ run: | cd /opt sudo wget -q https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-2.1.0%2Bcpu.zip sudo unzip -q libtorch-cxx11-abi-shared-with-deps-2.1.0+cpu.zip sudo rm libtorch-cxx11-abi-shared-with-deps-2.1.0+cpu.zip - name: Build with benchmarks run: | cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/opt/libtorch cmake --build build -j$(nproc) - name: Run Performance Tests working-directory: build run: | export LD_LIBRARY_PATH=/opt/libtorch/lib:$LD_LIBRARY_PATH make test_performance documentation: name: Build Documentation runs-on: ubuntu-latest if: github.ref == 'refs/heads/main' steps: - uses: actions/checkout@v4 - name: Install Doxygen run: sudo apt-get update && sudo apt-get install -y doxygen graphviz - name: Generate Documentation run: | doxygen Doxyfile - name: Deploy to GitHub Pages uses: peaceiris/actions-gh-pages@v3 if: github.ref == 'refs/heads/main' with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./docs/html package: name: Create Release Package runs-on: ubuntu-latest needs: [build-and-test, docker-build] if: github.event_name == 'release' steps: - uses: actions/checkout@v4 with: submodules: recursive - name: Install dependencies run: | sudo apt-get update sudo apt-get install -y build-essential cmake pkg-config libblas-dev liblapack-dev - name: Install PyTorch C++ run: | cd /opt sudo wget -q https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-2.1.0%2Bcpu.zip sudo unzip -q libtorch-cxx11-abi-shared-with-deps-2.1.0+cpu.zip sudo rm libtorch-cxx11-abi-shared-with-deps-2.1.0+cpu.zip - name: Build Release Package run: | cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/opt/libtorch cmake --build build -j$(nproc) cd build && cpack - name: Upload Release Assets uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ github.event.release.upload_url }} asset_path: ./build/SVMClassifier-*.tar.gz asset_name: svm-classifier-${{ github.event.release.tag_name }}-linux.tar.gz asset_content_type: application/gzip