Skip to content
Snippets Groups Projects
Commit 29a15163 authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

refactor: add function to get latest package version from github

parent 22003d19
Branches
Tags
No related merge requests found
......@@ -312,6 +312,11 @@ variables:
echo -e "[\\e[1;91mERROR\\e[0m] $*"
}
function fail() {
log_error "$*"
exit 1
}
function assert_defined() {
if [[ -z "$1" ]]
then
......@@ -836,6 +841,18 @@ variables:
fi
}
function github_get_latest_version() {
if command -v curl &> /dev/null
then
curl -sSf -I "https://github.com/$1/releases/latest" | awk -F '/' '/location:/ {print $NF}'
elif command -v python3 &> /dev/null
then
python3 -c "import urllib.request;url='https://github.com/$1/releases/latest';opener=urllib.request.build_opener(type('NoRedirection', (urllib.request.HTTPErrorProcessor,), {'http_response': lambda self, req, resp: resp, 'https_response': lambda self, req, resp: resp})());req=urllib.request.Request(url, method='HEAD');print(opener.open(req).headers.get('Location').split('/')[-1])"
else
fail "curl or python3 required"
fi
}
unscope_variables
eval_all_secrets
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment