-
Notifications
You must be signed in to change notification settings - Fork 89
408 lines (372 loc) · 16.5 KB
/
main.yml
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
name: CI
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches: [ master ]
tags: [ '*' ]
pull_request:
branches: [ master ]
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
Windows:
runs-on: windows-latest
needs: Linux
strategy:
fail-fast: true
matrix:
include:
- arch: x86
- arch: x64
steps:
- name: "Set Build Type"
id: build_type
run: |
if ("${{ github.ref }}".StartsWith("refs/tags/")) {
echo "BUILD_TYPE::Release";
echo "::set-output name=BUILD_TYPE::Release";
} else {
echo "BUILD_TYPE::Debug";
echo "::set-output name=BUILD_TYPE::Debug";
}
if ("${{ matrix.arch }}" -eq "x64") {
echo "Arch:x64";
echo "::set-output name=BUILD_ARCH::x64";
} else {
echo "Arch:Win32";
echo "::set-output name=BUILD_ARCH::Win32";
}
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
# https://github.com/OpenTTD/OpenTTD/blob/master/.github/workflows/ci-build.yml
# "restore-cache" which is done by "run-vcpkg" uses Windows tar.
# A git clone on windows marks a few files as read-only; when Windows tar
# tries to extract the cache over this folder, it fails, despite the files
# being identical. This failure shows up as an warning in the logs. We
# avoid this by simply removing the read-only mark from the git folder.
# In other words: this is a hack!
# See: https://github.com/lukka/run-vcpkg/issues/61
# - name: Remove read-only flag from vcpkg git folder
# shell: powershell
# run: |
# attrib -r "c:\vcpkg\.git\*.*" /s
# - name: Prepare vcpkg (with cache)
# uses: lukka/run-vcpkg@v6
# with:
# vcpkgDirectory: 'c:/vcpkg'
# doNotUpdateVcpkg: true
# vcpkgArguments: 'liblzma libpng lzo zlib'
# vcpkgTriplet: '${{ matrix.arch }}-windows-static'
# - name: Install MSVC problem matcher
# uses: ammaraskar/msvc-problem-matcher@master
- name: 'Run CMake with VS16'
uses: lukka/run-cmake@v3
with:
cmakeListsOrSettingsJson: CMakeListsTxtAdvanced
cmakeListsTxtPath: '${{ github.workspace }}/CMakeLists.txt'
buildDirectory: "${{ github.workspace }}/../../_temp/windows"
useVcpkgToolchainFile: true
cmakeBuildType: ${{ steps.build_type.outputs.BUILD_TYPE }}
buildWithCMake: true
cmakeGenerator: VS16Win64
cmakeAppendedArgs: -A ${{steps.build_type.outputs.BUILD_ARCH }}
buildWithCMakeArgs: --config ${{ steps.build_type.outputs.BUILD_TYPE }}
- name: "Check file existence"
uses: andstor/file-existence-action@v1
with:
allow_failure: true
files: "${{ github.workspace }}/../../_temp/windows/src/${{ steps.build_type.outputs.BUILD_TYPE }}/simple.dll, ${{ github.workspace }}/../../_temp/windows/cppjieba/src/cppjieba/dict/jieba.dict.utf8"
# can't build
# npm run
# - uses: actions/setup-node@v2
# with:
# node-version: '16'
# - name: run node example
# working-directory: ./examples/node/
# run: |
# npm install
# npm run p -- --ext_path="${{ github.workspace }}/../../_temp/windows/src/${{ steps.build_type.outputs.BUILD_TYPE }}/" --dict_path="${{ github.workspace }}/../../_temp/windows/cppjieba/src/cppjieba/dict/"
# - name: 'Run CTest'
# run: ctest -C ${{ env.BUILD_TYPE }}
# working-directory: "${{ github.workspace }}/../../_temp/windows"
# python run
# - uses: actions/setup-python@v4
# with:
# python-version: '3.x' # Version range or exact version of a Python version to use, using SemVer's version range syntax
# - name: run python example
# working-directory: ./examples/python3/
# run: python db_connector.py "${{ github.workspace }}/../../_temp/windows/src/${{ steps.build_type.outputs.BUILD_TYPE }}/simple"
- name: Package
if: startsWith(github.ref, 'refs/tags/')
run: |
mkdir libsimple-windows-${{ matrix.arch }}
Copy-Item -Path src/${{ steps.build_type.outputs.BUILD_TYPE }}/simple.dll,cppjieba/src/cppjieba/dict/ -Destination libsimple-windows-${{ matrix.arch }}/ -Recurse
Compress-Archive -Path libsimple-windows-${{ matrix.arch }} -DestinationPath libsimple-windows-${{ matrix.arch }}.zip
working-directory: "${{ github.workspace }}/../../_temp/windows/"
- name: Release
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v1
with:
draft: true
files: "D:/a/_temp/windows/libsimple-windows-${{ matrix.arch }}.zip"
# files: "${{ github.workspace }}/../../_temp/windows/libsimple-windows-${{ matrix.arch }}.zip"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# copy from https://github.com/Cyan4973/xxHash/blob/dev/.github/workflows/ci.yml
# Linux ARM64
# All tests are using QEMU and gcc cross compiler.
qemu-consistency:
name: QEMU ${{ matrix.name }}
needs: Linux
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true # 'false' means Don't stop matrix workflows even if some matrix failed.
matrix:
include: [
{ name: 'ARM64', xcc_pkg: gcc-aarch64-linux-gnu, xcc: aarch64-linux-gnu-gcc, xemu_pkg: qemu-system-arm, xemu: qemu-aarch64-static, os: ubuntu-latest, },
{ name: 'ARM64, gcc-9', xcc_pkg: gcc-9-aarch64-linux-gnu, xcc: aarch64-linux-gnu-gcc-9, xemu_pkg: qemu-system-arm, xemu: qemu-aarch64-static, os: ubuntu-20.04, },
]
env: # Set environment variables
CC: ${{ matrix.xcc }}
XEMU: ${{ matrix.xemu }}
# LDFLAGS: -static
steps:
- uses: actions/checkout@v2 # https://github.com/actions/checkout
- name: apt update & install (1)
run: |
sudo apt-get update
sudo apt-get install gcc-multilib g++-multilib qemu-utils qemu-user-static
- name: Environment info (1)
run: |
echo && apt-cache search "^gcc-" | grep "linux" | sort
- name: apt update & install (2)
run: |
sudo apt-get install ${{ matrix.xcc_pkg }} ${{ matrix.xemu_pkg }}
- name: Environment info (2)
run: |
echo && which $CC
echo && $CC --version
echo && $CC -v # Show built-in specs
echo && which $XEMU
echo && $XEMU --version
- name: ARM64
uses: lukka/run-cmake@v3
with:
cmakeListsOrSettingsJson: CMakeListsTxtAdvanced
cmakeListsTxtPath: '${{ github.workspace }}/CMakeLists.txt'
cmakeBuildType: 'Release'
buildDirectory: "${{ github.workspace }}/build"
buildWithCMake: true
buildWithCMakeArgs: --config Release
# cmakeAppendedArgs: " -DCODE_COVERAGE=OFF -DBUILD_SHELL=OFF -DBUILD_TEST_EXAMPLE=OFF -DBUILD_STATIC"
cmakeAppendedArgs: " -DCODE_COVERAGE=OFF -DBUILD_SHELL=OFF -DBUILD_TEST_EXAMPLE=OFF"
- name: "Check file existence"
uses: andstor/file-existence-action@v1
with:
allow_failure: true
# files: "${{ github.workspace }}/build/src/libsimple.a, ${{ github.workspace }}/build/src/libPINYIN_TEXT.a, ${{ github.workspace }}/build/test/dict/jieba.dict.utf8"
files: "${{ github.workspace }}/build/src/libsimple.so, ${{ github.workspace }}/build/test/dict/jieba.dict.utf8"
- name: Package
if: startsWith(github.ref, 'refs/tags/')
run: |
mkdir libsimple-${{ matrix.xcc }}
# cp -r src/libsimple.a src/libPINYIN_TEXT.a test/dict/ libsimple-linux-${{ matrix.xcc }}/
cp -r src/libsimple.so test/dict/ libsimple-${{ matrix.xcc }}/
zip -r libsimple-${{ matrix.xcc }}.zip libsimple-${{ matrix.xcc }}
working-directory: "${{ github.workspace }}/build"
- name: Release
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v1
with:
draft: true
files: ${{ github.workspace }}/build/libsimple-${{ matrix.xcc }}.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Linux:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
include:
- os: ubuntu-20.04
- os: ubuntu-latest
steps:
- name: "Release Build Type"
if: startsWith(github.ref, 'refs/tags/')
run: echo "BUILD_TYPE=Release" >> $GITHUB_ENV
- name: "Debug Build Type"
if: startsWith(github.ref, 'refs/tags/') != true
run: echo "BUILD_TYPE=Debug" >> $GITHUB_ENV
- uses: actions/checkout@v2
- name: Update apt-get
run: sudo apt-get update
- name: Install lcov
if: startsWith(github.ref, 'refs/tags/') != true
run: sudo apt-get install lcov
- name: Install codecov
if: startsWith(github.ref, 'refs/tags/') != true
shell: bash
run: sudo pip install codecov
- name: 'Run CMake'
uses: lukka/run-cmake@v3
if: startsWith(github.ref, 'refs/tags/') != true
with:
cmakeListsOrSettingsJson: CMakeListsTxtAdvanced
cmakeListsTxtPath: '${{ github.workspace }}/CMakeLists.txt'
cmakeBuildType: ${{ env.BUILD_TYPE }}
buildDirectory: "${{ github.workspace }}/build"
buildWithCMake: true
buildWithCMakeArgs: --config ${{ env.BUILD_TYPE }}
cmakeAppendedArgs: " -DCODE_COVERAGE=ON "
- name: 'Run CMake without coverage'
if: startsWith(github.ref, 'refs/tags/')
uses: lukka/run-cmake@v3
with:
cmakeListsOrSettingsJson: CMakeListsTxtAdvanced
cmakeListsTxtPath: '${{ github.workspace }}/CMakeLists.txt'
cmakeBuildType: ${{ env.BUILD_TYPE }}
buildDirectory: "${{ github.workspace }}/build"
buildWithCMake: true
buildWithCMakeArgs: --config ${{ env.BUILD_TYPE }}
cmakeAppendedArgs: " -DCODE_COVERAGE=OFF -DBUILD_SHELL=OFF -DBUILD_TEST_EXAMPLE=OFF"
- name: 'Run CTest'
if: ${{ startsWith(github.ref, 'refs/tags/') != true && matrix.os == 'ubuntu-latest' }}
run: ctest -V -C ${{ env.BUILD_TYPE }}
working-directory: "${{ github.workspace }}/build"
# CODE COVERAGE
- name: Code coverage - Capture coverage info
if: ${{ startsWith(github.ref, 'refs/tags/') != true && matrix.os == 'ubuntu-latest' }}
run: lcov --directory . --capture --output-file coverage.info
- name: Code coverage - Filter out system, external, and unit test source files
if: ${{ startsWith(github.ref, 'refs/tags/') != true && matrix.os == 'ubuntu-latest' }}
run: lcov --remove coverage.info --output-file coverage_filter.info '/Library/*' '/usr/*' '*/test/*' '*/cmrc/*' '*/entry.cc' '*/simple_highlight.*'
- name: Code coverage - Output coverage data for debugging
if: ${{ startsWith(github.ref, 'refs/tags/') != true && matrix.os == 'ubuntu-latest' }}
run: lcov --list coverage_filter.info
- name: Code coverage - Upload to CodeCov
if: ${{ startsWith(github.ref, 'refs/tags/') != true && matrix.os == 'ubuntu-latest' }}
run: bash <(curl -s https://codecov.io/bash) -f coverage_filter.info || echo "Codecov did not collect coverage reports"
- name: "Check file existence"
uses: andstor/file-existence-action@v1
with:
allow_failure: true
files: "${{ github.workspace }}/build/src/libsimple.so, ${{ github.workspace }}/build/test/dict/jieba.dict.utf8"
# npm run
- uses: actions/setup-node@v2
if: startsWith(github.ref, 'refs/tags/') != true
with:
node-version: '20'
- name: run node example
if: startsWith(github.ref, 'refs/tags/') != true
working-directory: ./examples/node/
run: |
npm install
npm run p -- --ext_path="${{ github.workspace }}/build/src/" --dict_path="${{ github.workspace }}/build/test/dict/"
npm run b -- --ext_path="${{ github.workspace }}/build/src/" --dict_path="${{ github.workspace }}/build/test/dict/"
# python run
- uses: actions/setup-python@v4
if: startsWith(github.ref, 'refs/tags/') != true
with:
python-version: '3.10' # Version range or exact version of a Python version to use, using SemVer's version range syntax
- name: run python example
if: startsWith(github.ref, 'refs/tags/') != true
working-directory: ./examples/python3/
run: python db_connector.py "${{ github.workspace }}/build/src/libsimple"
# create release
- name: "Build Changelog"
id: build_changelog
if: ${{ startsWith(github.ref, 'refs/tags/') && matrix.os == 'ubuntu-latest' }}
uses: mikepenz/release-changelog-builder-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Package
if: startsWith(github.ref, 'refs/tags/')
run: |
mkdir libsimple-linux-${{ matrix.os }}
cp -r src/libsimple.so test/dict/ libsimple-linux-${{ matrix.os }}/
zip -r libsimple-linux-${{ matrix.os }}.zip libsimple-linux-${{ matrix.os }}
working-directory: "${{ github.workspace }}/build"
- name: Release without changelog
if: ${{ startsWith(github.ref, 'refs/tags/') && matrix.os != 'ubuntu-latest' }}
uses: softprops/action-gh-release@v1
with:
draft: true
files: ${{ github.workspace }}/build/libsimple-linux-${{ matrix.os }}.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Release
if: ${{ startsWith(github.ref, 'refs/tags/') && matrix.os == 'ubuntu-latest' }}
uses: softprops/action-gh-release@v1
with:
draft: true
files: ${{ github.workspace }}/build/libsimple-linux-${{ matrix.os }}.zip
body: ${{steps.build_changelog.outputs.changelog}}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MacOS:
runs-on: macos-latest
needs: Linux
steps:
- name: "Release Build Type"
if: startsWith(github.ref, 'refs/tags/')
run: echo "BUILD_TYPE=Release" >> $GITHUB_ENV
- name: "Debug Build Type"
if: startsWith(github.ref, 'refs/tags/') != true
run: echo "BUILD_TYPE=Debug" >> $GITHUB_ENV
- uses: actions/checkout@v2
- name: 'Run CMake'
uses: lukka/run-cmake@v3
with:
cmakeListsOrSettingsJson: CMakeListsTxtAdvanced
cmakeListsTxtPath: '${{ github.workspace }}/CMakeLists.txt'
cmakeBuildType: ${{ env.BUILD_TYPE }}
buildDirectory: "${{ github.workspace }}/../../_temp/macos"
buildWithCMake: true
cmakeAppendedArgs: -DCMAKE_INSTALL_PREFIX="${{ github.workspace }}/../../_temp/macos/install"
buildWithCMakeArgs: --config ${{ env.BUILD_TYPE }}
- name: 'Run CTest'
run: ctest -C ${{ env.BUILD_TYPE }}
working-directory: "${{ github.workspace }}/../../_temp/macos"
- name: "Check file existence"
uses: andstor/file-existence-action@v1
with:
allow_failure: true
files: "${{ github.workspace }}/../../_temp/macos/src/libsimple.dylib, ${{ github.workspace }}/../../_temp/macos/test/dict/jieba.dict.utf8"
- uses: actions/setup-node@v2
with:
node-version: '20'
# - uses: actions/setup-python@v5
# with:
# python-version: '3.12' # Version range or exact version of a Python version to use, using SemVer's version range syntax
# npm run
- name: run node example
working-directory: ./examples/node/
run: |
brew install python-setuptools
npm install
npm run p -- --ext_path="${{ github.workspace }}/../../_temp/macos/src/" --dict_path="${{ github.workspace }}/../../_temp/macos/test/dict/"
# don't run this as it's toooo slow
# npm run b -- --ext_path="${{ github.workspace }}/../../_temp/macos/src/" --dict_path="${{ github.workspace }}/../../_temp/macos/test/dict/"
# python run
# - name: run python example
# working-directory: ./examples/python3/
# run: |
# python db_connector.py "${{ github.workspace }}/../../_temp/macos/src/libsimple"
- name: Package
if: startsWith(github.ref, 'refs/tags/')
run: |
mkdir libsimple-osx-x64
sudo xattr -r -d com.apple.quarantine src/libsimple.dylib
cp -r src/libsimple.dylib test/dict libsimple-osx-x64/
zip -r libsimple-osx-x64.zip libsimple-osx-x64
working-directory: "${{ github.workspace }}/../../_temp/macos"
- name: Release
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v1
with:
draft: true
files: ${{ github.workspace }}/../../_temp/macos/libsimple-osx-x64.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: build-iOS
run: ./build-ios.sh