Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .coderabbit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# CodeRabbit AI 代码审查配置
# 文档: https://docs.coderabbit.ai/reference/configuration

language: "zh-CN"
tone_instructions: "使用简洁的中文进行代码审查,关注实际问题而非风格偏好。"
early_access: true

reviews:
profile: "chill"
high_level_summary: true
poem: false
sequence_diagrams: false
collapse_walkthrough: true
changed_files_summary: true
path_filters:
- "!build/**"
- "!oh_modules/**"
- "!entry/oh_modules/**"
- "!entry/build/**"
- "!nativelib/build/**"
- "!hvigor/**"
- "!oh-package-lock.json5"
- "!entry/oh-package-lock.json5"
- "!store-assets/**"
- "!nativelib/src/main/cpp/moonlight-common-c/**"
- "!nativelib/src/main/cpp/ohos-openssl/**"
path_instructions:
- path: "entry/src/main/ets/**"
instructions: |
这是 HarmonyOS ArkTS 前端代码。使用 ArkUI 声明式 UI 框架,@Component/@State/@Prop/@Link 等装饰器。
关注线程安全(UI 线程 vs Worker)、内存泄漏(定时器/事件监听未清理)、空指针安全。
- path: "nativelib/src/main/cpp/**"
instructions: |
C/C++ 原生层代码,通过 N-API 与 ArkTS 交互。关注内存管理、线程安全、JNI/N-API 生命周期。
auto_review:
enabled: true
drafts: false

chat:
auto_reply: true
75 changes: 4 additions & 71 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ jobs:
ci/patch-sdk.sh ~/ohos-sdk

# ── 构建 ──
- name: Build HAP
- name: Build Native
run: |
set -o pipefail
BUILD_MODE="${{ steps.build-mode.outputs.mode }}"
Expand All @@ -310,94 +310,27 @@ jobs:
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 assembleHap \
node hvigorw.js assembleHar \
--mode module \
-p module=nativelib@default \
-p product=default \
-p buildMode="${BUILD_MODE}" \
--no-daemon \
--stacktrace \
2>&1 | tee build-hap.log

find . -name "*.hap" -type f -exec sh -c 'echo " $(du -h "$1" | cut -f1) $1"' _ {} \;

- name: Build APP (signed)
if: steps.signing.outputs.available == 'true'
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}"

node hvigorw.js assembleApp \
--mode module \
-p product=default \
-p buildMode="${BUILD_MODE}" \
--no-daemon \
2>&1 | tee build-app.log

find . -name "*.app" -type f -exec sh -c 'echo " $(du -h "$1" | cut -f1) $1"' _ {} \;

# ── 清理 & 上传 ──
- name: Cleanup signing files
if: always()
run: rm -rf .signing/

- name: Upload HAP artifact
uses: actions/upload-artifact@v4
if: always()
with:
name: moonlight-hap-${{ steps.version.outputs.version }}-${{ steps.build-mode.outputs.mode }}
path: entry/build/default/outputs/**/*.hap
if-no-files-found: warn
retention-days: 30

- name: Upload APP artifact
uses: actions/upload-artifact@v4
if: steps.signing.outputs.available == 'true'
with:
name: moonlight-app-${{ steps.version.outputs.version }}-${{ steps.build-mode.outputs.mode }}
path: |
entry/build/default/outputs/**/*.app
build/default/outputs/**/*.app
if-no-files-found: warn
retention-days: 30

- name: Upload build logs on failure
uses: actions/upload-artifact@v4
if: failure()
with:
name: build-logs-${{ github.run_id }}
path: |
build-hap.log
build-app.log
retention-days: 7

# ── Release ──
release:
name: Create Release
needs: build
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
permissions:
contents: write

steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: moonlight-*
path: ./artifacts
merge-multiple: true

- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
files: |
./artifacts/**/*.hap
./artifacts/**/*.app
draft: false
prerelease: ${{ contains(github.ref, 'beta') || contains(github.ref, 'alpha') || contains(github.ref, 'rc') }}
generate_release_notes: true
fail_on_unmatched_files: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Release 由本地手动构建签名后上传
23 changes: 23 additions & 0 deletions ci/patch-sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,27 @@ if [ -n "$DISPLAY_DTS" ] && ! grep -q "getBrightnessInfo" "$DISPLAY_DTS"; then
echo " Patched display module"
fi

