-
Notifications
You must be signed in to change notification settings - Fork 0
421 lines (355 loc) · 15.2 KB
/
ci.yml
File metadata and controls
421 lines (355 loc) · 15.2 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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
name: CI
on:
push:
branches: [main]
paths-ignore:
- ".github/badges/**"
pull_request:
branches: [main]
workflow_call:
workflow_dispatch:
jobs:
tests-gcc:
runs-on: ubuntu-latest
env:
DS_MYSQL_TEST_HOST: 127.0.0.1
DS_MYSQL_TEST_PORT: 3306
DS_MYSQL_TEST_DATABASE: ds_mysql_test
DS_MYSQL_TEST_USER: ds_mysql_test_user
DS_MYSQL_TEST_PASSWORD: ds_mysql_test_password
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: ds_mysql_test
MYSQL_USER: ds_mysql_test_user
MYSQL_PASSWORD: ds_mysql_test_password
ports:
- 3306/tcp
options: >-
--health-cmd="mysqladmin ping -h 127.0.0.1 --protocol=tcp"
--health-interval=5s
--health-timeout=10s
--health-retries=10
steps:
- uses: actions/checkout@v6
- name: Export mapped MySQL service port
run: echo "DS_MYSQL_TEST_PORT=${{ job.services.mysql.ports[3306] }}" >> "$GITHUB_ENV"
- name: Install dependencies
run: |
sudo apt-get update -q
sudo apt-get install -y --no-install-recommends software-properties-common ca-certificates gpg wget
# Kitware APT repo for CMake 3.31+
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc \
| gpg --dearmor \
| sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg > /dev/null
echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ noble main' \
| sudo tee /etc/apt/sources.list.d/kitware.list
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
sudo apt-get update -q
sudo apt-get install -y --no-install-recommends cmake ninja-build g++-15 gcc-15 \
libmysqlclient-dev pkg-config
- name: Configure
run: cmake --preset release -DSKIP_DOCKER_MANAGEMENT=ON
env:
CXX: g++-15
CC: gcc-15
- name: Build
run: cmake --build --preset release -j4
- name: Unit tests
run: ctest --preset release -R tests_unit_ds_mysql
- name: Integration tests
run: ctest --preset release -R tests_integration_ds_mysql
tests-clang:
runs-on: ubuntu-latest
env:
DS_MYSQL_TEST_HOST: 127.0.0.1
DS_MYSQL_TEST_PORT: 3306
DS_MYSQL_TEST_DATABASE: ds_mysql_test
DS_MYSQL_TEST_USER: ds_mysql_test_user
DS_MYSQL_TEST_PASSWORD: ds_mysql_test_password
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: ds_mysql_test
MYSQL_USER: ds_mysql_test_user
MYSQL_PASSWORD: ds_mysql_test_password
ports:
- 3306/tcp
options: >-
--health-cmd="mysqladmin ping -h 127.0.0.1 --protocol=tcp"
--health-interval=5s
--health-timeout=10s
--health-retries=10
steps:
- uses: actions/checkout@v6
- name: Export mapped MySQL service port
run: echo "DS_MYSQL_TEST_PORT=${{ job.services.mysql.ports[3306] }}" >> "$GITHUB_ENV"
- name: Install dependencies
run: |
sudo apt-get update -q
sudo apt-get install -y software-properties-common ca-certificates gpg wget
# Kitware APT repo for CMake 3.31+
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc \
| gpg --dearmor \
| sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg > /dev/null
echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ noble main' \
| sudo tee /etc/apt/sources.list.d/kitware.list
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key \
| gpg --dearmor \
| sudo tee /usr/share/keyrings/llvm-archive-keyring.gpg > /dev/null
UBUNTU_CODENAME="$(. /etc/os-release && echo "$VERSION_CODENAME")"
echo "deb [signed-by=/usr/share/keyrings/llvm-archive-keyring.gpg] https://apt.llvm.org/${UBUNTU_CODENAME}/ llvm-toolchain-${UBUNTU_CODENAME}-20 main" \
| sudo tee /etc/apt/sources.list.d/llvm.list
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
sudo apt-get update -q
sudo apt-get install -y cmake ninja-build clang-20 libstdc++-15-dev \
libmysqlclient-dev pkg-config
- name: Configure
run: cmake --preset release -DSKIP_DOCKER_MANAGEMENT=ON
env:
CXX: clang++-20
CC: clang-20
- name: Build
run: cmake --build --preset release -j4
- name: Unit tests
run: ctest --preset release -R tests_unit_ds_mysql
- name: Integration tests
run: ctest --preset release -R tests_integration_ds_mysql
package-consumer-smoke:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Install dependencies
run: |
sudo apt-get update -q
sudo apt-get install -y software-properties-common ca-certificates gpg wget
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc \
| gpg --dearmor \
| sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg > /dev/null
echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ noble main' \
| sudo tee /etc/apt/sources.list.d/kitware.list
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
sudo apt-get update -q
sudo apt-get install -y cmake ninja-build g++-15 gcc-15 libmysqlclient-dev pkg-config libboost-dev
- name: Configure (install enabled)
run: |
cmake --preset release \
-DSKIP_DOCKER_MANAGEMENT=ON \
-DBUILD_TESTING=OFF \
-DBUILD_INTEGRATION_TESTS=OFF \
-DBUILD_EXAMPLES=OFF \
-DDSMYSQL_ENABLE_INSTALL=ON
env:
CXX: g++-15
CC: gcc-15
- name: Build and install
run: |
cmake --build --preset release -j4
cmake --install build/release --prefix "$RUNNER_TEMP/dsmysql-install"
- name: External consumer smoke test
run: |
mkdir -p "$RUNNER_TEMP/consumer"
cat > "$RUNNER_TEMP/consumer/CMakeLists.txt" << 'EOF'
cmake_minimum_required(VERSION 3.25)
project(ds_mysql_consumer LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 23)
find_package(ds_mysql CONFIG REQUIRED)
add_executable(consumer main.cpp)
target_link_libraries(consumer PRIVATE ds_mysql::ds_mysql)
EOF
cat > "$RUNNER_TEMP/consumer/main.cpp" << 'EOF'
#include <ds_mysql/version.hpp>
int main() {
return static_cast<int>(ds_mysql::version::major);
}
EOF
cmake -S "$RUNNER_TEMP/consumer" -B "$RUNNER_TEMP/consumer/build" \
-DCMAKE_PREFIX_PATH="$RUNNER_TEMP/dsmysql-install"
cmake --build "$RUNNER_TEMP/consumer/build" -j4
tests-msvc:
runs-on: windows-latest
env:
DS_MYSQL_TEST_HOST: 127.0.0.1
DS_MYSQL_TEST_PORT: 3306
DS_MYSQL_TEST_DATABASE: ds_mysql_test
DS_MYSQL_TEST_USER: ds_mysql_test_user
DS_MYSQL_TEST_PASSWORD: ds_mysql_test_password
steps:
- uses: actions/checkout@v6
- name: Install dependencies
run: |
choco install cmake ninja --no-progress -y
shell: pwsh
- name: Ensure MySQL is installed
shell: pwsh
run: |
$mysqlCmd = Get-Command mysql -ErrorAction SilentlyContinue
$mysqldCmd = Get-Command mysqld -ErrorAction SilentlyContinue
if (-not $mysqlCmd -or -not $mysqldCmd) {
choco install mysql --no-progress -y
}
$mysqlCmd = Get-Command mysql -ErrorAction SilentlyContinue
$mysqldCmd = Get-Command mysqld -ErrorAction SilentlyContinue
if (-not $mysqlCmd -or -not $mysqldCmd) {
throw "MySQL client/server binaries not available on PATH after installation"
}
- name: Detect MySQL root
shell: pwsh
run: |
$candidateRoots = @()
if (Test-Path "C:\Program Files\MySQL") {
$candidateRoots += (Get-ChildItem "C:\Program Files\MySQL" -Directory -ErrorAction SilentlyContinue |
Where-Object { $_.Name -like "MySQL Server *" } |
Sort-Object Name -Descending |
ForEach-Object { $_.FullName })
}
$candidateRoots += (Get-ChildItem "C:\ProgramData\chocolatey\lib" -Directory -ErrorAction SilentlyContinue |
Where-Object { $_.Name -like "mysql*" } |
ForEach-Object {
$toolsDir = Join-Path $_.FullName "tools"
if (Test-Path $toolsDir) {
Get-ChildItem $toolsDir -Directory -ErrorAction SilentlyContinue | ForEach-Object { $_.FullName }
}
})
$candidateRoots = $candidateRoots | Select-Object -Unique
$root = $null
foreach ($candidate in $candidateRoots) {
$includeFile = Join-Path $candidate "include\mysql.h"
$libFile = Join-Path $candidate "lib\libmysql.lib"
if ((Test-Path $includeFile) -and (Test-Path $libFile)) {
$root = $candidate
break
}
}
if (-not $root) {
throw "MySQL installation not found with include/mysql.h and lib/libmysql.lib"
}
Write-Host "Detected MYSQL_ROOT_DIR: $root"
echo "MYSQL_ROOT_DIR=$root" >> $env:GITHUB_ENV
echo "MYSQL_BIN_DIR=$(Join-Path $root 'bin')" >> $env:GITHUB_ENV
echo "$root\bin" >> $env:GITHUB_PATH
echo "$root\lib" >> $env:GITHUB_PATH
- name: Configure
shell: pwsh
run: |
cmake -B build `
-G "Visual Studio 17 2022" -A x64 `
-DSKIP_DOCKER_MANAGEMENT=ON `
-DBUILD_EXAMPLES=OFF `
"-DMYSQL_ROOT_DIR=$env:MYSQL_ROOT_DIR"
- name: Build
run: cmake --build build --config Release -j4
- name: Unit tests
run: ctest --test-dir build -C Release -R tests_unit_ds_mysql --output-on-failure
- name: Integration tests
shell: pwsh
run: |
function Find-Tool([string]$toolName) {
$toolBase = [System.IO.Path]::GetFileNameWithoutExtension($toolName)
$fromPath = Get-Command $toolBase -ErrorAction SilentlyContinue
if ($fromPath -and (Test-Path $fromPath.Source)) {
return $fromPath.Source
}
$candidates = @(
(Join-Path $env:MYSQL_BIN_DIR $toolName),
(Join-Path $env:MYSQL_ROOT_DIR $toolName),
(Join-Path $env:MYSQL_ROOT_DIR "bin\$toolName")
)
foreach ($candidate in $candidates) {
if ($candidate -and (Test-Path $candidate)) {
return $candidate
}
}
$match = Get-ChildItem -Path $env:MYSQL_ROOT_DIR -Filter $toolName -Recurse -ErrorAction SilentlyContinue |
Select-Object -First 1
if ($match) {
return $match.FullName
}
throw "$toolName not found under MYSQL_ROOT_DIR=$env:MYSQL_ROOT_DIR"
}
$dataDir = Join-Path $env:RUNNER_TEMP ("mysql-data-" + [guid]::NewGuid().ToString("N"))
$stdoutLogFile = Join-Path $env:RUNNER_TEMP "mysql-server.stdout.log"
$stderrLogFile = Join-Path $env:RUNNER_TEMP "mysql-server.stderr.log"
$mysqlExe = Find-Tool "mysql.exe"
$mysqlAdminExe = Find-Tool "mysqladmin.exe"
$mysqldExe = Find-Tool "mysqld.exe"
$process = $null
try {
Write-Host "Using mysql.exe: $mysqlExe"
Write-Host "Using mysqladmin.exe: $mysqlAdminExe"
Write-Host "Using mysqld.exe: $mysqldExe"
New-Item -ItemType Directory -Force -Path $dataDir | Out-Null
& $mysqldExe --initialize-insecure --datadir="$dataDir" --console
if ($LASTEXITCODE -ne 0) {
throw "mysqld --initialize-insecure failed with exit code $LASTEXITCODE"
}
$requestedPort = [int]$env:DS_MYSQL_TEST_PORT
$portsToTry = @($requestedPort, 3307, 3308, 33306) | Select-Object -Unique
$chosenPort = $null
foreach ($port in $portsToTry) {
Write-Host "Trying MySQL port $port"
$process = Start-Process -FilePath $mysqldExe -ArgumentList @(
"--datadir=$dataDir",
"--port=$port",
"--bind-address=$env:DS_MYSQL_TEST_HOST",
"--console"
) -RedirectStandardOutput $stdoutLogFile -RedirectStandardError $stderrLogFile -PassThru
$ready = $false
for ($attempt = 0; $attempt -lt 45; $attempt++) {
& $mysqlAdminExe --protocol=tcp --host=$env:DS_MYSQL_TEST_HOST --port=$port --user=root ping --silent
if ($LASTEXITCODE -eq 0) {
$ready = $true
break
}
Start-Sleep -Seconds 2
}
if ($ready) {
$chosenPort = $port
break
}
if ($process -and -not $process.HasExited) {
Stop-Process -Id $process.Id -Force -ErrorAction SilentlyContinue
}
$process = $null
}
if (-not $chosenPort) {
throw "MySQL server did not become ready on any candidate port"
}
$env:DS_MYSQL_TEST_PORT = [string]$chosenPort
Write-Host "MySQL is ready on port $chosenPort"
$sql = @(
"CREATE DATABASE IF NOT EXISTS $env:DS_MYSQL_TEST_DATABASE;"
"CREATE USER IF NOT EXISTS '$env:DS_MYSQL_TEST_USER'@'%' IDENTIFIED BY '$env:DS_MYSQL_TEST_PASSWORD';"
"GRANT ALL PRIVILEGES ON $env:DS_MYSQL_TEST_DATABASE.* TO '$env:DS_MYSQL_TEST_USER'@'%';"
"FLUSH PRIVILEGES;"
) -join ' '
& $mysqlExe --protocol=tcp --host=$env:DS_MYSQL_TEST_HOST --port=$chosenPort --user=root --execute="$sql"
if ($LASTEXITCODE -ne 0) {
throw "Failed to initialize MySQL test database"
}
& $mysqlAdminExe --protocol=tcp --host=$env:DS_MYSQL_TEST_HOST --port=$chosenPort --user=root ping --silent
if ($LASTEXITCODE -ne 0) {
throw "MySQL server stopped responding before running integration tests"
}
ctest --test-dir build -C Release -R tests_integration_ds_mysql --output-on-failure
if ($LASTEXITCODE -ne 0) {
throw "Integration tests failed"
}
}
finally {
if (Test-Path $stdoutLogFile) {
Write-Host "--- mysqld stdout ---"
Get-Content $stdoutLogFile
}
if (Test-Path $stderrLogFile) {
Write-Host "--- mysqld stderr ---"
Get-Content $stderrLogFile
}
if ($process -and -not $process.HasExited) {
Stop-Process -Id $process.Id -Force -ErrorAction SilentlyContinue
}
}