Skip to content

fix(build): make format includes portable for CI #35

fix(build): make format includes portable for CI

fix(build): make format includes portable for CI #35

Workflow file for this run

name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
format-check:
name: Check code formatting
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install clang-format-18
run: |
sudo apt-get update
sudo apt-get install -y clang-format-18
- name: Check C++ formatting
run: ./scripts/format.sh --check
tidy-check:
name: Run clang-tidy checks
runs-on: ubuntu-latest
container: fedora:42
needs: [format-check]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install dependencies
run: |
dnf install -y \
gcc-c++ \
clang \
clang-tools-extra \
cmake \
ninja-build \
git \
protobuf-devel \
abseil-cpp-devel \
paho-c-devel \
openssl-devel
- name: Configure CMake
env:
CC: clang
CXX: clang++
run: cmake --preset default
- name: Build (for compile_commands.json)
run: cmake --build build -j$(nproc)
- name: Run clang-tidy
run: ./scripts/tidy.sh --quiet
build-and-test-fedora:
name: Build and test (Fedora 42)
runs-on: ubuntu-latest
container: fedora:42
needs: [tidy-check]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install dependencies
run: |
dnf install -y \
gcc-c++ \
clang \
cmake \
ninja-build \
git \
protobuf-devel \
abseil-cpp-devel \
paho-c-devel \
openssl-devel \
openssl \
mosquitto \
procps-ng
- name: Generate TLS certificates
run: |
cd certs
chmod +x generate_certs.sh
./generate_certs.sh
echo "Certificates generated:"
ls -la *.crt *.key
- name: Create password file for authentication tests
run: |
cd certs
mosquitto_passwd -c -b passwordfile admin admin
chmod 600 passwordfile
echo "Password file created with admin/admin"
- name: Start Mosquitto broker
run: |
# Start Mosquitto with default config for basic tests
mosquitto -v &
MOSQUITTO_PID=$!
sleep 2
# Verify Mosquitto is running
if ps -p $MOSQUITTO_PID > /dev/null; then
echo "Mosquitto started successfully (PID: $MOSQUITTO_PID)"
else
echo "ERROR: Mosquitto failed to start"
exit 1
fi
- name: Configure CMake
env:
CC: clang
CXX: clang++
run: cmake --preset default
- name: Build
run: cmake --build build -j$(nproc)
- name: Run tests
run: ctest --test-dir build --output-on-failure
# Authentication tests disabled - require complex Mosquitto TLS setup
# Re-enable once Mosquitto container configuration is fixed
# - name: Run authentication tests
# run: |
# mosquitto -c certs/mosquitto_test.conf -d
# sleep 2
# ./build/examples/test_auth_password
# ./build/examples/test_auth_mtls
# ./build/examples/test_auth_combined
build-and-test-ubuntu:
name: Build and test (Ubuntu 24.04 LTS)
runs-on: ubuntu-24.04
needs: [tidy-check]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
build-essential \
clang-18 \
cmake \
git \
protobuf-compiler \
libprotobuf-dev \
libabsl-dev \
libssl-dev \
openssl \
pkg-config \
mosquitto
- name: Build and install Paho MQTT C
run: |
cd /tmp
git clone --depth 1 --branch v1.3.15 https://github.com/eclipse/paho.mqtt.c.git
cd paho.mqtt.c
cmake -Bbuild \
-DCMAKE_BUILD_TYPE=Release \
-DPAHO_WITH_SSL=ON \
-DPAHO_BUILD_DOCUMENTATION=OFF \
-DPAHO_BUILD_SAMPLES=OFF \
-DPAHO_BUILD_STATIC=OFF
cmake --build build
sudo cmake --install build
- name: Generate TLS certificates
run: |
cd certs
chmod +x generate_certs.sh
./generate_certs.sh
- name: Create password file
run: |
cd certs
mosquitto_passwd -c -b passwordfile admin admin
chmod 600 passwordfile
- name: Start Mosquitto broker
run: |
mosquitto -c certs/mosquitto_test.conf -d
sleep 3
timeout 1 mosquitto_sub -h localhost -p 1883 -t test || true
- name: Configure CMake
env:
CC: clang-18
CXX: clang++-18
run: cmake --preset default
- name: Build
run: cmake --build build -j$(nproc)
- name: Run tests
run: ctest --test-dir build --output-on-failure
- name: Verify tl::expected is used (Ubuntu lacks std::expected)
run: |
echo "Checking that tl::expected fallback is working..."
strings build/src/libsparkplug_cpp.a | grep -q "tl::" || echo "Note: Binary doesn't contain tl:: symbols (may be optimized out)"
echo "Ubuntu 24.04 build successful with C++23 compatibility layer!"
build-static-musl:
name: Build and test static musl bundle (Alpine)
runs-on: ubuntu-latest
container: alpine:latest
needs: [tidy-check]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install dependencies
run: |
apk add --no-cache \
build-base \
cmake \
git \
bash \
linux-headers \
openssl-dev \
openssl-libs-static \
zlib-static \
samurai \
protobuf-dev \
protoc
- name: Build static musl bundle
run: |
export VERSION="ci-test"
bash ./scripts/build_static_musl.sh
- name: Verify static bundle was created
run: |
BUNDLE_LIB="build-static-musl/sparkplug-c-ci-test-linux-musl-x86_64-static/lib/libsparkplug_c_static_bundle.a"
if [ ! -f "$BUNDLE_LIB" ]; then
echo "ERROR: Static bundle not found at $BUNDLE_LIB"
exit 1
fi
echo "Static bundle size: $(du -h $BUNDLE_LIB | cut -f1)"
echo "Checking for expected symbols..."
nm $BUNDLE_LIB | grep -E " T (sparkplug_publisher_create|sparkplug_host_application_create)" || {
echo "ERROR: Expected symbols not found"
exit 1
}
echo "Static bundle verification passed!"
- name: Test linking static bundle
run: |
cat > test_link.c << 'EOF'
#include <stdio.h>
#include <sparkplug/sparkplug_c.h>
int main() {
printf("Testing static bundle link...\n");
void* pub_ptr = (void*)sparkplug_publisher_create;
void* host_ptr = (void*)sparkplug_host_application_create;
if (pub_ptr && host_ptr) {
printf("Static link test passed!\n");
return 0;
}
return 1;
}
EOF
g++ test_link.c \
-I build-static-musl/sparkplug-c-ci-test-linux-musl-x86_64-static/include \
-L build-static-musl/sparkplug-c-ci-test-linux-musl-x86_64-static/lib \
-lsparkplug_c_static_bundle \
-lssl -lcrypto -lpthread -ldl \
-o test_link
./test_link
echo "Link test successful!"
- name: Check static bundle has no unexpected dependencies
run: |
echo "Checking that bundle is truly static (except OpenSSL)..."
# The .a file itself shouldn't have dependencies
# A linked executable should only depend on libc and OpenSSL
if ldd test_link 2>&1 | grep -v "libc\|libssl\|libcrypto\|libpthread\|libdl\|ld-musl" | grep "=>"; then
echo "WARNING: Unexpected dynamic dependencies found"
ldd test_link
else
echo "Static bundle dependencies look good!"
ldd test_link || echo "(statically linked)"
fi