-
Notifications
You must be signed in to change notification settings - Fork 159
350 lines (313 loc) · 12.9 KB
/
Copy pathrelease.yml
File metadata and controls
350 lines (313 loc) · 12.9 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
name: Release
on:
push:
branches:
- main
workflow_dispatch:
permissions:
contents: write
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
jobs:
detect-version:
runs-on: ubuntu-latest
outputs:
changed: ${{ steps.version.outputs.changed }}
version: ${{ steps.version.outputs.version }}
tag: ${{ steps.version.outputs.tag }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- id: version
shell: bash
run: |
set -euo pipefail
version="$(tr -d '\r\n' < version.txt)"
if [[ -z "$version" ]]; then
echo "version.txt is empty" >&2
exit 1
fi
changed="false"
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
changed="true"
else
before="${{ github.event.before }}"
if [[ -z "$before" || "$before" == "0000000000000000000000000000000000000000" ]]; then
changed="true"
elif git cat-file -e "${before}:version.txt" 2>/dev/null; then
previous="$(git show "${before}:version.txt" | tr -d '\r\n')"
if [[ "$previous" != "$version" ]]; then
changed="true"
fi
else
changed="true"
fi
fi
echo "changed=$changed" >> "$GITHUB_OUTPUT"
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "tag=v$version" >> "$GITHUB_OUTPUT"
build:
needs: detect-version
if: needs.detect-version.outputs.changed == 'true'
strategy:
fail-fast: false
matrix:
include:
- os: windows-2022
preset: x64-release
arch: x64
artifact_name: YSMParser-windows-x64
archive_name: YSMParser-${{ needs.detect-version.outputs.version }}-windows-x64
binary_relpath: out/install/x64-release/YSMParser.exe
jni_relpath: out/install/x64-release/YSMParserJNI.dll
- os: windows-2022
preset: x86-release
arch: x86
artifact_name: YSMParser-windows-x86
archive_name: YSMParser-${{ needs.detect-version.outputs.version }}-windows-x86
binary_relpath: out/install/x86-release/YSMParser.exe
jni_relpath: out/install/x86-release/YSMParserJNI.dll
- os: ubuntu-24.04
preset: linux-release
arch: x64
artifact_name: YSMParser-linux-x64
archive_name: YSMParser-${{ needs.detect-version.outputs.version }}-linux-x64
binary_relpath: out/install/linux-release/YSMParser
jni_relpath: out/install/linux-release/libYSMParserJNI.so
- os: macos-14
preset: macos-release
arch: arm64
artifact_name: YSMParser-macos-arm64
archive_name: YSMParser-${{ needs.detect-version.outputs.version }}-macos-arm64
binary_relpath: out/install/macos-release/YSMParser
jni_relpath: out/install/macos-release/libYSMParserJNI.dylib
- os: ubuntu-24.04
preset: wasm-release
arch: wasm32
artifact_name: YSMParser-wasm-node
archive_name: YSMParser-${{ needs.detect-version.outputs.version }}-wasm-node
binary_relpath: out/install/wasm-release/YSMParser.js
install_dir: out/install/wasm-release
package_web_frontend: 'false'
- os: ubuntu-24.04
preset: wasm-web-release
arch: wasm32
artifact_name: YSMParser-wasm-web
archive_name: YSMParser-${{ needs.detect-version.outputs.version }}-wasm-web
binary_relpath: out/install/wasm-web-release/YSMParser.js
install_dir: out/install/wasm-web-release
package_web_frontend: 'true'
# --- New targets ---
- os: ubuntu-24.04-arm
preset: linux-arm64-release
arch: arm64
artifact_name: YSMParser-linux-arm64
archive_name: YSMParser-${{ needs.detect-version.outputs.version }}-linux-arm64
binary_relpath: out/install/linux-arm64-release/YSMParser
jni_relpath: out/install/linux-arm64-release/libYSMParserJNI.so
- os: ubuntu-24.04
preset: loongarch64-release
arch: loongarch64
artifact_name: YSMParser-linux-loongarch64
archive_name: YSMParser-${{ needs.detect-version.outputs.version }}-linux-loongarch64
binary_relpath: out/install/loongarch64-release/YSMParser
jni_relpath: ''
- os: ubuntu-24.04
preset: riscv64-release
arch: riscv64
artifact_name: YSMParser-linux-riscv64
archive_name: YSMParser-${{ needs.detect-version.outputs.version }}-linux-riscv64
binary_relpath: out/install/riscv64-release/YSMParser
jni_relpath: ''
- os: ubuntu-24.04
preset: android-arm64-release
arch: android-arm64
artifact_name: YSMParser-android-arm64-v8a
archive_name: YSMParser-${{ needs.detect-version.outputs.version }}-android-arm64-v8a
binary_relpath: ''
jni_relpath: out/install/android-arm64-release/libYSMParserJNI.so
install_dir: out/install/android-arm64-release
package_android: 'true'
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v6
- name: Setup Ninja
if: matrix.os != 'ubuntu-24.04-arm'
uses: seanmiddleditch/gha-setup-ninja@v5
- name: Setup Ninja (ARM64)
if: matrix.os == 'ubuntu-24.04-arm'
run: sudo apt-get update -qq && sudo apt-get install -y -qq ninja-build
- name: Setup Emscripten
if: matrix.arch == 'wasm32'
uses: mymindstorm/setup-emsdk@v14
with:
version: latest
- name: Setup MSVC environment
if: runner.os == 'Windows'
uses: ilammy/msvc-dev-cmd@v1
with:
arch: ${{ matrix.arch }}
- name: Setup LoongArch64 cross-compiler
if: matrix.arch == 'loongarch64'
run: |
set -euo pipefail
# Fetch latest release assets from loongson/build-tools (GitHub-hosted)
ASSET_URL=$(curl -fsSL \
https://api.github.com/repos/loongson/build-tools/releases/latest \
| python3 -c "
import sys, json
assets = json.load(sys.stdin).get('assets', [])
# Prefer Linux-hosted cross-tools; skip Windows-hosted ones
for a in assets:
name = a['name']
if 'cross-tools' not in name: continue
if not name.endswith(('.tar.xz', '.tar.gz', '.tgz')): continue
if 'Windows' in name or 'windows' in name or 'win32' in name or 'win64' in name:
continue
if 'loongarch64' not in name: continue
print(a['browser_download_url'])
break
")
if [[ -z "${ASSET_URL}" ]]; then
echo "No suitable Linux-hosted loongarch64 asset found. Available assets:"
curl -fsSL https://api.github.com/repos/loongson/build-tools/releases/latest \
| python3 -c "import sys,json;[print(' ',a['name']) for a in json.load(sys.stdin).get('assets',[])]"
exit 1
fi
echo "Downloading ${ASSET_URL}"
curl -fsSL -o loongarch64-toolchain.tar.xz "${ASSET_URL}"
sudo mkdir -p /opt/loongarch64-toolchain
sudo tar -xf loongarch64-toolchain.tar.xz -C /opt/loongarch64-toolchain
# Find the cross-compiler (prefix varies between releases)
GCC=$(find /opt/loongarch64-toolchain -name 'loongarch64*-gcc' -type f | head -1)
GXX=$(find /opt/loongarch64-toolchain -name 'loongarch64*-g++' -type f | head -1)
if [[ -z "${GCC}" || -z "${GXX}" ]]; then
echo "Could not find loongarch64 gcc/g++ in toolchain"
find /opt/loongarch64-toolchain -name '*-gcc' -type f
exit 1
fi
echo "Found gcc: ${GCC}"
echo "Found g++: ${GXX}"
"${GXX}" --version
# Add bin directory to PATH
echo "$(dirname "${GCC}")" >> "${GITHUB_PATH}"
# Rewrite toolchain file with detected compiler paths
cat > cmake/toolchains/loongarch64-linux-gnu.cmake << EOF
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR loongarch64)
set(CMAKE_C_COMPILER ${GCC})
set(CMAKE_CXX_COMPILER ${GXX})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
EOF
- name: Setup RISC-V64 cross-compiler
if: matrix.arch == 'riscv64'
run: |
set -euo pipefail
sudo apt-get update -qq
sudo apt-get install -y -qq \
gcc-riscv64-linux-gnu \
g++-riscv64-linux-gnu \
libc6-dev-riscv64-cross
- name: Setup Android NDK
if: matrix.arch == 'android-arm64'
run: |
set -euo pipefail
NDK_VERSION="r27c"
NDK_ZIP="android-ndk-${NDK_VERSION}-linux.zip"
wget -q "https://dl.google.com/android/repository/${NDK_ZIP}"
unzip -q "${NDK_ZIP}"
echo "ANDROID_NDK_HOME=${PWD}/android-ndk-${NDK_VERSION}" >> "${GITHUB_ENV}"
- name: Configure
run: cmake --preset ${{ matrix.preset }}
- name: Build
run: cmake --build --preset ${{ matrix.preset }} --parallel
- name: Install
run: cmake --install out/build/${{ matrix.preset }} --prefix out/install/${{ matrix.preset }}
- name: Package archive
shell: bash
run: |
set -euo pipefail
mkdir -p package
# Copy CLI binary (if present)
if [[ -n "${{ matrix.binary_relpath }}" ]]; then
cp "${{ matrix.binary_relpath }}" package/
fi
# Copy JNI library (if present)
if [[ -n "${{ matrix.jni_relpath }}" ]]; then
cp "${{ matrix.jni_relpath }}" package/
fi
# WASM: copy .wasm file
if [[ "${{ matrix.arch }}" == "wasm32" ]]; then
wasm_file="$(find "${{ matrix.install_dir }}" -maxdepth 1 -type f -name '*.wasm' | head -n 1)"
if [[ -z "$wasm_file" ]]; then
echo "No .wasm file found in ${{ matrix.install_dir }}" >&2
exit 1
fi
cp "$wasm_file" package/
fi
# WASM web: include frontend
if [[ "${{ matrix.package_web_frontend }}" == "true" ]]; then
cp web/index.html package/
cp web/app.js package/
fi
# Android: compile Java classes and include JAR
if [[ "${{ matrix.package_android }}" == "true" ]]; then
mkdir -p package/java
javac -d package/java java/com/ysm/parser/*.java java/Example.java
cd package/java && jar cf ../YSMParserJNI.jar . && cd ../..
rm -rf package/java
# Package .so in ABI-named directory for drop-in use
abi_dir="arm64-v8a"
mkdir -p "package/${abi_dir}"
if [[ -f "package/libYSMParserJNI.so" ]]; then
mv "package/libYSMParserJNI.so" "package/${abi_dir}/"
fi
fi
cp LICENSE.txt package/
if [[ -f README.md ]]; then
cp README.md package/
fi
if [[ "${{ runner.os }}" == "Windows" ]]; then
powershell -NoProfile -Command "Compress-Archive -Path package\\* -DestinationPath '${{ matrix.archive_name }}.zip'"
else
tar -C package -czf "${{ matrix.archive_name }}.tar.gz" .
fi
- name: Upload packaged artifact
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.artifact_name }}
path: |
${{ matrix.archive_name }}.zip
${{ matrix.archive_name }}.tar.gz
if-no-files-found: error
release:
needs:
- detect-version
- build
if: needs.detect-version.outputs.changed == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Download artifacts
uses: actions/download-artifact@v5
with:
path: artifacts
- name: Create or update release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
set -euo pipefail
tag="${{ needs.detect-version.outputs.tag }}"
title="YSMParser ${{ needs.detect-version.outputs.version }}"
if gh release view "$tag" >/dev/null 2>&1; then
gh release edit "$tag" --title "$title" --notes "Automated build for $tag"
else
gh release create "$tag" --title "$title" --notes "Automated build for $tag"
fi
find artifacts -type f \( -name '*.zip' -o -name '*.tar.gz' \) -print0 | \
xargs -0 -I{} gh release upload "$tag" "{}" --clobber