diff --git a/templates/gitlab-ci-python.yml b/templates/gitlab-ci-python.yml index ffc92507537a9d57bf847551018fe417e2b1c681..d1dd8ecaf1acef6bff754ff6dbd884531f5e70cc 100644 --- a/templates/gitlab-ci-python.yml +++ b/templates/gitlab-ci-python.yml @@ -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