Skip to content

Commit

Permalink
Try resolving compatible mirror releases
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
jschwe committed Oct 7, 2024
1 parent 8f99e9a commit 02f4895
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion install_ohos_sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 02f4895

Please sign in to comment.