forked from oxisto/kotlintree
-
Notifications
You must be signed in to change notification settings - Fork 1
367 lines (327 loc) · 12.2 KB
/
build.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
name: 'Build'
on:
pull_request:
push:
branches:
- 'master'
tags:
- 'v*'
workflow_dispatch:
env:
GRADLE_OPTS: -Dorg.gradle.daemon=true -Dorg.gradle.parallel=true -Dorg.gradle.welcome=never
GPG_SEC: ${{ secrets.PGP_SEC }}
GPG_PASSWORD: ${{ secrets.PGP_PASSWORD }}
jobs:
build-native:
name: 'Build native code (${{ matrix.jna-os }}-${{ matrix.jna-arch }})'
runs-on: ${{ matrix.os }}
env:
CC: gcc
CXX: g++
CFLAGS: ${{ matrix.cflags }}
CXXFLAGS: ${{ matrix.cflags }}
CMAKE_BUILD_TYPE: Release
CMAKE_COLOR_DIAGNOSTICS: ON
strategy:
fail-fast: false
matrix:
jna-os: [ linux, win32, darwin ]
jna-arch: [ x86, x86-64 ]
include:
- os: ubuntu-latest
jna-os: linux
- os: windows-latest
jna-os: win32
- os: macos-13
jna-os: darwin
- arch: x86
jna-arch: x86
cflags: '-m32'
- arch: x64
jna-arch: x86-64
cflags: '-m64'
exclude:
- jna-os: darwin
jna-arch: x86
steps:
- name: 'Set up GCC'
if: ${{ runner.os == 'Linux' }}
uses: egor-tensin/setup-gcc@v1
with:
version: latest
platform: ${{ matrix.arch }}
- name: 'Set up MinGW'
id: 'mingw'
if: ${{ runner.os == 'Windows' && matrix.arch == 'x86' }}
uses: egor-tensin/setup-mingw@v2
with:
platform: ${{ matrix.arch }}
version: 12.2.0
- name: 'Set up MinGW environment'
if: ${{ runner.os == 'Windows' }}
run: |
if [[ '${{ steps.mingw.outcome }}' == 'success' ]]
then
echo 'CC=${{ steps.mingw.outputs.gcc }}' >>${GITHUB_ENV}
echo 'CXX=${{ steps.mingw.outputs.gxx }}' >>${GITHUB_ENV}
elif [[ '${{ matrix.arch }}' == 'x86' ]]
then
echo 'CC=i686-w64-mingw32-gcc' >>${GITHUB_ENV}
echo 'CXX=i686-w64-mingw32-g++' >>${GITHUB_ENV}
else
echo 'CC=x86_64-w64-mingw32-gcc' >>${GITHUB_ENV}
echo 'CXX=x86_64-w64-mingw32-g++' >>${GITHUB_ENV}
fi
echo 'CMAKE_GENERATOR=MinGW Makefiles' >>${GITHUB_ENV}
shell: bash
- name: 'Set up CMake'
uses: lukka/get-cmake@latest
- name: 'Report tool versions'
run: |
echo '| `arch` | `uname -m` | CMake Version | GCC | GCC Version | GCC Target Architecture |' >>${GITHUB_STEP_SUMMARY}
echo '|--------|------------|---------------|-----|-------------|-------------------------|' >>${GITHUB_STEP_SUMMARY}
echo "|$(arch)|$(uname -m)|$(cmake --version | head -n1)|$(which "${CC}")|$("${CC}" --version | head -n1)|$("${CC}" -dumpmachine)|" >>${GITHUB_STEP_SUMMARY}
shell: bash
- uses: actions/checkout@v4
with:
submodules: recursive
- name: 'Build libtree-sitter.so'
if: ${{ runner.os != 'Windows' }}
run: |
cmake -S jna-lib/tree-sitter/ -B jna-lib/tree-sitter/build/
cmake --build jna-lib/tree-sitter/build/
shell: bash
- name: 'Build tree-sitter.dll'
if: ${{ runner.os == 'Windows' }}
# MinGW builds require `mingw-w64-{i686,x86_64}-icu` (`unicode/umachine.h`)
# which is not installed by default.
# In the future, we'll try to resolve this by using the `msys2/setup-msys2` Action.
continue-on-error: true
run: |
cmake -S jna-lib/tree-sitter/ -B jna-lib/tree-sitter/build/
cmake --build jna-lib/tree-sitter/build/
shell: bash
- name: 'Build libtree-sitter-cpp.so'
run: |
cmake -S jna-lib/tree-sitter-cpp/ -B jna-lib/tree-sitter-cpp/build/
cmake --build jna-lib/tree-sitter-cpp/build/
shell: bash
- name: 'Upload native libraries (libtree-sitter.so)'
if: ${{ runner.os != 'Windows' }}
uses: actions/upload-artifact@v4
with:
name: 'libtree-sitter-${{ matrix.jna-os }}-${{ matrix.jna-arch }}'
path: |
jna-lib/tree-sitter/build/libtree-sitter*.so*
jna-lib/tree-sitter/build/libtree-sitter*.dylib
if-no-files-found: error
retention-days: 1
- name: 'Upload native libraries (tree-sitter.dll)'
if: ${{ runner.os == 'Windows' }}
uses: actions/upload-artifact@v4
with:
name: 'libtree-sitter-${{ matrix.jna-os }}-${{ matrix.jna-arch }}'
path: |
jna-lib/tree-sitter/build/tree-sitter*.dll
retention-days: 1
# We put each file into the artifact separately, so that internal
# directory structure remains flat (no relative paths get stored).
- name: 'Upload native libraries (libtree-sitter-cpp.so)'
uses: actions/upload-artifact@v4
with:
name: 'libtree-sitter-${{ matrix.jna-os }}-${{ matrix.jna-arch }}'
path: |
jna-lib/tree-sitter-cpp/build/libtree-sitter*.so*
jna-lib/tree-sitter-cpp/build/libtree-sitter*.dylib
jna-lib/tree-sitter-cpp/build/tree-sitter*.dll
if-no-files-found: error
retention-days: 1
test:
name: 'Run unit tests (${{ matrix.jna-os }}-${{ matrix.jna-arch }})'
runs-on: ${{ matrix.os }}
needs: build-native
strategy:
fail-fast: false
matrix:
jna-os: [ linux, win32, darwin ]
jna-arch: [ x86, x86-64 ]
include:
- os: ubuntu-latest
jna-os: linux
- os: windows-latest
jna-os: win32
- os: macos-13
jna-os: darwin
- arch: x86
jna-arch: x86
- arch: x64
jna-arch: x86-64
exclude:
- jna-os: darwin
jna-arch: x86
# `tree-sitter-cpp.dll` depends on `libstdc++` and `libgcc_s`.
# Any attempts to load it fail with an `UnsatisfiedLinkError`
# whenever `mingw{32,64}\bin` is not in `PATH`.
#
# Until we start linking against `libstdc++` statically,
# disable tests on `win32-x86`.
- jna-os: win32
jna-arch: x86
# A possible workaround for <https://github.com/dorny/test-reporter/issues/168>.
permissions:
checks: write
contents: write
pull-requests: write
statuses: write
steps:
- uses: actions/checkout@v4
with:
# Fetch Git tags, so that semantic version can be calculated.
# Alternatively, run `git fetch --prune --unshallow --tags` as the
# next step, see
# https://github.com/actions/checkout/issues/206#issuecomment-607496604.
fetch-depth: 0
- name: 'Download native libraries'
uses: actions/download-artifact@v4
with:
name: 'libtree-sitter-${{ matrix.jna-os }}-${{ matrix.jna-arch }}'
path: jna-lib/src/main/resources/${{ matrix.jna-os }}-${{ matrix.jna-arch }}/
- name: 'Strip version information from file names'
if: ${{ runner.os != 'Windows' }}
run: |
for file in $(find jna-lib/src/main/resources/${{ matrix.jna-os }}-${{ matrix.jna-arch }}/ -type f \( -name 'lib*.so*' -o -name 'lib*.dylib' \))
do
old_file="$(basename "${file}")"
new_file="$(echo "${old_file}" | sed -n '/^lib..*\.[0-9]..*/s/\.[0-9][0-9]*//gp')"
if [[ "${old_file}" != "${new_file}" ]]
then
echo "mv ${file} $(dirname ${file})/${new_file}"
mv -v "${file}" "$(dirname "${file}")/${new_file}"
fi
done
shell: bash
- name: 'Set POSIX attributes'
if: ${{ runner.os != 'Windows' }}
run: |
find jna-lib/src/main/resources/${{ matrix.jna-os }}-${{ matrix.jna-arch }}/ -type f \( -name 'lib*.so' -o -name 'lib*.dylib' \) -exec chmod 755 '{}' ';'
find jna-lib/src/main/resources/${{ matrix.jna-os }}-${{ matrix.jna-arch }}/ -type f \( -name 'lib*.so' -o -name 'lib*.dylib' \) -exec ls -lF --color=always '{}' ';'
shell: bash
- name: 'Set up Java 11'
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 11
java-package: 'jdk+fx'
architecture: ${{ matrix.arch }}
- name: 'Run unit tests'
id: test
uses: gradle/gradle-build-action@v2
with:
gradle-version: wrapper
arguments: |
--continue
build
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish:
name: 'Publish packages'
if: ${{ github.event_name == 'push' && github.ref_type == 'tag' }}
runs-on: ubuntu-latest
needs: build-native
permissions:
# Explicitly granted, necessary for the `publish` step.
packages: write
steps:
- uses: actions/checkout@v4
with:
# Fetch Git tags, so that semantic version can be calculated.
# Alternatively, run `git fetch --prune --unshallow --tags` as the
# next step, see
# https://github.com/actions/checkout/issues/206#issuecomment-607496604.
fetch-depth: 0
- name: 'Download native libraries (darwin-x86-64)'
uses: actions/download-artifact@v4
with:
name: 'libtree-sitter-darwin-x86-64'
path: jna-lib/src/main/resources/darwin-x86-64/
- name: 'Download native libraries (linux-x86)'
uses: actions/download-artifact@v4
with:
name: 'libtree-sitter-linux-x86'
path: jna-lib/src/main/resources/linux-x86/
- name: 'Download native libraries (linux-x86-64)'
uses: actions/download-artifact@v4
with:
name: 'libtree-sitter-linux-x86-64'
path: jna-lib/src/main/resources/linux-x86-64/
- name: 'Download native libraries (win32-x86)'
uses: actions/download-artifact@v4
with:
name: 'libtree-sitter-win32-x86'
path: jna-lib/src/main/resources/win32-x86/
- name: 'Download native libraries (win32-x86-64)'
uses: actions/download-artifact@v4
with:
name: 'libtree-sitter-win32-x86-64'
path: jna-lib/src/main/resources/win32-x86-64/
- name: 'Strip version information from file names'
if: ${{ runner.os != 'Windows' }}
run: |
for file in $(find jna-lib/src/main/resources/ -type f \( -name 'lib*.so*' -o -name 'lib*.dylib' \))
do
old_file="$(basename "${file}")"
new_file="$(echo "${old_file}" | sed -n '/^lib..*\.[0-9]..*/s/\.[0-9][0-9]*//gp')"
if [[ "${old_file}" != "${new_file}" ]]
then
echo "mv ${file} $(dirname ${file})/${new_file}"
mv -v "${file}" "$(dirname "${file}")/${new_file}"
fi
done
shell: bash
- name: 'Set POSIX attributes'
if: ${{ runner.os != 'Windows' }}
run: |
find jna-lib/src/main/resources/ -type f \( -name 'lib*.so' -o -name 'lib*.dylib' \) -exec chmod 755 '{}' ';'
find jna-lib/src/main/resources/ -type f \( -name 'lib*.so' -o -name 'lib*.dylib' \) -exec ls -lF --color=always '{}' ';'
shell: bash
- name: 'Set up Java 11'
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 11
java-package: 'jdk+fx'
- name: 'Publish a release'
id: publish
uses: gradle/gradle-build-action@v2
with:
gradle-version: wrapper
arguments: |
-x test
build
publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
report:
name: 'Publish JUnit test results (${{ matrix.jna-os }}-${{ matrix.jna-arch }})'
if: ${{ always() }}
needs: test
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
jna-os: [ linux, win32, darwin ]
jna-arch: [ x86, x86-64 ]
exclude:
- jna-os: darwin
jna-arch: x86
- jna-os: win32
jna-arch: x86
permissions:
checks: write
pull-requests: write
steps:
# Uses Docker, that's why Linux-only.
- name: 'JUnit Tests (EnricoMi/publish-unit-test-result-action)'
run: |
echo ''
shell: bash