-
Notifications
You must be signed in to change notification settings - Fork 3
/
install_ohos_sdk.sh
executable file
·168 lines (152 loc) · 5.87 KB
/
install_ohos_sdk.sh
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
#!/usr/bin/env bash
set -eux
: "${INPUT_VERSION:?INPUT_VERSION needs to be set}"
: "${INPUT_MIRROR:?INPUT_MIRROR needs to be set}"
# https://repo.huaweicloud.com/openharmony/os/4.0-Release/ohos-sdk-windows_linux-public.tar.gz
URL_BASE="https://repo.huaweicloud.com/openharmony/os"
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
OS_FILENAME="ohos-sdk-windows_linux-public.tar.gz"
OS=linux
elif [[ "$OSTYPE" == "darwin"* ]]; then
if [[ $(uname -m) == 'arm64' ]]; then
OS_FILENAME="L2-SDK-MAC-M1-PUBLIC.tar.gz"
else
OS_FILENAME="ohos-sdk-mac-public.tar.gz"
fi
OS=mac
elif [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]]; then
OS_FILENAME="ohos-sdk-windows_linux-public.tar.gz"
OS=windows
else
echo "Unknown OS type. The OHOS SDK is only available for Windows, Linux and macOS."
exit 1
fi
WORK_DIR="${HOME}/setup-ohos-sdk"
mkdir -p "${WORK_DIR}"
cd "${WORK_DIR}"
# Assumption: cwd contains the zipped components.
# Outputs: API_VERSION
function extract_sdk_components() {
if [[ "${INPUT_COMPONENTS}" == "all" ]]; then
COMPONENTS=(*.zip)
else
IFS=";" read -ra COMPONENTS <<< "${INPUT_COMPONENTS}"
resolved_components=()
for COMPONENT in "${COMPONENTS[@]}"
do
resolved_components+=("${COMPONENT}"-*.zip)
done
COMPONENTS=(${resolved_components[@]})
fi
for COMPONENT in "${COMPONENTS[@]}"
do
echo "Extracting component ${COMPONENT}"
echo "::group::Unzipping archive"
#shellcheck disable=SC2144
if [[ -f "${COMPONENT}" ]]; then
unzip "${COMPONENT}"
else
echo "Failed to find component ${COMPONENT}"
ls -la
exit 1
fi
echo "::endgroup::"
# Removing everything after the first dash should give us the component dir
component_dir=${COMPONENT%%-*}
API_VERSION=$(jq -r '.apiVersion' < "${component_dir}/oh-uni-package.json")
if [ "$INPUT_FIXUP_PATH" = "true" ]; then
mkdir -p "${API_VERSION}"
mv "${component_dir}" "${API_VERSION}/"
fi
done
rm ./*.zip
}
function download_and_extract_sdk() {
MIRROR_DOWNLOAD_SUCCESS=false
if [[ "${INPUT_MIRROR}" == "true" || "${INPUT_MIRROR}" == "force" ]]; then
RESOLVED_MIRROR_VERSION_TAG="v${INPUT_VERSION}"
gh release download "${RESOLVED_MIRROR_VERSION_TAG}" --pattern "${OS_FILENAME}*" --repo openharmony-rs/ohos-sdk && MIRROR_DOWNLOAD_SUCCESS=true
if [[ "${MIRROR_DOWNLOAD_SUCCESS}" == "true" ]]; then
# The mirror may have split the archives due to the Github releases size limits.
# First rename the sha256 file, so we don't glob it.
mv "${OS_FILENAME}.sha256" "sha256.${OS_FILENAME}"
# Now get all the .aa .ab etc. output of the split command for our filename
shopt -s nullglob
split_files=("${OS_FILENAME}".*)
if [ ${#split_files[@]} -ne 0 ]; then
cat "${split_files[@]}" > "${OS_FILENAME}"
rm "${split_files[@]}"
fi
# Rename the shafile back again to the original name
mv "sha256.${OS_FILENAME}" "${OS_FILENAME}.sha256"
elif [[ "${INPUT_MIRROR}" == "force" ]]; then
echo "Downloading from mirror failed, and mirror=force. Failing the job."
echo "Note: mirror=force is for internal test purposes, and should not be selected by users."
exit 1
else
echo "Failed to download SDK from mirror. Falling back to downloading from upstream."
fi
fi
if [[ "${MIRROR_DOWNLOAD_SUCCESS}" != "true" ]]; then
DOWNLOAD_URL="${URL_BASE}/${INPUT_VERSION}-Release/${OS_FILENAME}"
echo "Downloading OHOS SDK from ${DOWNLOAD_URL}"
curl --fail -L -O "${DOWNLOAD_URL}"
curl --fail -L -O "${DOWNLOAD_URL}.sha256"
fi
VERSION_MAJOR=${INPUT_VERSION%%.*}
if [[ "${OS}" == "mac" ]]; then
echo "$(cat "${OS_FILENAME}".sha256) ${OS_FILENAME}" | shasum -a 256 --check --status
tar -xf "${OS_FILENAME}" --strip-components=3
else
echo "$(cat "${OS_FILENAME}".sha256) ${OS_FILENAME}" | sha256sum --check --status
if (( VERSION_MAJOR >= 5 )); then
tar -xf "${OS_FILENAME}"
else
tar -xf "${OS_FILENAME}" --strip-components=1
fi
fi
rm "${OS_FILENAME}" "${OS_FILENAME}.sha256"
if [[ "${OS}" == "linux" ]]; then
rm -rf windows
cd linux
elif [[ "${OS}" == "windows" ]]; then
rm -rf linux
cd windows
else
cd darwin
fi
OHOS_BASE_SDK_HOME="$PWD"
extract_sdk_components
}
echo "sdk-path=$PWD" >> "${GITHUB_OUTPUT}"
if [[ "${INPUT_CACHE}" != "true" || "${INPUT_WAS_CACHED}" != "true" ]]; then
download_and_extract_sdk
else
if [[ "${OS}" == "linux" ]]; then
cd linux
elif [[ "${OS}" == "windows" ]]; then
cd windows
else
cd darwin
fi
OHOS_BASE_SDK_HOME="$PWD"
fi
if [ "${INPUT_FIXUP_PATH}" = "true" ]; then
# When we are restoring from cache we don't know the API version, so we glob for now.
# In the future we should do something more robust, like copying `oh-uni-package.json` to the root.
OHOS_NDK_HOME=$(cd "${OHOS_BASE_SDK_HOME}"/* && pwd)
OHOS_SDK_NATIVE="${OHOS_NDK_HOME}"/native
else
OHOS_NDK_HOME="${OHOS_BASE_SDK_HOME}"
OHOS_SDK_NATIVE="${OHOS_BASE_SDK_HOME}/native"
fi
cd "${OHOS_SDK_NATIVE}"
SDK_VERSION="$(jq -r .version < oh-uni-package.json )"
API_VERSION="$(jq -r .apiVersion < oh-uni-package.json )"
echo "OHOS_BASE_SDK_HOME=${OHOS_BASE_SDK_HOME}" >> "$GITHUB_ENV"
echo "ohos-base-sdk-home=${OHOS_BASE_SDK_HOME}" >> "$GITHUB_OUTPUT"
echo "OHOS_NDK_HOME=${OHOS_NDK_HOME}" >> "$GITHUB_ENV"
echo "OHOS_SDK_NATIVE=${OHOS_SDK_NATIVE}" >> "$GITHUB_ENV"
echo "ohos_sdk_native=${OHOS_SDK_NATIVE}" >> "$GITHUB_OUTPUT"
echo "sdk-version=${SDK_VERSION}" >> "$GITHUB_OUTPUT"
echo "api-version=${API_VERSION}" >> "$GITHUB_OUTPUT"