# ─── @kit.ScanKit ───
[ ! -f "$KIT_CONFIGS/@kit.ScanKit.json" ] && \
cp "$STUBS_DIR/kit.ScanKit.json" "$KIT_CONFIGS/@kit.ScanKit.json"
cp "$STUBS_DIR/kit.ScanKit.d.ts" "$ETS_API/@kit.ScanKit.d.ts"
cp "$STUBS_DIR/ohos.scan.scanCore.d.ts" "$ETS_API/@ohos.scan.scanCore.d.ts"
cp "$STUBS_DIR/ohos.scan.scanBarcode.d.ts" "$ETS_API/@ohos.scan.scanBarcode.d.ts"
echo " Applied ScanKit stubs"

# ─── @kit.ShareKit ───
[ ! -f "$KIT_CONFIGS/@kit.ShareKit.json" ] && \
cp "$STUBS_DIR/kit.ShareKit.json" "$KIT_CONFIGS/@kit.ShareKit.json"
cp "$STUBS_DIR/kit.ShareKit.d.ts" "$ETS_API/@kit.ShareKit.d.ts"
cp "$STUBS_DIR/ohos.share.systemShare.d.ts" "$ETS_API/@ohos.share.systemShare.d.ts"
echo " Applied ShareKit stubs"

# ─── DevKeySecret (CI-only placeholder) ───
DEV_KEY_SECRET="entry/src/main/ets/config/DevKeySecret.ets"
if [ ! -f "$DEV_KEY_SECRET" ]; then
mkdir -p "$(dirname "$DEV_KEY_SECRET")"
cp "${DEV_KEY_SECRET}.example" "$DEV_KEY_SECRET"
echo " Created DevKeySecret from example"
Comment on lines +135 to +139
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

DevKeySecret 使用相对路径会导致 CI 调用目录变化时失败

Line 132 依赖当前工作目录是仓库根目录;如果从其他目录调用脚本,这里会找不到目标路径。并且 Line 135 在 .example 缺失时会直接中断整个脚本(set -e)。建议改成基于脚本位置解析仓库根目录,并显式校验模板文件存在。

🔧 建议修复
 # ─── DevKeySecret (CI-only placeholder) ───
