From 02f489521d9f0d02c9a691129b938b8ca7deea17 Mon Sep 17 00:00:00 2001 From: Jonathan Schwender Date: Mon, 7 Oct 2024 20:11:12 +0200 Subject: [PATCH] Try resolving compatible mirror releases Allows user specified versions such as 5.0 to resolve to e.g. 5.0.x, with x being the latest release in the 5.0.x series. If there is an exact match, then that is preferred. Signed-off-by: Jonathan Schwender --- install_ohos_sdk.sh | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/install_ohos_sdk.sh b/install_ohos_sdk.sh index 00a1868..22ec8e8 100755 --- a/install_ohos_sdk.sh +++ b/install_ohos_sdk.sh @@ -31,9 +31,32 @@ WORK_DIR="${HOME}/setup-ohos-sdk" mkdir -p "${WORK_DIR}" cd "${WORK_DIR}" +# RESOLVED_MIRROR_VERSION_TAG is both in- and output of this function. +# If the user provides a version like `5.0`, we try to resolve the version to something more specific like `5.0.0`, +# since we can't easily have aliasing releases on Github. (e.g. 5.0 pointing to the latest 5.0.x release) +function select_version() { + local base_tag_version="${RESOLVED_MIRROR_VERSION_TAG}" + local available_releases + local latest_compatible_version + available_releases=$(gh release list --repo openharmony-rs/ohos-sdk --json 'tagName') + # If this exact release exists, return and use it. + jq ".[] | select(.tagName == \"${base_tag_version}\")" <<< "${available_releases}" \ + && return 0 + # Otherwise, get the first (== latest) release matching the start of our version tag (e.g. `5.0.3` for input `5.0`) + latest_compatible_version=$(jq "[.[] | select(.tagName | startswith(\"${base_tag_version}.\"))][0].tagName" <<< "${available_releases}") + if [[ -n "${latest_compatible_version}" ]]; then + echo "Resolved version ${base_tag_version} to release ${latest_compatible_version}" + RESOLVED_MIRROR_VERSION_TAG="${latest_compatible_version}" + else + echo "Couldn't find any compatible release on the mirror." + fi +} + 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 + RESOLVED_MIRROR_VERSION_TAG="v${INPUT_VERSION}" + select_version # This will update RESOLVED_MIRROR_VERSION_TAG. + 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.