Skip to content

Commit 0ee4782

Browse files
committed
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 <[email protected]>
1 parent 8f99e9a commit 0ee4782

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

install_ohos_sdk.sh

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,36 @@ WORK_DIR="${HOME}/setup-ohos-sdk"
3131
mkdir -p "${WORK_DIR}"
3232
cd "${WORK_DIR}"
3333

34+
# RESOLVED_MIRROR_VERSION_TAG is both in- and output of this function.
35+
# If the user provides a version like `5.0`, we try to resolve the version to something more specific like `5.0.0`,
36+
# since we can't easily have aliasing releases on Github. (e.g. 5.0 pointing to the latest 5.0.x release)
37+
function select_version() {
38+
local base_tag_version="${RESOLVED_MIRROR_VERSION_TAG}"
39+
local available_releases
40+
local exact_version_res
41+
local latest_compatible_version
42+
available_releases=$(gh release list --repo openharmony-rs/ohos-sdk --json 'tagName')
43+
# Note: jq doesn't seem to return an error if select doesn't find anything
44+
exact_version_res=$(jq ".[] | select(.tagName == \"${base_tag_version}\")" <<< "${available_releases}")
45+
if [[ -n "${exact_version_res}" ]]; then
46+
# If we found an exactly matching release, then we don't need to do anything.
47+
return 0
48+
fi
49+
# Otherwise, get the first (== latest) release matching the start of our version tag (e.g. `5.0.3` for input `5.0`)
50+
latest_compatible_version=$(jq "[.[] | select(.tagName | startswith(\"${base_tag_version}.\"))][0].tagName" <<< "${available_releases}" | tr -d '"')
51+
if [[ -n "${latest_compatible_version}" ]]; then
52+
echo "Resolved version ${base_tag_version} to release ${latest_compatible_version}"
53+
RESOLVED_MIRROR_VERSION_TAG="${latest_compatible_version}"
54+
else
55+
echo "Couldn't find any compatible release on the mirror."
56+
fi
57+
}
58+
3459
MIRROR_DOWNLOAD_SUCCESS=false
3560
if [[ "${INPUT_MIRROR}" == "true" || "${INPUT_MIRROR}" == "force" ]]; then
36-
gh release download "v${INPUT_VERSION}" --pattern "${OS_FILENAME}*" --repo openharmony-rs/ohos-sdk && MIRROR_DOWNLOAD_SUCCESS=true
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
3764
if [[ "${MIRROR_DOWNLOAD_SUCCESS}" == "true" ]]; then
3865
# The mirror may have split the archives due to the Github releases size limits.
3966
# First rename the sha256 file, so we don't glob it.

0 commit comments

Comments
 (0)