From 15a618dc496c0613799b38ba1a17c2272c62e0ed Mon Sep 17 00:00:00 2001 From: Jonathan Schwender Date: Sun, 6 Oct 2024 13:09:09 +0200 Subject: [PATCH] Add default option to download from GitHub releases mirror 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. Additionally also verify the sha256. Signed-off-by: Jonathan Schwender --- action.yml | 6 ++++++ install_ohos_sdk.sh | 47 +++++++++++++++++++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/action.yml b/action.yml index 0fec160..785c3a4 100644 --- a/action.yml +++ b/action.yml @@ -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" @@ -60,6 +64,8 @@ runs: INPUT_VERSION: "${{ inputs.version }}" INPUT_COMPONENTS: "${{ inputs.components }}" INPUT_FIXUP_PATH: ${{ inputs.fixup-path }} + INPUT_MIRROR: "${{ inputs.mirror }}" + GH_TOKEN: "${{ github.token }}" - name: Set Outputs id: set_outputs shell: bash diff --git a/install_ohos_sdk.sh b/install_ohos_sdk.sh index a0d922c..db837cf 100755 --- a/install_ohos_sdk.sh +++ b/install_ohos_sdk.sh @@ -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 @@ -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}" -echo "Downloading OHOS SDK from ${DOWNLOAD_URL}" +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 -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 + echo "$(cat "${OS_FILENAME}".sha256) ${OS_FILENAME}" | shasum -a 256 --check --status + tar -xf "${OS_FILENAME}" --strip-components=2 else - tar -xf openharmony-sdk.tar.gz + echo "$(cat "${OS_FILENAME}".sha256) ${OS_FILENAME}" | sha256sum --check --status + tar -xf "${OS_FILENAME}" fi -rm openharmony-sdk.tar.gz +rm "${OS_FILENAME}" "${OS_FILENAME}.sha256" cd ohos-sdk if [[ "${OS}" == "linux" ]]; then