@@ -56,109 +56,132 @@ function select_version() {
5656 fi
5757}
5858
59- MIRROR_DOWNLOAD_SUCCESS=false
60- if [[ " ${INPUT_MIRROR} " == " true" || " ${INPUT_MIRROR} " == " force" ]]; then
61- RESOLVED_MIRROR_VERSION_TAG=" v${INPUT_VERSION} "
62- select_version # This will update RESOLVED_MIRROR_VERSION_TAG.
63- gh release download " ${RESOLVED_MIRROR_VERSION_TAG} " --pattern " ${OS_FILENAME} *" --repo openharmony-rs/ohos-sdk && MIRROR_DOWNLOAD_SUCCESS=true
64- if [[ " ${MIRROR_DOWNLOAD_SUCCESS} " == " true" ]]; then
65- # The mirror may have split the archives due to the Github releases size limits.
66- # First rename the sha256 file, so we don't glob it.
67- mv " ${OS_FILENAME} .sha256" " sha256.${OS_FILENAME} "
68- # Now get all the .aa .ab etc. output of the split command for our filename
69- shopt -s nullglob
70- split_files=(" ${OS_FILENAME} " .* )
71- if [ ${# split_files[@]} -ne 0 ]; then
72- cat " ${split_files[@]} " > " ${OS_FILENAME} "
73- rm " ${split_files[@]} "
59+ # Assumption: cwd contains the zipped components.
60+ # Outputs: API_VERSION
61+ function extract_sdk_components() {
62+ if [[ " ${INPUT_COMPONENTS} " == " all" ]]; then
63+ COMPONENTS=(* .zip)
64+ else
65+ IFS=" ;" read -ra COMPONENTS <<< " ${INPUT_COMPONENTS}"
66+ resolved_components=()
67+ for COMPONENT in " ${COMPONENTS[@]} "
68+ do
69+ resolved_components+=(" ${COMPONENT} " -* .zip)
70+ done
71+ COMPONENTS=(${resolved_components[@]} )
7472 fi
75- # Rename the shafile back again to the original name
76- mv " sha256.${OS_FILENAME} " " ${OS_FILENAME} .sha256"
77- elif [[ " ${INPUT_MIRROR} " == " force" ]]; then
78- echo " Downloading from mirror failed, and mirror=force. Failing the job."
79- echo " Note: mirror=force is for internal test purposes, and should not be selected by users."
80- exit 1
81- else
82- echo " Failed to download SDK from mirror. Falling back to downloading from upstream."
83- fi
84- fi
85- if [[ " ${MIRROR_DOWNLOAD_SUCCESS} " != " true" ]]; then
86- DOWNLOAD_URL=" ${URL_BASE} /${INPUT_VERSION} -Release/${OS_FILENAME} "
87- echo " Downloading OHOS SDK from ${DOWNLOAD_URL} "
88- curl --fail -L -O " ${DOWNLOAD_URL} "
89- curl --fail -L -O " ${DOWNLOAD_URL} .sha256"
90- fi
9173
92- VERSION_MAJOR=${INPUT_VERSION%% .* }
74+ for COMPONENT in " ${COMPONENTS[@]} "
75+ do
76+ echo " Extracting component ${COMPONENT} "
77+ echo " ::group::Unzipping archive"
78+ # shellcheck disable=SC2144
79+ if [[ -f " ${COMPONENT} " ]]; then
80+ unzip " ${COMPONENT} "
81+ else
82+ echo " Failed to find component ${COMPONENT} "
83+ ls -la
84+ exit 1
85+ fi
86+ echo " ::endgroup::"
87+ # Removing everything after the first dash should give us the component dir
88+ component_dir=${COMPONENT%% -* }
89+ API_VERSION=$( jq -r ' .apiVersion' < " ${component_dir} /oh-uni-package.json" )
90+ if [ " $INPUT_FIXUP_PATH " = " true" ]; then
91+ mkdir -p " ${API_VERSION} "
92+ mv " ${component_dir} " " ${API_VERSION} /"
93+ fi
94+ done
95+ rm ./* .zip
96+ }
9397
94- if [[ " ${OS} " == " mac" ]]; then
95- echo " $( cat " ${OS_FILENAME} " .sha256) ${OS_FILENAME} " | shasum -a 256 --check --status
96- tar -xf " ${OS_FILENAME} " --strip-components=3
97- else
98- echo " $( cat " ${OS_FILENAME} " .sha256) ${OS_FILENAME} " | sha256sum --check --status
99- if (( VERSION_MAJOR >= 5 )) ; then
100- tar -xf " ${OS_FILENAME} "
98+ function download_and_extract_sdk() {
99+ MIRROR_DOWNLOAD_SUCCESS=false
100+ if [[ " ${INPUT_MIRROR} " == " true" || " ${INPUT_MIRROR} " == " force" ]]; then
101+ RESOLVED_MIRROR_VERSION_TAG=" v${INPUT_VERSION} "
102+ select_version # This will update RESOLVED_MIRROR_VERSION_TAG.
103+ gh release download " ${RESOLVED_MIRROR_VERSION_TAG} " --pattern " ${OS_FILENAME} *" --repo openharmony-rs/ohos-sdk && MIRROR_DOWNLOAD_SUCCESS=true
104+ if [[ " ${MIRROR_DOWNLOAD_SUCCESS} " == " true" ]]; then
105+ # The mirror may have split the archives due to the Github releases size limits.
106+ # First rename the sha256 file, so we don't glob it.
107+ mv " ${OS_FILENAME} .sha256" " sha256.${OS_FILENAME} "
108+ # Now get all the .aa .ab etc. output of the split command for our filename
109+ shopt -s nullglob
110+ split_files=(" ${OS_FILENAME} " .* )
111+ if [ ${# split_files[@]} -ne 0 ]; then
112+ cat " ${split_files[@]} " > " ${OS_FILENAME} "
113+ rm " ${split_files[@]} "
114+ fi
115+ # Rename the shafile back again to the original name
116+ mv " sha256.${OS_FILENAME} " " ${OS_FILENAME} .sha256"
117+ elif [[ " ${INPUT_MIRROR} " == " force" ]]; then
118+ echo " Downloading from mirror failed, and mirror=force. Failing the job."
119+ echo " Note: mirror=force is for internal test purposes, and should not be selected by users."
120+ exit 1
121+ else
122+ echo " Failed to download SDK from mirror. Falling back to downloading from upstream."
123+ fi
124+ fi
125+ if [[ " ${MIRROR_DOWNLOAD_SUCCESS} " != " true" ]]; then
126+ DOWNLOAD_URL=" ${URL_BASE} /${INPUT_VERSION} -Release/${OS_FILENAME} "
127+ echo " Downloading OHOS SDK from ${DOWNLOAD_URL} "
128+ curl --fail -L -O " ${DOWNLOAD_URL} "
129+ curl --fail -L -O " ${DOWNLOAD_URL} .sha256"
130+ fi
131+
132+ VERSION_MAJOR=${INPUT_VERSION%% .* }
133+
134+ if [[ " ${OS} " == " mac" ]]; then
135+ echo " $( cat " ${OS_FILENAME} " .sha256) ${OS_FILENAME} " | shasum -a 256 --check --status
136+ tar -xf " ${OS_FILENAME} " --strip-components=3
101137 else
102- tar -xf " ${OS_FILENAME} " --strip-components=1
138+ echo " $( cat " ${OS_FILENAME} " .sha256) ${OS_FILENAME} " | sha256sum --check --status
139+ if (( VERSION_MAJOR >= 5 )) ; then
140+ tar -xf " ${OS_FILENAME} "
141+ else
142+ tar -xf " ${OS_FILENAME} " --strip-components=1
143+ fi
103144 fi
104- fi
105- rm " ${OS_FILENAME} " " ${OS_FILENAME} .sha256"
106- echo " sdk-path=$PWD " >> " ${GITHUB_OUTPUT} "
145+ rm " ${OS_FILENAME} " " ${OS_FILENAME} .sha256"
107146
108- if [[ " ${OS} " == " linux" ]]; then
109- rm -rf windows
110- cd linux
111- elif [[ " ${OS} " == " windows" ]]; then
112- rm -rf linux
113- cd windows
114- else
115- cd darwin
116- fi
147+ if [[ " ${OS} " == " linux" ]]; then
148+ rm -rf windows
149+ cd linux
150+ elif [[ " ${OS} " == " windows" ]]; then
151+ rm -rf linux
152+ cd windows
153+ else
154+ cd darwin
155+ fi
156+ OHOS_BASE_SDK_HOME=" $PWD "
157+ extract_sdk_components
158+ }
117159
118- OHOS_BASE_SDK_HOME= " $PWD "
160+ echo " sdk-path= $PWD " >> " ${GITHUB_OUTPUT} "
119161
120- if [[ " ${INPUT_COMPONENTS } " = = " all " ]]; then
121- COMPONENTS=( * .zip)
162+ if [[ " ${INPUT_CACHE } " != " true " || " ${INPUT_WAS_CACHED} " ! = " true " ]]; then
163+ download_and_extract_sdk
122164else
123- IFS=" ;" read -ra COMPONENTS <<< " ${INPUT_COMPONENTS}"
124- resolved_components=()
125- for COMPONENT in " ${COMPONENTS[@]} "
126- do
127- resolved_components+=(" ${COMPONENT} " -* .zip)
128- done
129- COMPONENTS=(${resolved_components[@]} )
130- fi
131-
132- for COMPONENT in " ${COMPONENTS[@]} "
133- do
134- echo " Extracting component ${COMPONENT} "
135- echo " ::group::Unzipping archive"
136- # shellcheck disable=SC2144
137- if [[ -f " ${COMPONENT} " ]]; then
138- unzip " ${COMPONENT} "
165+ if [[ " ${OS} " == " linux" ]]; then
166+ cd linux
167+ elif [[ " ${OS} " == " windows" ]]; then
168+ cd windows
139169 else
140- echo " Failed to find component ${COMPONENT} "
141- ls -la
142- exit 1
170+ cd darwin
143171 fi
144- echo " ::endgroup::"
145- # Removing everything after the first dash should give us the component dir
146- component_dir=${COMPONENT%% -* }
147- API_VERSION=$( cat " ${component_dir} /oh-uni-package.json" | jq -r ' .apiVersion' )
148- if [ " $INPUT_FIXUP_PATH " = " true" ]; then
149- mkdir -p " ${API_VERSION} "
150- mv " ${component_dir} " " ${API_VERSION} /"
151- fi
152- done
153- rm ./* .zip
172+ OHOS_BASE_SDK_HOME=" $PWD "
173+ fi
154174
155175if [ " ${INPUT_FIXUP_PATH} " = " true" ]; then
156- OHOS_NDK_HOME=" ${OHOS_BASE_SDK_HOME} /${API_VERSION} "
157- OHOS_SDK_NATIVE=" ${OHOS_BASE_SDK_HOME} /${API_VERSION} /native"
176+ # When we are restoring from cache we don't know the API version, so we glob for now.
177+ # In the future we should do something more robust, like copying `oh-uni-package.json` to the root.
178+ OHOS_NDK_HOME=$( cd " ${OHOS_BASE_SDK_HOME} " /* && pwd)
179+ OHOS_SDK_NATIVE=" ${OHOS_NDK_HOME} " /native
158180else
159181 OHOS_NDK_HOME=" ${OHOS_BASE_SDK_HOME} "
160182 OHOS_SDK_NATIVE=" ${OHOS_BASE_SDK_HOME} /native"
161183fi
184+
162185cd " ${OHOS_SDK_NATIVE} "
163186SDK_VERSION=" $( jq -r .version < oh-uni-package.json ) "
164187API_VERSION=" $( jq -r .apiVersion < oh-uni-package.json ) "
0 commit comments