Skip to content

Commit 6701f5d

Browse files
committed
ci: add harmonyos device smoke script
1 parent e63c2a0 commit 6701f5d

2 files changed

Lines changed: 174 additions & 0 deletions

File tree

‎ohos/README.md‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ The environment must provide:
2727
- `ohpm`
2828
- `hvigor` or `ohos/hvigorw`
2929

30+
The GitHub runner package test only proves that the HAP can be built and
31+
uploaded as an artifact. It does not prove that the app can open, because the
32+
runner does not provide a HarmonyOS/OpenHarmony emulator or device.
33+
3034
Docker is still available as a convenience wrapper when a suitable image exists:
3135

3236
```bash
@@ -51,6 +55,61 @@ It is enough for Rust OHOS native compilation. A full HAP build still requires
5155
DevEco/HarmonyOS SDK image via `OHOS_DOCKER_IMAGE` or run `--local` from a
5256
runner/host where those tools are installed.
5357

58+
## Run on an Emulator or Device
59+
60+
Install DevEco Studio and create a HarmonyOS/OpenHarmony phone emulator from
61+
Device Manager, or connect a compatible device. This project installs `.hap`
62+
packages with `hdc`; Android Emulator is not a valid target.
63+
64+
Make sure the command-line tools are available:
65+
66+
```bash
67+
hdc version
68+
hdc list targets
69+
```
70+
71+
Build the package, then install and start the entry ability:
72+
73+
```bash
74+
script/build-harmonyos.sh --local
75+
script/run-harmonyos-device.sh
76+
```
77+
78+
The run script defaults to the newest HAP under:
79+
80+
```text
81+
ohos/entry/build/default/outputs/default/
82+
```
83+
84+
You can also install a downloaded runner artifact directly:
85+
86+
```bash
87+
script/run-harmonyos-device.sh /path/to/entry-default-unsigned.hap
88+
```
89+
90+
If multiple devices are connected, set the target explicitly:
91+
92+
```bash
93+
HDC_TARGET=127.0.0.1:5555 script/run-harmonyos-device.sh
94+
```
95+
96+
The script starts:
97+
98+
```text
99+
bundle: com.onetcli.app
100+
ability: EntryAbility
101+
```
102+
103+
Override those names only if the app metadata changes:
104+
105+
```bash
106+
OHOS_BUNDLE_NAME=com.onetcli.app OHOS_ABILITY_NAME=EntryAbility script/run-harmonyos-device.sh
107+
```
108+
109+
The expected smoke-test result is that the app opens and shows the GPUI launch
110+
view with the text `OnetCli`, `HarmonyOS native package`, and
111+
`GPUI runtime started`.
112+
54113
## Native Entry
55114

56115
`native/` is an isolated Rust `cdylib` crate. It follows the

‎script/run-harmonyos-device.sh‎

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5+
DEFAULT_HAP_GLOB="${ROOT_DIR}/ohos/entry/build/default/outputs/default/"*.hap
6+
BUNDLE_NAME="${OHOS_BUNDLE_NAME:-com.onetcli.app}"
7+
ABILITY_NAME="${OHOS_ABILITY_NAME:-EntryAbility}"
8+
HDC_TARGET="${HDC_TARGET:-}"
9+
10+
usage() {
11+
cat <<'USAGE'
12+
Usage: script/run-harmonyos-device.sh [path/to/app.hap]
13+
14+
Installs a built HarmonyOS/OpenHarmony HAP on the connected hdc target and
15+
starts the OnetCli entry ability.
16+
17+
Environment:
18+
HDC_TARGET Optional hdc target id. Defaults to the first listed target.
19+
OHOS_BUNDLE_NAME Bundle name to start. Default: com.onetcli.app
20+
OHOS_ABILITY_NAME Ability name to start. Default: EntryAbility
21+
22+
Build first when no explicit HAP path is supplied:
23+
24+
script/build-harmonyos.sh --local
25+
script/run-harmonyos-device.sh
26+
USAGE
27+
}
28+
29+
require_tool() {
30+
local tool="$1"
31+
if ! command -v "${tool}" >/dev/null 2>&1; then
32+
echo "missing required tool: ${tool}" >&2
33+
echo "Install DevEco Studio and add its command-line tools to PATH." >&2
34+
exit 127
35+
fi
36+
}
37+
38+
resolve_hap() {
39+
if [[ "${1:-}" == "--help" || "${1:-}" == "-h" ]]; then
40+
usage
41+
exit 0
42+
fi
43+
if [[ -n "${1:-}" ]]; then
44+
if [[ ! -f "$1" ]]; then
45+
echo "HAP file does not exist: $1" >&2
46+
exit 2
47+
fi
48+
echo "$1"
49+
return
50+
fi
51+
52+
local matches=()
53+
shopt -s nullglob
54+
matches=(${DEFAULT_HAP_GLOB})
55+
shopt -u nullglob
56+
if [[ "${#matches[@]}" -eq 0 ]]; then
57+
echo "no HAP found under ohos/entry/build/default/outputs/default" >&2
58+
echo "Run script/build-harmonyos.sh --local first, or pass a HAP path." >&2
59+
exit 2
60+
fi
61+
printf '%s\n' "${matches[@]}" | sort | tail -1
62+
}
63+
64+
select_target() {
65+
if [[ -n "${HDC_TARGET}" ]]; then
66+
echo "${HDC_TARGET}"
67+
return
68+
fi
69+
70+
local target
71+
target="$(
72+
hdc list targets \
73+
| sed '/^[[:space:]]*$/d;/^\[Empty\]$/d;/^List of devices/d' \
74+
| head -1
75+
)"
76+
if [[ -z "${target}" ]]; then
77+
echo "no hdc target found" >&2
78+
echo "Start a DevEco Studio emulator or connect a HarmonyOS/OpenHarmony device." >&2
79+
exit 2
80+
fi
81+
echo "${target%%[[:space:]]*}"
82+
}
83+
84+
hdc_target_cmd() {
85+
local target="$1"
86+
shift
87+
if [[ -n "${target}" ]]; then
88+
hdc -t "${target}" "$@"
89+
else
90+
hdc "$@"
91+
fi
92+
}
93+
94+
main() {
95+
if [[ "${1:-}" == "--help" || "${1:-}" == "-h" ]]; then
96+
usage
97+
exit 0
98+
fi
99+
100+
require_tool hdc
101+
102+
local hap_path
103+
local target
104+
hap_path="$(resolve_hap "${1:-}")"
105+
target="$(select_target)"
106+
107+
echo "Using hdc target: ${target}"
108+
echo "Installing HAP: ${hap_path}"
109+
hdc_target_cmd "${target}" install -r "${hap_path}"
110+
111+
echo "Starting ability: ${BUNDLE_NAME}/${ABILITY_NAME}"
112+
hdc_target_cmd "${target}" shell aa start -b "${BUNDLE_NAME}" -a "${ABILITY_NAME}"
113+
}
114+
115+
main "$@"

0 commit comments

Comments
 (0)