|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +# --- 1. Find all Static Tool Versions and put them into a single JSON object --- |
| 6 | + |
| 7 | +# Collect all versions into bash variables first |
| 8 | +HELM_VERSION=$(curl -s https://api.github.com/repos/helm/helm/releases | jq -r '.[].tag_name | select([startswith("v"), (contains("-") | not)] | all)' | sort -rV | head -n 1 | sed 's/v//') |
| 9 | +KUSTOMIZE_RELEASE=$(curl -s https://api.github.com/repos/kubernetes-sigs/kustomize/releases | jq -r '.[].tag_name | select(contains("kustomize"))' | sort -rV | head -n 1) |
| 10 | +KUSTOMIZE_VERSION=$(basename ${KUSTOMIZE_RELEASE}) |
| 11 | +KUBESEAL_VERSION=$(curl -s https://api.github.com/repos/bitnami-labs/sealed-secrets/releases | jq -r '.[].tag_name | select(startswith("v"))' | sort -rV | head -n 1 | sed 's/v//') |
| 12 | +KREW_VERSION=$(curl -s https://api.com/repos/kubernetes-sigs/krew/releases | jq -r '.[].tag_name | select(startswith("v"))' | sort -rV | head -n 1 | sed 's/v//') |
| 13 | +VALS_VERSION=$(curl -s https://api.github.com/repos/helmfile/vals/releases | jq -r '.[].tag_name | select(startswith("v"))' | sort -rV | head -n 1 | sed 's/v//') |
| 14 | +KUBECONFORM_VERSION=$(curl -s https://api.github.com/repos/yannh/kubeconform/releases | jq -r '.[].tag_name | select(startswith("v"))' | sort -rV | head -n 1 | sed 's/v//') |
| 15 | + |
| 16 | + |
| 17 | +# Construct a single JSON object with all static tool versions |
| 18 | +# This will be output to the GITHUB_OUTPUT variable 'latest_tools' |
| 19 | +LATEST_TOOLS_JSON=$( |
| 20 | + jq -n \ |
| 21 | + --arg helm "$HELM_VERSION" \ |
| 22 | + --arg kustomize "$KUSTOMIZE_VERSION" \ |
| 23 | + --arg kubeseal "$KUBESEAL_VERSION" \ |
| 24 | + --arg krew "$KREW_VERSION" \ |
| 25 | + --arg vals "$VALS_VERSION" \ |
| 26 | + --arg kubeconform "$KUBECONFORM_VERSION" \ |
| 27 | + '{ |
| 28 | + "helm_version": $helm, |
| 29 | + "kustomize_version": $kustomize, |
| 30 | + "kubeseal_version": $kubeseal, |
| 31 | + "krew_version": $krew, |
| 32 | + "vals_version": $vals, |
| 33 | + "kubeconform_version": $kubeconform |
| 34 | + }' |
| 35 | +) |
| 36 | + |
| 37 | +echo "latest_tools=$LATEST_TOOLS_JSON" >> $GITHUB_OUTPUT |
| 38 | +echo "Found static tools: $LATEST_TOOLS_JSON" |
| 39 | + |
| 40 | +# --- 2. Find the top 4 latest K8s minor versions and output as a JSON Array --- |
| 41 | + |
| 42 | +# Get the list of all releases tags, excludes alpha, beta, rc tags |
| 43 | +RELEASES=$(curl -s https://api.github.com/repos/kubernetes/kubernetes/releases | jq -r '.[].tag_name | select(test("alpha|beta|rc") | not)') |
| 44 | + |
| 45 | +# Logic to extract unique minor versions |
| 46 | +MINOR_VERSIONS=() |
| 47 | +for RELEASE in $RELEASES; do |
| 48 | + # Extract v1.30 or v1.29 |
| 49 | + MINOR_VERSION=$(echo $RELEASE | awk -F'.' '{print $1"."$2}') |
| 50 | + if [[ ! " ${MINOR_VERSIONS[@]} " =~ " ${MINOR_VERSION} " ]]; then |
| 51 | + MINOR_VERSIONS+=($MINOR_VERSION) |
| 52 | + fi |
| 53 | +done |
| 54 | + |
| 55 | +# Sort the unique minor versions in reverse order |
| 56 | +SORTED_MINOR_VERSIONS=($(echo "${MINOR_VERSIONS[@]}" | tr ' ' '\n' | sort -rV)) |
| 57 | + |
| 58 | +# Loop through the first 4 unique minor versions and get the LATEST PATCH for each |
| 59 | +K8S_TAGS=() |
| 60 | +# Loop for the first 4 latest minors |
| 61 | +for i in $(seq 0 3); do |
| 62 | + MINOR_VERSION="${SORTED_MINOR_VERSIONS[$i]}" |
| 63 | + # Get the single latest patch version for this minor |
| 64 | + LATEST_VERSION=$(echo "$RELEASES" | grep "^$MINOR_VERSION\." | sort -rV | head -1 | sed 's/v//') |
| 65 | + K8S_TAGS+=("$LATEST_VERSION") |
| 66 | +done |
| 67 | + |
| 68 | +# Convert the bash array into a JSON array string |
| 69 | +K8S_TAGS_JSON=$(printf '%s\n' "${K8S_TAGS[@]}" | jq -R . | jq -s .) |
| 70 | + |
| 71 | +echo "k8s_versions=$K8S_TAGS_JSON" >> $GITHUB_OUTPUT |
| 72 | +echo "Found K8s versions: ${K8S_TAGS[*]}" |
0 commit comments