Skip to content
Snippets Groups Projects
Unverified Commit 16c05d16 authored by paulfantom's avatar paulfantom
Browse files

jsonnet,scripts: better version updater

parent ebd4b28b
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
"alertmanager": "0.21.0", "alertmanager": "0.21.0",
"blackboxExporter": "0.18.0", "blackboxExporter": "0.18.0",
"grafana": "7.4.3", "grafana": "7.4.3",
"kubeStateMetrics": "1.9.8",
"nodeExporter": "1.1.1", "nodeExporter": "1.1.1",
"prometheus": "2.25.0", "prometheus": "2.25.0",
"prometheusAdapter": "0.8.3", "prometheusAdapter": "0.8.3",
......
...@@ -2,11 +2,38 @@ ...@@ -2,11 +2,38 @@
set -euo pipefail set -euo pipefail
# Get component version from GitHub API
get_latest_version() { get_latest_version() {
echo >&2 "Checking release version for ${1}" echo >&2 "Checking release version for ${1}"
curl --retry 5 --silent --fail -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/repos/${1}/releases/latest" | jq '.tag_name' | tr -d '"v' curl --retry 5 --silent --fail -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/repos/${1}/releases/latest" | jq '.tag_name' | tr -d '"v'
} }
# Get component version from version file
get_current_version() {
echo >&2 "Reading currently used version of ${1}"
jq -r ".${1}" "$VERSION_FILE"
}
# Get version from online source and filter out unstable releases. In case of unstable release use what is set in version file
get_version() {
component="${1}"
v="$(get_latest_version "${component}")"
# Advanced AI heurestics to filter out common patterns suggesting new version is not stable /s
if [[ "$v" == *"alpha"* ]] || [[ "$v" == *"beta"* ]] || [[ "$v" == *"rc"* ]] || [[ "$v" == *"helm"* ]]; then
component="$(convert_to_camel_case "$(echo "${component}" | sed 's/^.*\///')")"
v="$(get_current_version "${component}")"
fi
echo "$v"
}
convert_to_camel_case() {
echo "${1}" | sed -E 's/[ _-]([a-z])/\U\1/gi;s/^([A-Z])/\l\1/'
}
# File is used to read current versions
VERSION_FILE="jsonnet/kube-prometheus/versions.json"
# token can be passed as `GITHUB_TOKEN` variable or passed as first argument # token can be passed as `GITHUB_TOKEN` variable or passed as first argument
GITHUB_TOKEN=${GITHUB_TOKEN:-${1}} GITHUB_TOKEN=${GITHUB_TOKEN:-${1}}
...@@ -17,12 +44,13 @@ fi ...@@ -17,12 +44,13 @@ fi
cat <<-EOF cat <<-EOF
{ {
"alertmanager": "$(get_latest_version "prometheus/alertmanager")", "alertmanager": "$(get_version "prometheus/alertmanager")",
"blackboxExporter": "$(get_latest_version "prometheus/blackbox_exporter")", "blackboxExporter": "$(get_version "prometheus/blackbox_exporter")",
"grafana": "$(get_latest_version "grafana/grafana")", "grafana": "$(get_version "grafana/grafana")",
"nodeExporter": "$(get_latest_version "prometheus/node_exporter")", "kubeStateMetrics": "$(get_version "kubernetes/kube-state-metrics")",
"prometheus": "$(get_latest_version "prometheus/prometheus")", "nodeExporter": "$(get_version "prometheus/node_exporter")",
"prometheusAdapter": "$(get_latest_version "kubernetes-sigs/prometheus-adapter")", "prometheus": "$(get_version "prometheus/prometheus")",
"prometheusOperator": "$(get_latest_version "prometheus-operator/prometheus-operator")" "prometheusAdapter": "$(get_version "kubernetes-sigs/prometheus-adapter")",
"prometheusOperator": "$(get_version "prometheus-operator/prometheus-operator")"
} }
EOF EOF
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment