forked from jsulmont/sparkplug-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
279 lines (241 loc) · 7.99 KB
/
ci.yml
File metadata and controls
279 lines (241 loc) · 7.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
tidy-check:
name: Run clang-tidy checks
runs-on: ubuntu-latest
container: fedora:42
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
- 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