Skip to content

Commit

Permalink
Add default option to download from GitHub releases mirror
Browse files Browse the repository at this point in the history
The download speed from the official SDK host varies quite a lot, and can take
20+ minutes in some cases.
Using github releases should make the overall
download speed much more consistent.

Signed-off-by: Jonathan Schwender <[email protected]>
  • Loading branch information
jschwe committed Oct 6, 2024
1 parent 659227c commit 54feba6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ inputs:
description: "Whether to fixup the output paths so that the components appear under api level directory"
required: false
default: false
mirror:
description: "Prefer downloading from Github Releases SDK mirror"
required: false
default: 'true'
outputs:
sdk-path:
description: "Root directory of the OpenHarmony SDK installation"
Expand Down Expand Up @@ -60,6 +64,7 @@ runs:
INPUT_VERSION: "${{ inputs.version }}"
INPUT_COMPONENTS: "${{ inputs.components }}"
INPUT_FIXUP_PATH: ${{ inputs.fixup-path }}
INPUT_MIRROR: "${{ inputs.mirror }}"
- name: Set Outputs
id: set_outputs
shell: bash
Expand Down
47 changes: 39 additions & 8 deletions install_ohos_sdk.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env bash

set -eu
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

Expand All @@ -23,20 +24,50 @@ elif [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" ==
OS=windows
else
echo "Unknown OS type. The OHOS SDK is only available for Windows, Linux and macOS."
exit 1
fi

DOWNLOAD_URL="${URL_BASE}/${INPUT_VERSION}-Release/${OS_FILENAME}"
cd "${HOME}"

MIRROR_DOWNLOAD_SUCCESS=false
if [[ "${INPUT_MIRROR}" == "true" || "${INPUT_MIRROR}" == "force" ]]; then
gh release download "v${INPUT_VERSION}" --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

echo "Downloading OHOS SDK from ${DOWNLOAD_URL}"
echo "$(cat "${OS_FILENAME}".sha256) ${OS_FILENAME}" | sha256sum --check --status

curl --fail -L -o "${HOME}/openharmony-sdk.tar.gz" "${DOWNLOAD_URL}"
cd "${HOME}"
if [[ "${OS}" == "mac" ]]; then
tar -xf openharmony-sdk.tar.gz --strip-components=2
tar -xf "${OS_FILENAME}" --strip-components=2
else
tar -xf openharmony-sdk.tar.gz
tar -xf "${OS_FILENAME}"
fi
rm openharmony-sdk.tar.gz
rm "${OS_FILENAME}" "${OS_FILENAME}.sha256"
cd ohos-sdk

if [[ "${OS}" == "linux" ]]; then
Expand Down

0 comments on commit 54feba6

Please sign in to comment.