-
-
Notifications
You must be signed in to change notification settings - Fork 5
389 lines (353 loc) · 12.9 KB
/
Copy pathbuild.yml
File metadata and controls
389 lines (353 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
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
name: Build HarmonyOS
on:
push:
branches: [ master, main ]
tags: [ 'v*' ]
pull_request:
branches: [ master, main ]
workflow_dispatch:
inputs:
build_type:
description: 'Build type'
required: false
default: 'debug'
type: choice
options:
- debug
- release
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
NODE_OPTIONS: '--max_old_space_size=8192'
SDK_VERSION: '6.1-Release'
CI_TARGET_API_VERSION: '24'
CMDLINE_TOOLS_VERSION: '5.1.0.840'
CACHE_VERSION: 'v10'
# v0.6.0
AUDIO_HAPTICS_SDK_REF: 'b71b47a08fd400996ed374a97e1bff73bac2932e'
jobs:
build:
name: Build (${{ github.event.inputs.build_type || 'debug' }})
runs-on: ubuntu-latest
timeout-minutes: 90
steps:
# ── 基础环境 ──
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
- name: Setup Node.js 18
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Run repository checks
run: npm run check
- name: Checkout audio haptics SDK
uses: actions/checkout@v4
with:
repository: AlkaidLab/moonlight-audio-haptics
ref: ${{ env.AUDIO_HAPTICS_SDK_REF }}
path: audio-haptics-sdk
fetch-depth: 1
persist-credentials: false
- name: Setup Java 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
- name: Get version info
id: version
run: |
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
VERSION="${GITHUB_REF#refs/tags/v}"
else
VERSION="$(git describe --tags --always --dirty 2>/dev/null || echo "dev-${GITHUB_SHA:0:7}")"
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Version: $VERSION"
- name: Determine build mode
id: build-mode
run: |
if [[ "${{ github.event.inputs.build_type }}" == "release" ]] || [[ "$GITHUB_REF" == refs/tags/v* ]]; then
echo "mode=release" >> "$GITHUB_OUTPUT"
else
echo "mode=debug" >> "$GITHUB_OUTPUT"
fi
- name: Check signing config
id: signing
run: |
if [[ -n "${{ secrets.SIGNING_CERT }}" ]] && [[ -n "${{ secrets.SIGNING_PROFILE }}" ]] && [[ -n "${{ secrets.SIGNING_KEYSTORE }}" ]]; then
echo "available=true" >> "$GITHUB_OUTPUT"
else
echo "available=false" >> "$GITHUB_OUTPUT"
fi
# ── 磁盘空间 ──
- name: Free disk space
run: |
sudo rm -rf /usr/share/dotnet /opt/ghc /usr/local/share/boost \
"$AGENT_TOOLSDIRECTORY" /opt/hostedtoolcache/CodeQL
df -h /
# ── SDK 下载 & 缓存 ──
- name: Cache OHOS SDK & tools
id: cache-sdk
uses: actions/cache@v4
with:
path: |
~/ohos-sdk
~/cmdline-tools
key: ohos-${{ env.SDK_VERSION }}-tools-${{ env.CMDLINE_TOOLS_VERSION }}-${{ env.CACHE_VERSION }}
- name: Download OHOS SDK
if: steps.cache-sdk.outputs.cache-hit != 'true'
run: |
set -euo pipefail
SDK_URL="https://repo.huaweicloud.com/harmonyos/os/${{ env.SDK_VERSION }}/ohos-sdk-windows_linux-public.tar.gz"
mkdir -p ~/ohos-sdk && cd ~/ohos-sdk
curl -L --retry 3 --retry-delay 10 -o sdk.tar.gz "$SDK_URL" --progress-bar --fail
tar -xzf sdk.tar.gz && rm sdk.tar.gz
if [ -d "linux" ]; then
for zip in linux/*.zip; do
[ -f "$zip" ] && unzip -q -o "$zip" -d .
done
rm -rf linux windows
fi
- name: Download command-line-tools
if: steps.cache-sdk.outputs.cache-hit != 'true'
run: |
set -euo pipefail
TOOLS_VER="${{ env.CMDLINE_TOOLS_VERSION }}"
TOOLS_PREFIX="${TOOLS_VER%.*}"
TOOLS_URL="https://repo.huaweicloud.com/harmonyos/ohpm/${TOOLS_PREFIX}/commandline-tools-linux-x64-${TOOLS_VER}.zip"
cd ~
curl -L --retry 3 --retry-delay 10 -o cmdline-tools.zip "$TOOLS_URL" --progress-bar --fail
unzip -q cmdline-tools.zip
[ -d "command-line-tools" ] && mv command-line-tools ~/cmdline-tools
rm -f cmdline-tools.zip
chmod -R +x ~/cmdline-tools/ohpm/bin/ 2>/dev/null || true
# ── SDK 结构修正 & 补丁 ──
- name: Normalize SDK layout
run: |
chmod +x ci/normalize-sdk.sh
OUTPUT=$(ci/normalize-sdk.sh ~/ohos-sdk)
echo "$OUTPUT"
API_VER=$(echo "$OUTPUT" | grep "SDK_API_VERSION=" | cut -d= -f2)
TARGET_SDK_VERSION=$(echo "$OUTPUT" | grep "HOS_TARGET_SDK_VERSION=" | cut -d= -f2)
echo "SDK_API_VERSION=$API_VER" >> "$GITHUB_ENV"
echo "TARGET_SDK_VERSION=$TARGET_SDK_VERSION" >> "$GITHUB_ENV"
echo "Target SDK version: $TARGET_SDK_VERSION"
- name: Setup environment
run: |
SDK_HOME=~/ohos-sdk
NATIVE_DIR="$(find "$SDK_HOME" -maxdepth 3 -name "native" -type d | head -1)"
TOOLCHAINS_DIR="$(find "$SDK_HOME" -maxdepth 3 -name "toolchains" -type d | head -1)"
[ -n "$TOOLCHAINS_DIR" ] && echo "$TOOLCHAINS_DIR" >> "$GITHUB_PATH"
[ -n "$NATIVE_DIR" ] && echo "${NATIVE_DIR}/build-tools/cmake/bin" >> "$GITHUB_PATH"
echo "$HOME/cmdline-tools/ohpm/bin" >> "$GITHUB_PATH"
echo "$HOME/cmdline-tools/hvigor/bin" >> "$GITHUB_PATH"
{
echo "OHOS_SDK_HOME=$SDK_HOME"
echo "HOS_SDK_HOME=$SDK_HOME"
echo "OHOS_BASE_SDK_HOME=$SDK_HOME"
echo "DEVECO_SDK_HOME=$SDK_HOME"
} >> "$GITHUB_ENV"
# ── build-profile.json5 ──
- name: Create build profile (unsigned)
if: steps.signing.outputs.available != 'true'
run: |
cat > build-profile.json5 << EOF
{
"app": {
"signingConfigs": [],
"products": [
{
"name": "default",
"compatibleSdkVersion": "5.0.0(12)",
"compileSdkVersion": "${TARGET_SDK_VERSION}",
"targetSdkVersion": "${TARGET_SDK_VERSION}",
"runtimeOS": "HarmonyOS",
"buildOption": {
"strictMode": {
"caseSensitiveCheck": true,
"useNormalizedOHMUrl": true
}
}
}
],
"buildModeSet": [
{ "name": "debug" },
{ "name": "release" }
]
},
"modules": [
{
"name": "entry",
"srcPath": "./entry",
"targets": [{ "name": "default", "applyToProducts": ["default"] }]
},
{
"name": "nativelib",
"srcPath": "./nativelib",
"targets": [{ "name": "default", "applyToProducts": ["default"] }]
}
]
}
EOF
- name: Create build profile (signed)
if: steps.signing.outputs.available == 'true'
run: |
mkdir -p .signing
echo "${{ secrets.SIGNING_CERT }}" | base64 -d > .signing/cert.cer
echo "${{ secrets.SIGNING_PROFILE }}" | base64 -d > .signing/profile.p7b
echo "${{ secrets.SIGNING_KEYSTORE }}" | base64 -d > .signing/keystore.p12
CERT_PATH="$(pwd)/.signing/cert.cer"
PROFILE_PATH="$(pwd)/.signing/profile.p7b"
KEYSTORE_PATH="$(pwd)/.signing/keystore.p12"
KEY_ALIAS="${{ secrets.SIGNING_KEY_ALIAS }}"
KEY_PASSWORD="${{ secrets.SIGNING_KEY_PASSWORD }}"
STORE_PASSWORD="${{ secrets.SIGNING_STORE_PASSWORD }}"
cat > build-profile.json5 << PROFILE_EOF
{
"app": {
"signingConfigs": [
{
"name": "default",
"type": "HarmonyOS",
"material": {
"certpath": "${CERT_PATH}",
"keyAlias": "${KEY_ALIAS}",
"keyPassword": "${KEY_PASSWORD}",
"profile": "${PROFILE_PATH}",
"signAlg": "SHA256withECDSA",
"storeFile": "${KEYSTORE_PATH}",
"storePassword": "${STORE_PASSWORD}"
}
}
],
"products": [
{
"name": "default",
"signingConfig": "default",
"compatibleSdkVersion": "5.0.0(12)",
"compileSdkVersion": "${TARGET_SDK_VERSION}",
"targetSdkVersion": "${TARGET_SDK_VERSION}",
"runtimeOS": "HarmonyOS",
"buildOption": {
"strictMode": {
"caseSensitiveCheck": true,
"useNormalizedOHMUrl": true
}
}
}
],
"buildModeSet": [
{ "name": "debug" },
{ "name": "release" }
]
},
"modules": [
{
"name": "entry",
"srcPath": "./entry",
"targets": [{ "name": "default", "applyToProducts": ["default"] }]
},
{
"name": "nativelib",
"srcPath": "./nativelib",
"targets": [{ "name": "default", "applyToProducts": ["default"] }]
}
]
}
PROFILE_EOF
# ── 依赖安装 ──
- name: Cache ohpm packages
uses: actions/cache@v4
with:
path: |
oh_modules
entry/oh_modules
nativelib/oh_modules
~/.ohpm
key: ohpm-${{ hashFiles('**/oh-package.json5') }}
restore-keys: ohpm-
- name: Setup hvigor
run: |
set -euo pipefail
CMDTOOLS_HVIGOR="$HOME/cmdline-tools/hvigor"
echo "@ohos:registry=https://repo.huaweicloud.com/repository/npm/" > ~/.npmrc
mkdir -p "$CMDTOOLS_HVIGOR/node_modules/@ohos"
ln -sf "$CMDTOOLS_HVIGOR/hvigor" "$CMDTOOLS_HVIGOR/node_modules/@ohos/hvigor"
ln -sf "$CMDTOOLS_HVIGOR/hvigor-ohos-plugin" "$CMDTOOLS_HVIGOR/node_modules/@ohos/hvigor-ohos-plugin"
mkdir -p "$CMDTOOLS_HVIGOR/hvigor/node_modules/@ohos"
ln -sf "$CMDTOOLS_HVIGOR/hvigor" "$CMDTOOLS_HVIGOR/hvigor/node_modules/@ohos/hvigor"
mkdir -p "$CMDTOOLS_HVIGOR/hvigor-ohos-plugin/node_modules/@ohos"
ln -sf "$CMDTOOLS_HVIGOR/hvigor" "$CMDTOOLS_HVIGOR/hvigor-ohos-plugin/node_modules/@ohos/hvigor"
for dir in . hvigor entry nativelib; do
mkdir -p "$dir/node_modules/@ohos"
ln -sf "$CMDTOOLS_HVIGOR/hvigor" "$dir/node_modules/@ohos/hvigor"
ln -sf "$CMDTOOLS_HVIGOR/hvigor-ohos-plugin" "$dir/node_modules/@ohos/hvigor-ohos-plugin"
done
- name: Install ohpm dependencies
run: |
ohpm config set registry https://ohpm.openharmony.cn/ohpm/
ohpm config set strict_ssl false
ohpm install --all
# ── SDK 补丁 ──
- name: Patch SDK
run: |
chmod +x ci/patch-sdk.sh
ci/patch-sdk.sh ~/ohos-sdk
# ── 构建 ──
- name: Build Native HAR
run: |
set -o pipefail
BUILD_MODE="${{ steps.build-mode.outputs.mode }}"
export NODE_HOME="$(dirname "$(dirname "$(which node)")")"
export JAVA_HOME="${JAVA_HOME_17_X64}"
export LD_LIBRARY_PATH="${HOME}/ohos-sdk/toolchains/lib:${HOME}/ohos-sdk/previewer/common/bin:${LD_LIBRARY_PATH:-}"
node hvigorw.js assembleHar \
--mode module \
-p module=nativelib@default \
-p product=default \
-p buildMode="${BUILD_MODE}" \
--no-daemon \
--stacktrace \
2>&1 | tee build-har.log
- name: Build App
run: |
set -o pipefail
BUILD_MODE="${{ steps.build-mode.outputs.mode }}"
export NODE_HOME="$(dirname "$(dirname "$(which node)")")"
export JAVA_HOME="${JAVA_HOME_17_X64}"
export LD_LIBRARY_PATH="${HOME}/ohos-sdk/toolchains/lib:${HOME}/ohos-sdk/previewer/common/bin:${LD_LIBRARY_PATH:-}"
node hvigorw.js assembleApp \
--mode project \
-p product=default \
-p buildMode="${BUILD_MODE}" \
--no-daemon \
--stacktrace \
2>&1 | tee build-hap.log
# ── 清理 & 上传 ──
- name: Cleanup signing files
if: always()
run: rm -rf .signing/
- name: Upload build logs on failure
uses: actions/upload-artifact@v4
if: failure()
with:
name: build-logs-${{ github.run_id }}
path: |
build-har.log
build-hap.log
retention-days: 7
- name: Upload build artifacts
uses: actions/upload-artifact@v4
if: success()
with:
name: harmonyos-${{ steps.build-mode.outputs.mode }}-${{ github.run_id }}
path: |
entry/build/default/outputs/**/*.hap
nativelib/build/default/outputs/**/*.har
if-no-files-found: warn
retention-days: 7
# Signed release artifacts are produced when signing secrets are configured.