1c758836eca17c9ee28e1d5806b4974fedb1c2fb
[m6w6/libmemcached] / .github / workflows / cmake-build-ci.gen
1 #!/usr/bin/env php
2 <?php
3
4 echo "# Generated file; do not edit!\n";
5
6 const DEF = [
7 "os" => "Linux",
8 "Linux" => "ubuntu-20.04",
9 "Windows" => "windows-2019",
10 "macOS" => "macos-10.15",
11 "ubuntu-20.04" => "gnu",
12 "windows-2019" => "msvc",
13 "macos-10.15" => "clang",
14 "gnu" => [
15 "ver" => "cur",
16 "CC" => "gcc",
17 "CXX" => "g++",
18 ],
19 "clang" => [
20 "ver" => "apple",
21 "CC" => "clang",
22 "CXX" => "clang++",
23 ],
24 "msvc" => [ // dummy
25 "ver" => "cur",
26 "CC" => "msvc",
27 "CXX" => "msvc",
28 ],
29 ];
30 const ENV = [
31 "ubuntu-20.04" => [
32 "gnu" => [
33 "new" => [
34 "INSTALL_CC" => "gcc-10",
35 "INSTALL_CXX" => "g++-10",
36 ]
37 ]
38 ],
39 "ubuntu-18.04" => [
40 "clang" => [
41 "old" => [
42 "CXXFLAGS" => "-stdlib=libc++"
43 ]
44 ]
45 ]
46 ];
47 const MAP = [
48 'env.OS_VER' => [
49 "ubuntu-20.04" => [
50 'env.CC_VND' => [
51 "gnu" => [
52 'env.CC_VER' => [
53 "new" => "-10",
54 "cur" => "-9",
55 "old" => "-8"
56 ]
57 ],
58 "clang" => [
59 'env.CC_VER' => [
60 "new" => "-10",
61 "cur" => "-9",
62 "old" => "-8"
63 ]
64 ]
65 ]
66 ],
67 "ubuntu-18.04" => [
68 'env.CC_VND' => [
69 "gnu" => [
70 'env.CC_VER' => [
71 "new" => "-9",
72 "cur" => "-8",
73 "old" => "-7"
74 ]
75 ],
76 "clang" => [
77 'env.CC_VER' => [
78 "new" => "-9",
79 "cur" => "-8",
80 "old" => "-6.0"
81 ]
82 ]
83 ]
84 ],
85 "windows-2019" => [
86 'env.CC_VND' => [
87 "msvc" => [
88 'env.CC_VER' => [
89 "cur" => "2019",
90 ],
91 ],
92 ],
93 ],
94 ]
95 ];
96
97 /**
98 * @var bool $splat_map false = no splat map, null = default splat map, true = full splat map
99 */
100 function steps_setenv($splat_map = null) {
101 if ($splat_map !== false) {
102 foreach (MAP as $os_is => $os_vers) {
103 foreach ($os_vers as $os_ver => $cc_vnds_) {
104 if (!$splat_map && DEF[DEF["os"]] != $os_ver) continue;
105 foreach ($cc_vnds_ as $cc_vnd_is => $cc_vnds) {
106 foreach ($cc_vnds as $cc_vnd => $cc_vers_) {
107 if (!$splat_map && DEF[DEF[DEF["os"]]] != $cc_vnd) continue;
108 foreach ($cc_vers_ as $cc_ver_is => $cc_vers) {
109 foreach ($cc_vers as $cc_ver => $ver) {
110 if (!$splat_map && DEF[DEF[DEF[DEF["os"]]]]["ver"] != $cc_ver) continue;
111 ?>
112 - name: Prepare environment (<?= "for $cc_ver $cc_vnd on $os_ver" ?>)
113 if: (<?="$os_is=='$os_ver') && ($cc_vnd_is=='$cc_vnd') && ($cc_ver_is=='$cc_ver'"?>)
114 run: |
115 echo CC="<?=DEF[$cc_vnd]["CC"] . $ver?>" >> ${GITHUB_ENV}
116 echo CXX="<?=DEF[$cc_vnd]["CXX"] . $ver?>" >> ${GITHUB_ENV}
117 <?php
118 if (isset(ENV[$os_ver][$cc_vnd][$cc_ver])) {
119 foreach (ENV[$os_ver][$cc_vnd][$cc_ver] as $env => $val) {
120 ?>
121 echo <?=$env?>="<?=$val?>" >> ${GITHUB_ENV}
122 <?php
123 }
124 }
125 }
126 }
127 }
128 }
129 }
130 }
131 }
132 }
133
134 function steps_getdeps() {
135 ?>
136 - name: Install dependencies (Linux)
137 if: runner.os == 'Linux'
138 run: |
139 sudo apt-get install \
140 libevent-dev \
141 libsasl2-dev \
142 libtbb-dev \
143 ${INSTALL_MEMCACHED} \
144 ${INSTALL_CC} ${INSTALL_CXX}
145 sudo systemctl stop memcached || true
146 - name: Install dependencies (Mac)
147 if: runner.os == 'macOS'
148 run: |
149 brew install bison flex ${INSTALL_MEMCACHED}
150 brew services stop memcached || true
151 echo MEMCACHED_BINARY="/usr/local/bin/memcached" >> ${GITHUB_ENV}
152 - name: Build memcached
153 run: |
154 if test -d memcached
155 then
156 cd memcached
157 ./autogen.sh
158 ./configure CFLAGS="-O2 -pipe" \
159 --prefix=${MEMCACHED_PREFIX} \
160 --enable-sasl \
161 --enable-sasl-pwdb \
162 --disable-coverage \
163 --disable-dependency-tracking \
164 --disable-docs \
165 --disable-extstore \
166 --disable-option-checking \
167 ;
168 make -j2
169 make install
170 cd ..
171 echo MEMCACHED_BINARY="${MEMCACHED_PREFIX}/bin/memcached" >> ${GITHUB_ENV}
172 fi
173 <?php
174 }
175
176 function steps_build() {
177 ?>
178 - name: Generate build tree (${{ env.CMAKE_BUILD_TYPE }})
179 run: cmake -S . -B build
180 - name: Build all with ${{ env.CXX }} ${{ env.CXXFLAGS }}
181 run: make -C build -j2 all
182 - name: Test
183 run: make -C build -j2 test
184 - name: Install
185 run: make -C build -j2 install DESTDIR=/tmp
186 - name: Failed tests log
187 if: ${{ failure() }}
188 run: cat build/Testing/Temporary/LastTest.log || true
189 <?php
190 }
191
192 function steps_notify() {
193 ?>
194 - name: Notify Gitter (success)
195 if: ${{ success() }}
196 run: |
197 REF=$(basename ${GITHUB_REF})
198 curl -sS "${{ secrets.GITTER }}" \
199 --data-urlencode "level=info" \
200 --data-urlencode "message=Github [${GITHUB_REPOSITORY}](https://github.com/${GITHUB_REPOSITORY}/commits/${REF}) (${REF}) [success](https://github.com/m6w6/libmemcached/actions/runs/${GITHUB_RUN_ID}) (${ImageOS}/${CC:-${CC_VND}-${CC_VER}})"
201 - name: Notify Gitter (failure)
202 if: ${{ failure() }}
203 run: |
204 REF=$(basename ${GITHUB_REF})
205 curl -sS "${{ secrets.GITTER }}" \
206 --data-urlencode "level=error" \
207 --data-urlencode "message=Github [${GITHUB_REPOSITORY}](https://github.com/${GITHUB_REPOSITORY}/commits/${REF}) (${REF}) [failure](https://github.com/m6w6/libmemcached/actions/runs/${GITHUB_RUN_ID}) (${ImageOS}/${CC:-${CC_VND}-${CC_VER}})"
208 <?php
209 }
210
211 function steps($splat_map = null) {
212 steps_setenv($splat_map);
213 steps_getdeps();
214 steps_build();
215 steps_notify();
216 }
217
218 function defaults() {
219 $os_ver = DEF[DEF["os"]];
220 $cc_vnd = DEF[$os_ver];
221 $cc_ver = DEF[$cc_vnd]["ver"];
222 return "$os_ver, $cc_vnd, $cc_ver";
223 }
224 ?>
225 name: cmake-build-ci
226 on:
227 push:
228 paths:
229 - "include/**"
230 - "src/**"
231 - "test/**"
232 - "CMake*"
233 - ".github/workflows/cmake-build-ci*"
234 branches-ignore:
235 - gh-pages
236 pull_request:
237 branches:
238 - master
239 - v1.x
240 env:
241 # defaults
242 INSTALL_MEMCACHED: memcached
243 CMAKE_BUILD_TYPE: Debug
244 BUILD_TESTING: "ON"
245 ENABLE_SASL: "OFF"
246 ENABLE_HASH_HSIEH: "ON"
247 ENABLE_DTRACE: "OFF"
248 VERBOSE: "ON"
249 OS_VND: <?=DEF["os"]?> #
250 OS_VER: <?=DEF[DEF["os"]]?> #
251 CC_VND: <?=DEF[DEF[DEF["os"]]]?> #
252 CC_VER: <?=DEF[DEF[DEF[DEF["os"]]]]["ver"]?> #
253
254 jobs:
255
256 # new memcached
257 dbg-new:
258 name: dbg-new (<?=defaults()?>)
259 runs-on: <?=DEF[DEF["os"]]?> #
260 env:
261 INSTALL_MEMCACHED:
262 MEMCACHED_PREFIX: /tmp
263 ENABLE_SASL: "ON"
264 CFLAGS: "-O0 --coverage"
265 CXXFLAGS: "-O0 --coverage"
266 steps:
267 - uses: actions/checkout@v2
268 - uses: actions/checkout@v2
269 with:
270 repository: memcached/memcached
271 path: memcached
272 ref: 1.6.7
273 <?php steps(); ?>
274 - uses: codecov/codecov-action@v1.0.13
275
276 # sanitizer build
277 dbg-san:
278 name: dbg-san (<?=defaults()?>)
279 runs-on: <?=DEF[DEF["os"]]?> #
280 env:
281 ENABLE_SANITIZERS: "address;undefined"
282 steps:
283 - uses: actions/checkout@v2
284 <?php steps(); ?>
285
286 # thread sanitizer build
287 dbg-tsan:
288 name: dbg-tsan (<?=defaults()?>)
289 runs-on: <?=DEF[DEF["os"]]?> #
290 env:
291 ENABLE_SANITIZERS: "thread"
292 steps:
293 - uses: actions/checkout@v2
294 <?php steps(); ?>
295
296 # mac build
297 dbg-mac:
298 name: dbg-mac (<?=DEF["macOS"]?>, <?=DEF[DEF["macOS"]]?>, <?=DEF[DEF[DEF["macOS"]]]["ver"]?>)
299 runs-on: <?=DEF["macOS"]?> #
300 env:
301 CFLAGS: -O0 --coverage
302 CXXFLAGS: -O0 --coverage
303 OS_VND: macOS
304 OS_VER: <?=DEF["macOS"]?> #
305 CC_VND: <?=DEF[DEF["macOS"]]?> #
306 CC_VER: <?=DEF[DEF[DEF["macOS"]]]["ver"]?> #
307 continue-on-error: true
308 steps:
309 - uses: actions/checkout@v2
310 <?php steps(false); ?>
311 - uses: codecov/codecov-action@v1.0.13
312
313 # win build
314 win-msvc:
315 name: win-msvc (<?=DEF["Windows"]?>, <?=DEF[DEF["Windows"]]?>, <?=DEF[DEF[DEF["Windows"]]]["ver"]?>)
316 runs-on: <?=DEF["Windows"]?> #
317 env:
318 CMAKE_BUILD_TYPE: Release
319 BUILD_TESTING: "OFF"
320 BISON_ROOT: "C:/msys64/usr"
321 FLEX_ROOT: "C:/msys64/usr"
322 OS_VND: Windows
323 OS_VER: <?=DEF["Windows"]?> #
324 CC_VND: <?=DEF[DEF["Windows"]]?> #
325 CC_VER: <?=DEF[DEF[DEF["Windows"]]]["ver"]?> #
326 continue-on-error: true
327 steps:
328 - uses: actions/checkout@v2
329 - name: Generate build tree (${{ env.CMAKE_BUILD_TYPE }})
330 run: cmake --config ${{ env.CMAKE_BUILD_TYPE }} -S . -B build
331 - name: Build all with ${{ env.CC_VND }}
332 run: cmake --build build --config ${{ env.CMAKE_BUILD_TYPE }}
333 - name: Install
334 run: cmake --install build --prefix installed --config ${{ env.CMAKE_BUILD_TYPE }}
335
336 # release builds
337 release:
338 strategy:
339 fail-fast: false
340 matrix:
341 os_ver: [ubuntu-20.04, ubuntu-18.04]
342 cc_vnd: [gnu, clang]
343 cc_ver: [new, cur, old]
344 runs-on: ${{ matrix.os_ver }}
345 continue-on-error: ${{ matrix.cc_vnd == 'clang' }}
346 env:
347 CMAKE_BUILD_TYPE: Release
348 OS_VND: Linux
349 OS_VER: ${{ matrix.os_ver }}
350 CC_VND: ${{ matrix.cc_vnd }}
351 CC_VER: ${{ matrix.cc_ver }}
352 steps:
353 - uses: actions/checkout@v2
354 <?php steps(true); ?>