Skip to content

Commit 6e2670e

Browse files
committed
Enhanced software release retrieval
Updated: - Web::upgradeRelease - Web::getReleases - Github::installRelease Changes: - support for gh - allows to override version place holder using env variable VERSION_PLACEHOLDER
1 parent f27f9f9 commit 6e2670e

File tree

14 files changed

+377
-334
lines changed

14 files changed

+377
-334
lines changed

bin/doc

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,7 @@ Github::upgradeRelease() {
677677
}
678678
FILTER_LAST_VERSION_CALLBACK=${FILTER_LAST_VERSION_CALLBACK:-extractVersion} \
679679
SOFT_VERSION_CALLBACK="${softVersionCallback}" \
680+
INSTALL_CALLBACK="${installCallback}" \
680681
Web::upgradeRelease \
681682
"${targetFile}" \
682683
"${releasesUrl}" \
@@ -1544,12 +1545,27 @@ Version::parse() {
15441545
Web::getReleases() {
15451546
local releaseListUrl="$1"
15461547
# Get latest release from GitHub api
1547-
Retry::parameterized "${RETRY_MAX_RETRY:-5}" "${RETRY_DELAY_BETWEEN_RETRIES:-15}" "Retrieving release versions list ..." curl \
1548-
-L \
1549-
--connect-timeout "${CURL_CONNECT_TIMEOUT:-5}" \
1550-
--fail \
1551-
--silent \
1552-
"${releaseListUrl}"
1548+
if command -v gh &>/dev/null && [[ -n "${GH_TOKEN}" ]]; then
1549+
Log::displayDebug "Using gh to retrieve release versions list"
1550+
Retry::parameterized "${RETRY_MAX_RETRY:-5}" \
1551+
"${RETRY_DELAY_BETWEEN_RETRIES:-15}" \
1552+
"Retrieving release versions list ..." \
1553+
gh api "${releaseListUrl#https://github.com}"
1554+
else
1555+
if command -v gh &>/dev/null && [[ "${GH_WARNING_DISPLAYED:-0}" = "0" ]]; then
1556+
Log::displayWarning "GH_TOKEN is not set, cannot use gh, using curl to retrieve release versions list"
1557+
GH_WARNING_DISPLAYED=1
1558+
fi
1559+
Retry::parameterized "${RETRY_MAX_RETRY:-5}" \
1560+
"${RETRY_DELAY_BETWEEN_RETRIES:-15}" \
1561+
"Retrieving release versions list ..." \
1562+
curl \
1563+
-L \
1564+
--connect-timeout "${CURL_CONNECT_TIMEOUT:-5}" \
1565+
--fail \
1566+
--silent \
1567+
"${releaseListUrl}"
1568+
fi
15531569
}
15541570

15551571

@@ -1567,6 +1583,7 @@ Web::getReleases() {
15671583
# @env PARSE_VERSION_CALLBACK a callback to parse the version of the existing command
15681584
# @env INSTALL_CALLBACK a callback to install the software downloaded
15691585
# @env CURL_CONNECT_TIMEOUT number of seconds before giving up host connection
1586+
# @env VERSION_PLACEHOLDER a placeholder to replace in downloadReleaseUrl (default: @latestVersion@)
15701587
Web::upgradeRelease() {
15711588
local targetFile="$1"
15721589
local releasesUrl="$2"
@@ -1577,25 +1594,28 @@ Web::upgradeRelease() {
15771594
local filterLastVersionCallback="${FILTER_LAST_VERSION_CALLBACK:-Version::parse}"
15781595
local softVersionCallback="${SOFT_VERSION_CALLBACK:-Version::getCommandVersionFromPlainText}"
15791596
local installCallback="${INSTALL_CALLBACK:-}"
1580-
local latestVersion
1581-
latestVersion="$(Web::getReleases "${releasesUrl}" | ${filterLastVersionCallback})" || {
1582-
Log::displayError "latest version not found on ${releasesUrl}"
1583-
return 1
1584-
}
1585-
Log::displayInfo "Latest version found is ${latestVersion}"
15861597

15871598
local currentVersion="not existing"
15881599
if [[ -f "${targetFile}" ]]; then
15891600
currentVersion="$(${softVersionCallback} "${targetFile}" "${softVersionArg}" 2>&1 || true)"
15901601
fi
15911602
if [[ -z "${exactVersion}" ]]; then
1603+
local latestVersion
1604+
latestVersion="$(Web::getReleases "${releasesUrl}" | ${filterLastVersionCallback})" || {
1605+
Log::displayError "latest version not found on ${releasesUrl}"
1606+
return 1
1607+
}
1608+
Log::displayInfo "Latest version found is ${latestVersion}"
1609+
15921610
exactVersion="${latestVersion}"
15931611
fi
1594-
local url="${downloadReleaseUrl//@latestVersion@/${exactVersion}}"
1612+
local url="${downloadReleaseUrl//${VERSION_PLACEHOLDER:-@latestVersion@}/${exactVersion}}"
15951613
if [[ -n "${exactVersion}" ]] && ! Github::isReleaseVersionExist "${url}"; then
15961614
Log::displayError "${targetFile} version ${exactVersion} doesn't exist on github"
15971615
return 2
15981616
fi
1617+
Log::displayDebug "currentVersion: '${currentVersion}'"
1618+
Log::displayDebug "exactVersion: '${exactVersion}'"
15991619
if [[ "${currentVersion}" = "${exactVersion}" ]]; then
16001620
Log::displayInfo "${targetFile} version ${exactVersion} already installed"
16011621
else

bin/dockerLint

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ Github::upgradeRelease() {
488488
}
489489
FILTER_LAST_VERSION_CALLBACK=${FILTER_LAST_VERSION_CALLBACK:-extractVersion} \
490490
SOFT_VERSION_CALLBACK="${softVersionCallback}" \
491+
INSTALL_CALLBACK="${installCallback}" \
491492
Web::upgradeRelease \
492493
"${targetFile}" \
493494
"${releasesUrl}" \
@@ -612,6 +613,19 @@ Log::displaySuccess() {
612613
}
613614

614615

616+
# @description Display message using warning color (yellow)
617+
# @arg $1 message:String the message to display
618+
# @env DISPLAY_DURATION int (default 0) if 1 display elapsed time information between 2 info logs
619+
# @env LOG_CONTEXT String allows to contextualize the log
620+
Log::displayWarning() {
621+
if ((BASH_FRAMEWORK_DISPLAY_LEVEL >= __LEVEL_WARNING)); then
622+
Log::computeDuration
623+
echo -e "${__WARNING_COLOR}WARN - ${LOG_CONTEXT:-}${LOG_LAST_DURATION_STR:-}${1}${__RESET_COLOR}" >&2
624+
fi
625+
Log::logWarning "$1"
626+
}
627+
628+
615629
# @description Display message using error color (red) and exit immediately with error status 1
616630
# @arg $1 message:String the message to display
617631
# @env DISPLAY_DURATION int (default 0) if 1 display elapsed time information between 2 info logs
@@ -704,6 +718,15 @@ Log::logSuccess() {
704718
}
705719

706720

721+
# @description log message to file
722+
# @arg $1 message:String the message to display
723+
Log::logWarning() {
724+
if ((BASH_FRAMEWORK_LOG_LEVEL >= __LEVEL_WARNING)); then
725+
Log::logMessage "${2:-WARNING}" "$1"
726+
fi
727+
}
728+
729+
707730
# @description activate or not Log::display* and Log::log* functions
708731
# based on BASH_FRAMEWORK_DISPLAY_LEVEL and BASH_FRAMEWORK_LOG_LEVEL
709732
# environment variables loaded by Env::requireLoad
@@ -1074,12 +1097,27 @@ Version::parse() {
10741097
Web::getReleases() {
10751098
local releaseListUrl="$1"
10761099
# Get latest release from GitHub api
1077-
Retry::parameterized "${RETRY_MAX_RETRY:-5}" "${RETRY_DELAY_BETWEEN_RETRIES:-15}" "Retrieving release versions list ..." curl \
1078-
-L \
1079-
--connect-timeout "${CURL_CONNECT_TIMEOUT:-5}" \
1080-
--fail \
1081-
--silent \
1082-
"${releaseListUrl}"
1100+
if command -v gh &>/dev/null && [[ -n "${GH_TOKEN}" ]]; then
1101+
Log::displayDebug "Using gh to retrieve release versions list"
1102+
Retry::parameterized "${RETRY_MAX_RETRY:-5}" \
1103+
"${RETRY_DELAY_BETWEEN_RETRIES:-15}" \
1104+
"Retrieving release versions list ..." \
1105+
gh api "${releaseListUrl#https://github.com}"
1106+
else
1107+
if command -v gh &>/dev/null && [[ "${GH_WARNING_DISPLAYED:-0}" = "0" ]]; then
1108+
Log::displayWarning "GH_TOKEN is not set, cannot use gh, using curl to retrieve release versions list"
1109+
GH_WARNING_DISPLAYED=1
1110+
fi
1111+
Retry::parameterized "${RETRY_MAX_RETRY:-5}" \
1112+
"${RETRY_DELAY_BETWEEN_RETRIES:-15}" \
1113+
"Retrieving release versions list ..." \
1114+
curl \
1115+
-L \
1116+
--connect-timeout "${CURL_CONNECT_TIMEOUT:-5}" \
1117+
--fail \
1118+
--silent \
1119+
"${releaseListUrl}"
1120+
fi
10831121
}
10841122

10851123

@@ -1097,6 +1135,7 @@ Web::getReleases() {
10971135
# @env PARSE_VERSION_CALLBACK a callback to parse the version of the existing command
10981136
# @env INSTALL_CALLBACK a callback to install the software downloaded
10991137
# @env CURL_CONNECT_TIMEOUT number of seconds before giving up host connection
1138+
# @env VERSION_PLACEHOLDER a placeholder to replace in downloadReleaseUrl (default: @latestVersion@)
11001139
Web::upgradeRelease() {
11011140
local targetFile="$1"
11021141
local releasesUrl="$2"
@@ -1107,25 +1146,28 @@ Web::upgradeRelease() {
11071146
local filterLastVersionCallback="${FILTER_LAST_VERSION_CALLBACK:-Version::parse}"
11081147
local softVersionCallback="${SOFT_VERSION_CALLBACK:-Version::getCommandVersionFromPlainText}"
11091148
local installCallback="${INSTALL_CALLBACK:-}"
1110-
local latestVersion
1111-
latestVersion="$(Web::getReleases "${releasesUrl}" | ${filterLastVersionCallback})" || {
1112-
Log::displayError "latest version not found on ${releasesUrl}"
1113-
return 1
1114-
}
1115-
Log::displayInfo "Latest version found is ${latestVersion}"
11161149

11171150
local currentVersion="not existing"
11181151
if [[ -f "${targetFile}" ]]; then
11191152
currentVersion="$(${softVersionCallback} "${targetFile}" "${softVersionArg}" 2>&1 || true)"
11201153
fi
11211154
if [[ -z "${exactVersion}" ]]; then
1155+
local latestVersion
1156+
latestVersion="$(Web::getReleases "${releasesUrl}" | ${filterLastVersionCallback})" || {
1157+
Log::displayError "latest version not found on ${releasesUrl}"
1158+
return 1
1159+
}
1160+
Log::displayInfo "Latest version found is ${latestVersion}"
1161+
11221162
exactVersion="${latestVersion}"
11231163
fi
1124-
local url="${downloadReleaseUrl//@latestVersion@/${exactVersion}}"
1164+
local url="${downloadReleaseUrl//${VERSION_PLACEHOLDER:-@latestVersion@}/${exactVersion}}"
11251165
if [[ -n "${exactVersion}" ]] && ! Github::isReleaseVersionExist "${url}"; then
11261166
Log::displayError "${targetFile} version ${exactVersion} doesn't exist on github"
11271167
return 2
11281168
fi
1169+
Log::displayDebug "currentVersion: '${currentVersion}'"
1170+
Log::displayDebug "exactVersion: '${exactVersion}'"
11291171
if [[ "${currentVersion}" = "${exactVersion}" ]]; then
11301172
Log::displayInfo "${targetFile} version ${exactVersion} already installed"
11311173
else

bin/installFacadeExample

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -516,39 +516,39 @@ Log::logFatal() {
516516
# FUNCTIONS
517517

518518
facade_main_installFacadeExamplesh() {
519-
FRAMEWORK_ROOT_DIR="$(cd "${CURRENT_DIR}/.." && pwd -P)"
520-
FRAMEWORK_SRC_DIR="${FRAMEWORK_ROOT_DIR}/src"
521-
FRAMEWORK_BIN_DIR="${FRAMEWORK_ROOT_DIR}/bin"
522-
FRAMEWORK_VENDOR_DIR="${FRAMEWORK_ROOT_DIR}/vendor"
523-
FRAMEWORK_VENDOR_BIN_DIR="${FRAMEWORK_ROOT_DIR}/vendor/bin"
524-
# REQUIRES
525-
Env::requireLoad
526-
Log::requireLoad
527-
UI::requireTheme
528-
Compiler::Facade::requireCommandBinDir
529-
530-
# @require Compiler::Facade::requireCommandBinDir
531-
532-
install() {
533-
echo "installation in progress"
534-
}
535-
536-
local action=$1
537-
shift || true
538-
case ${action} in
539-
install)
540-
install "$@"
541-
;;
542-
*)
543-
if Assert::functionExists defaultFacadeAction; then
544-
defaultFacadeAction "$1" "$@"
545-
else
546-
Log::displayError "invalid action requested: ${action}"
547-
exit 1
548-
fi
549-
;;
550-
esac
551-
exit 0
519+
FRAMEWORK_ROOT_DIR="$(cd "${CURRENT_DIR}/.." && pwd -P)"
520+
FRAMEWORK_SRC_DIR="${FRAMEWORK_ROOT_DIR}/src"
521+
FRAMEWORK_BIN_DIR="${FRAMEWORK_ROOT_DIR}/bin"
522+
FRAMEWORK_VENDOR_DIR="${FRAMEWORK_ROOT_DIR}/vendor"
523+
FRAMEWORK_VENDOR_BIN_DIR="${FRAMEWORK_ROOT_DIR}/vendor/bin"
524+
# REQUIRES
525+
Env::requireLoad
526+
Log::requireLoad
527+
UI::requireTheme
528+
Compiler::Facade::requireCommandBinDir
529+
530+
# @require Compiler::Facade::requireCommandBinDir
531+
532+
install() {
533+
echo "installation in progress"
534+
}
535+
536+
local action=$1
537+
shift || true
538+
case ${action} in
539+
install)
540+
install "$@"
541+
;;
542+
*)
543+
if Assert::functionExists defaultFacadeAction; then
544+
defaultFacadeAction "$1" "$@"
545+
else
546+
Log::displayError "invalid action requested: ${action}"
547+
exit 1
548+
fi
549+
;;
550+
esac
551+
exit 0
552552
}
553553

554554
# if file is sourced avoid calling main function

bin/installRequirements

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ Github::upgradeRelease() {
596596
}
597597
FILTER_LAST_VERSION_CALLBACK=${FILTER_LAST_VERSION_CALLBACK:-extractVersion} \
598598
SOFT_VERSION_CALLBACK="${softVersionCallback}" \
599+
INSTALL_CALLBACK="${installCallback}" \
599600
Web::upgradeRelease \
600601
"${targetFile}" \
601602
"${releasesUrl}" \
@@ -1172,12 +1173,27 @@ Version::parse() {
11721173
Web::getReleases() {
11731174
local releaseListUrl="$1"
11741175
# Get latest release from GitHub api
1175-
Retry::parameterized "${RETRY_MAX_RETRY:-5}" "${RETRY_DELAY_BETWEEN_RETRIES:-15}" "Retrieving release versions list ..." curl \
1176-
-L \
1177-
--connect-timeout "${CURL_CONNECT_TIMEOUT:-5}" \
1178-
--fail \
1179-
--silent \
1180-
"${releaseListUrl}"
1176+
if command -v gh &>/dev/null && [[ -n "${GH_TOKEN}" ]]; then
1177+
Log::displayDebug "Using gh to retrieve release versions list"
1178+
Retry::parameterized "${RETRY_MAX_RETRY:-5}" \
1179+
"${RETRY_DELAY_BETWEEN_RETRIES:-15}" \
1180+
"Retrieving release versions list ..." \
1181+
gh api "${releaseListUrl#https://github.com}"
1182+
else
1183+
if command -v gh &>/dev/null && [[ "${GH_WARNING_DISPLAYED:-0}" = "0" ]]; then
1184+
Log::displayWarning "GH_TOKEN is not set, cannot use gh, using curl to retrieve release versions list"
1185+
GH_WARNING_DISPLAYED=1
1186+
fi
1187+
Retry::parameterized "${RETRY_MAX_RETRY:-5}" \
1188+
"${RETRY_DELAY_BETWEEN_RETRIES:-15}" \
1189+
"Retrieving release versions list ..." \
1190+
curl \
1191+
-L \
1192+
--connect-timeout "${CURL_CONNECT_TIMEOUT:-5}" \
1193+
--fail \
1194+
--silent \
1195+
"${releaseListUrl}"
1196+
fi
11811197
}
11821198

11831199

@@ -1195,6 +1211,7 @@ Web::getReleases() {
11951211
# @env PARSE_VERSION_CALLBACK a callback to parse the version of the existing command
11961212
# @env INSTALL_CALLBACK a callback to install the software downloaded
11971213
# @env CURL_CONNECT_TIMEOUT number of seconds before giving up host connection
1214+
# @env VERSION_PLACEHOLDER a placeholder to replace in downloadReleaseUrl (default: @latestVersion@)
11981215
Web::upgradeRelease() {
11991216
local targetFile="$1"
12001217
local releasesUrl="$2"
@@ -1205,25 +1222,28 @@ Web::upgradeRelease() {
12051222
local filterLastVersionCallback="${FILTER_LAST_VERSION_CALLBACK:-Version::parse}"
12061223
local softVersionCallback="${SOFT_VERSION_CALLBACK:-Version::getCommandVersionFromPlainText}"
12071224
local installCallback="${INSTALL_CALLBACK:-}"
1208-
local latestVersion
1209-
latestVersion="$(Web::getReleases "${releasesUrl}" | ${filterLastVersionCallback})" || {
1210-
Log::displayError "latest version not found on ${releasesUrl}"
1211-
return 1
1212-
}
1213-
Log::displayInfo "Latest version found is ${latestVersion}"
12141225

12151226
local currentVersion="not existing"
12161227
if [[ -f "${targetFile}" ]]; then
12171228
currentVersion="$(${softVersionCallback} "${targetFile}" "${softVersionArg}" 2>&1 || true)"
12181229
fi
12191230
if [[ -z "${exactVersion}" ]]; then
1231+
local latestVersion
1232+
latestVersion="$(Web::getReleases "${releasesUrl}" | ${filterLastVersionCallback})" || {
1233+
Log::displayError "latest version not found on ${releasesUrl}"
1234+
return 1
1235+
}
1236+
Log::displayInfo "Latest version found is ${latestVersion}"
1237+
12201238
exactVersion="${latestVersion}"
12211239
fi
1222-
local url="${downloadReleaseUrl//@latestVersion@/${exactVersion}}"
1240+
local url="${downloadReleaseUrl//${VERSION_PLACEHOLDER:-@latestVersion@}/${exactVersion}}"
12231241
if [[ -n "${exactVersion}" ]] && ! Github::isReleaseVersionExist "${url}"; then
12241242
Log::displayError "${targetFile} version ${exactVersion} doesn't exist on github"
12251243
return 2
12261244
fi
1245+
Log::displayDebug "currentVersion: '${currentVersion}'"
1246+
Log::displayDebug "exactVersion: '${exactVersion}'"
12271247
if [[ "${currentVersion}" = "${exactVersion}" ]]; then
12281248
Log::displayInfo "${targetFile} version ${exactVersion} already installed"
12291249
else

0 commit comments

Comments
 (0)