-DEV_KEY_SECRET="entry/src/main/ets/config/DevKeySecret.ets"
-if [ ! -f "$DEV_KEY_SECRET" ]; then
-  mkdir -p "$(dirname "$DEV_KEY_SECRET")"
-  cp "${DEV_KEY_SECRET}.example" "$DEV_KEY_SECRET"
+REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
+DEV_KEY_SECRET="$REPO_ROOT/entry/src/main/ets/config/DevKeySecret.ets"
+DEV_KEY_SECRET_EXAMPLE="${DEV_KEY_SECRET}.example"
+if [ ! -f "$DEV_KEY_SECRET" ]; then
+  if [ ! -f "$DEV_KEY_SECRET_EXAMPLE" ]; then
+    echo "❌ Missing template: $DEV_KEY_SECRET_EXAMPLE" >&2
+    exit 1
+  fi
+  mkdir -p "$(dirname "$DEV_KEY_SECRET")"
+  cp "$DEV_KEY_SECRET_EXAMPLE" "$DEV_KEY_SECRET"
   echo "  Created DevKeySecret from example"
 fi
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ci/patch-sdk.sh` around lines 132 - 136, The DEV_KEY_SECRET path is
constructed relative to the current working directory which breaks when the
script is invoked from elsewhere; update the script to compute repository root
from the script location (e.g., use a SCRIPT_DIR or REPO_ROOT derived from
$(dirname "$0")/..), then set DEV_KEY_SECRET to that absolute path (use the
unique variable name DEV_KEY_SECRET). Before copying, explicitly check that the
template file "${DEV_KEY_SECRET}.example" exists and fail with a clear error
message if it does not (instead of letting set -e cause an opaque crash); still
create parent directories with mkdir -p "$(dirname "$DEV_KEY_SECRET")" and only
then cp the example into DEV_KEY_SECRET.

fi

echo "✅ SDK patches applied"
22 changes: 22 additions & 0 deletions ci/sdk-stubs/kit.ScanKit.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
declare module '@kit.ScanKit' {
namespace scanCore {
enum ScanType {
QR_CODE = 0,
BARCODE_TYPE_EAN_13 = 1,
BARCODE_TYPE_EAN_8 = 2,
BARCODE_TYPE_CODE_128 = 3,
}
}
namespace scanBarcode {
interface ScanOptions {
scanTypes?: scanCore.ScanType[];
enableMultiMode?: boolean;
enableAlbum?: boolean;
}
interface ScanResult {
originalValue?: string;
scanType?: number;
}
function startScanForResult(context: object, options?: ScanOptions): Promise<ScanResult>;
}
}
12 changes: 12 additions & 0 deletions ci/sdk-stubs/kit.ScanKit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"symbols": {
"scanCore": {
"source": "@ohos.scan.scanCore.d.ts",
"bindings": "default"
},
"scanBarcode": {
"source": "@ohos.scan.scanBarcode.d.ts",
"bindings": "default"
}
}
}
33 changes: 33 additions & 0 deletions ci/sdk-stubs/kit.ShareKit.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
declare module '@kit.ShareKit' {
namespace systemShare {
enum SelectionMode {
SINGLE = 0,
BATCH = 1,
}
enum SharePreviewMode {
DEFAULT = 0,
DETAIL = 1,
}
interface SharedDataRecord {
utd: string;
content?: string;
uri?: string;
data?: ArrayBuffer;
title?: string;
description?: string;
thumbnail?: object;
}
class SharedData {
constructor(record: SharedDataRecord);
addRecord(record: SharedDataRecord): void;
}
interface ShareControllerOptions {
selectionMode?: SelectionMode;
previewMode?: SharePreviewMode;
}
class ShareController {
constructor(data: SharedData);
show(context: object, options?: ShareControllerOptions): Promise<void>;
}
}
}
8 changes: 8 additions & 0 deletions ci/sdk-stubs/kit.ShareKit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"symbols": {
"systemShare": {
"source": "@ohos.share.systemShare.d.ts",
"bindings": "default"
}
}
}
13 changes: 13 additions & 0 deletions ci/sdk-stubs/ohos.scan.scanBarcode.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
declare namespace scanBarcode {
interface ScanOptions {
scanTypes?: number[];
enableMultiMode?: boolean;
enableAlbum?: boolean;
}
interface ScanResult {
originalValue?: string;
scanType?: number;
}
function startScanForResult(context: object, options?: ScanOptions): Promise<ScanResult>;
}
export default scanBarcode;
9 changes: 9 additions & 0 deletions ci/sdk-stubs/ohos.scan.scanCore.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
declare namespace scanCore {
enum ScanType {
QR_CODE = 0,
BARCODE_TYPE_EAN_13 = 1,
BARCODE_TYPE_EAN_8 = 2,
BARCODE_TYPE_CODE_128 = 3,
}
}
export default scanCore;
32 changes: 32 additions & 0 deletions ci/sdk-stubs/ohos.share.systemShare.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
declare namespace systemShare {
enum SelectionMode {
SINGLE = 0,
BATCH = 1,
}
enum SharePreviewMode {
DEFAULT = 0,
DETAIL = 1,
}
interface SharedDataRecord {
utd: string;
content?: string;
uri?: string;
data?: ArrayBuffer;
title?: string;
description?: string;
thumbnail?: object;
}
class SharedData {
constructor(record: SharedDataRecord);
addRecord(record: SharedDataRecord): void;
}
interface ShareControllerOptions {
selectionMode?: SelectionMode;
previewMode?: SharePreviewMode;
}
class ShareController {
constructor(data: SharedData);
show(context: object, options?: ShareControllerOptions): Promise<void>;
}
}
export default systemShare;
Loading
Loading