fetch_ml/.forgejo/workflows/ci-native.yml
Jeremie Fraeys 4c82237608
Some checks failed
CI with Native Libraries / Build and Test Native Libraries (push) Blocked by required conditions
CI with Native Libraries / Build Release Libraries (push) Blocked by required conditions
Documentation / build-and-publish (push) Waiting to run
Checkout test / test (push) Successful in 5s
CI with Native Libraries / Check Build Environment (push) Successful in 12s
CI/CD Pipeline / Test (push) Failing after 1m0s
CI/CD Pipeline / Dev Compose Smoke Test (push) Has been skipped
CI/CD Pipeline / Build (push) Has been skipped
CI/CD Pipeline / Test Scripts (push) Has been skipped
CI/CD Pipeline / Security Scan (push) Has been cancelled
CI/CD Pipeline / Docker Build (push) Has been cancelled
ci: performance optimizations - native lib caching, docker layer caching, path filtering, apt caching
2026-02-12 14:12:25 -05:00

273 lines
9.5 KiB
YAML

name: CI with Native Libraries
on:
push:
branches: [main, master]
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '**/*.md'
pull_request:
branches: [main, master]
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '**/*.md'
workflow_dispatch:
# Manual trigger for debugging native builds
# Global timeout - fail fast if hanging
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
# Pre-flight check to ensure build environment is ready
check-environment:
name: Check Build Environment
runs-on: self-hosted
timeout-minutes: 5
steps:
- name: Install Build Dependencies
run: |
echo "Installing build dependencies..."
# Detect OS and install dependencies
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
if command -v apt-get &> /dev/null; then
echo "Detected Debian/Ubuntu - installing cmake, zlib, build-essential..."
sudo apt-get update
sudo apt-get install -y cmake zlib1g-dev build-essential
elif command -v yum &> /dev/null; then
echo "Detected RHEL/CentOS - installing cmake, zlib, gcc-c++..."
sudo yum install -y cmake zlib-devel gcc-c++
else
echo "WARNING: Unknown package manager. Please install manually:"
echo " - cmake"
echo " - zlib development headers"
echo " - C++ compiler (g++ or clang++)"
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
echo "Detected macOS - checking for Homebrew..."
if ! command -v brew &> /dev/null; then
echo "ERROR: Homebrew not found. Install from https://brew.sh"
exit 1
fi
echo "Installing cmake, zlib via Homebrew..."
brew install cmake zlib
else
echo "WARNING: Unknown OS. Please install manually:"
echo " - cmake"
echo " - zlib development headers"
echo " - C++ compiler (g++ or clang++)"
fi
echo "Dependencies installed."
- name: Check CMake Available
run: |
if ! command -v cmake &> /dev/null; then
echo "❌ ERROR: cmake is not installed"
echo ""
echo "To fix this on your self-hosted runner:"
echo " Ubuntu/Debian: sudo apt-get install -y cmake zlib1g-dev"
echo " macOS: brew install cmake zlib"
echo " CentOS/RHEL: sudo yum install -y cmake zlib-devel"
echo ""
echo "Or add this to your runner setup script."
exit 1
fi
echo "cmake: $(cmake --version | head -1)"
- name: Check C++ Compiler
run: |
if ! command -v g++ &> /dev/null && ! command -v clang++ &> /dev/null; then
echo "No C++ compiler found (g++ or clang++)"
echo ""
echo "To fix this:"
echo " Ubuntu/Debian: sudo apt-get install -y build-essential"
echo " macOS: xcode-select --install"
exit 1
fi
echo "C++ compiler available"
- name: Check Zlib
run: |
if pkg-config --exists zlib 2>/dev/null || [ -f /usr/include/zlib.h ] || [ -f /usr/local/include/zlib.h ]; then
echo "zlib development headers found"
else
echo "zlib headers not found - native build may fail"
echo " Install: sudo apt-get install -y zlib1g-dev || brew install zlib"
fi
test-native:
name: Build and Test Native Libraries
runs-on: self-hosted
needs: check-environment
timeout-minutes: 30
services:
redis:
image: redis:7-alpine
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 5s
--health-timeout 3s
--health-retries 3
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Cache native libraries
uses: actions/cache@v4
with:
path: |
native/build/
key: ${{ runner.os }}-native-${{ hashFiles('native/**/*.cpp', 'native/**/*.h', 'native/**/CMakeLists.txt') }}
restore-keys: |
${{ runner.os }}-native-
- name: Cache apt packages
uses: actions/cache@v4
with:
path: /var/cache/apt/archives
key: ${{ runner.os }}-apt-native-${{ hashFiles('.forgejo/workflows/*.yml') }}
restore-keys: |
${{ runner.os }}-apt-
- name: Install cmake and build tools
run: |
echo "Installing cmake and build dependencies..."
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
if command -v apt-get &> /dev/null; then
sudo apt-get update
sudo apt-get install -y cmake zlib1g-dev build-essential
elif command -v yum &> /dev/null; then
sudo yum install -y cmake zlib-devel gcc-c++
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
brew install cmake zlib
fi
which cmake
- name: Setup Go
run: |
REQUIRED_GO="1.23.4"
if command -v go &> /dev/null && go version | grep -q "go${REQUIRED_GO}"; then
echo "Go ${REQUIRED_GO} already installed - skipping download"
else
echo "Installing Go ${REQUIRED_GO}..."
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
curl -sL "https://go.dev/dl/go${REQUIRED_GO}.linux-amd64.tar.gz" | sudo tar -C /usr/local -xzf -
elif [[ "$OSTYPE" == "darwin"* ]]; then
curl -sL "https://go.dev/dl/go${REQUIRED_GO}.darwin-amd64.tar.gz" | sudo tar -C /usr/local -xzf -
fi
export PATH="/usr/local/go/bin:$PATH"
echo "/usr/local/go/bin" >> $GITHUB_PATH
echo "Go ${REQUIRED_GO} installed"
fi
go version
- name: Build Native Libraries
run: |
echo "Building native C++ libraries..."
make native-build 2>&1
if [ $? -ne 0 ]; then
echo ""
echo "Native build failed!"
echo ""
echo "Common causes:"
echo " 1. Missing cmake: Install with 'apt-get install cmake' or 'brew install cmake'"
echo " 2. Missing C++ compiler: Install with 'apt-get install build-essential'"
echo " 3. Missing zlib: Install with 'apt-get install zlib1g-dev'"
echo " 4. CMakeLists.txt not found: Ensure native/CMakeLists.txt exists"
echo ""
echo "Check the detailed error above for more information."
exit 1
fi
echo "Native libraries built successfully"
- name: Test with Native Libraries
run: |
echo "Running tests WITH native libraries enabled..."
FETCHML_NATIVE_LIBS=1 go test -v ./tests/...
env:
FETCHML_NATIVE_LIBS: "1"
continue-on-error: true
- name: Test Fallback (Go only)
run: |
echo "Running tests WITHOUT native libraries (Go fallback)..."
FETCHML_NATIVE_LIBS=0 go test -v ./tests/...
env:
FETCHML_NATIVE_LIBS: "0"
- name: Run Benchmarks
run: |
echo "Running performance benchmarks..."
echo "=== Go Implementation ==="
FETCHML_NATIVE_LIBS=0 go test -bench=. ./tests/benchmarks/ -benchmem || true
echo ""
echo "=== Native Implementation ==="
FETCHML_NATIVE_LIBS=1 go test -bench=. ./tests/benchmarks/ -benchmem || true
- name: Lint
run: |
echo "Running linters..."
make lint || echo "Linting completed with warnings"
build-release:
name: Build Release Libraries
runs-on: self-hosted
needs: test-native
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Setup Go (fast)
run: |
REQUIRED_GO="1.23.4"
if command -v go &> /dev/null && go version | grep -q "go${REQUIRED_GO}"; then
echo "Go ${REQUIRED_GO} already installed - skipping download"
else
echo "Installing Go ${REQUIRED_GO}..."
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
curl -sL "https://go.dev/dl/go${REQUIRED_GO}.linux-amd64.tar.gz" | sudo tar -C /usr/local -xzf -
elif [[ "$OSTYPE" == "darwin"* ]]; then
curl -sL "https://go.dev/dl/go${REQUIRED_GO}.darwin-amd64.tar.gz" | sudo tar -C /usr/local -xzf -
fi
export PATH="/usr/local/go/bin:$PATH"
echo "/usr/local/go/bin" >> $GITHUB_PATH
echo "Go ${REQUIRED_GO} installed"
fi
go version
- name: Build Release Libraries
run: |
echo "Building optimized release libraries..."
make native-release 2>&1
echo "Release libraries built"
- name: List Build Artifacts
run: |
echo "Built libraries:"
ls -lh native/build/lib* 2>/dev/null || echo "No libraries found in native/build/"
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: native-libs-${{ runner.os }}-${{ runner.arch }}
path: |
native/build/lib*.so
native/build/lib*.dylib
continue-on-error: true