@@ -31,9 +31,36 @@ WORK_DIR="${HOME}/setup-ohos-sdk"
3131mkdir -p " ${WORK_DIR} "
3232cd " ${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+
3459MIRROR_DOWNLOAD_SUCCESS=false
3560if [[ " ${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