From 47c7e637ae0ad76e84be94a47e737552261c3d22 Mon Sep 17 00:00:00 2001 From: Wendy Ha Date: Mon, 16 Mar 2026 18:08:06 +1100 Subject: [PATCH 1/2] Create new GH Action workflow to auto fetch new kubernetes release version monthly Signed-off-by: Wendy Ha --- .github/workflows/detect-k8s-releases.yml | 37 +++++++++ hack/k8s-supported-versions.json | 5 ++ scripts/update-k8s-supported-versions.sh | 96 +++++++++++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 .github/workflows/detect-k8s-releases.yml create mode 100644 hack/k8s-supported-versions.json create mode 100755 scripts/update-k8s-supported-versions.sh diff --git a/.github/workflows/detect-k8s-releases.yml b/.github/workflows/detect-k8s-releases.yml new file mode 100644 index 0000000000..40fa3dc56c --- /dev/null +++ b/.github/workflows/detect-k8s-releases.yml @@ -0,0 +1,37 @@ +name: detect-k8s-releases + +on: + schedule: + # Run on the 1st and 15th of each month (fortnightly) + - cron: '0 0 1,15 * *' + workflow_dispatch: + +permissions: + contents: write + pull-requests: write + +jobs: + update-versions: + name: Update K8s supported versions + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v5 + with: + fetch-depth: 0 + + - name: Update K8s supported versions + run: ./scripts/update-k8s-supported-versions.sh + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v6 + with: + branch: k8s-versions-update + delete-branch: true + add-paths: hack/k8s-supported-versions.json + title: "chore: update K8s supported versions" + body: | + Automated update of the K8s supported versions file. + + This PR updates `hack/k8s-supported-versions.json` with the current supported Kubernetes release series (from kubernetes/kubernetes release-1.* branches) and the latest patch version per series. + commit-message: "chore: update K8s supported versions" diff --git a/hack/k8s-supported-versions.json b/hack/k8s-supported-versions.json new file mode 100644 index 0000000000..412c126ac6 --- /dev/null +++ b/hack/k8s-supported-versions.json @@ -0,0 +1,5 @@ +{ + "lastUpdated": "", + "supported_kubernetes_series": [], + "latest_releases": [] +} diff --git a/scripts/update-k8s-supported-versions.sh b/scripts/update-k8s-supported-versions.sh new file mode 100755 index 0000000000..b158804973 --- /dev/null +++ b/scripts/update-k8s-supported-versions.sh @@ -0,0 +1,96 @@ +#!/bin/bash +# +# Updates hack/k8s-supported-versions.json by fetching all patch releases +# for the 3 latest Kubernetes series from GitHub. Runs fortnightly via workflow. +# +# Prerequisites: curl, jq +# +# Usage: ./scripts/update-k8s-supported-versions.sh [output_path] +# output_path defaults to hack/k8s-supported-versions.json +# + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" +OUTPUT_PATH="${1:-${REPO_ROOT}/hack/k8s-supported-versions.json}" +GITHUB_API="https://api.github.com/repos/kubernetes/kubernetes" +DL_K8S="https://dl.k8s.io/release" + +# --- Dependency checks --- +for tool in curl jq; do + if ! command -v "$tool" &>/dev/null; then + echo "ERROR: Required tool '$tool' not found. Please install it." >&2 + exit 1 + fi +done + +# --- Step 1: Fetch supported series from release-1.* branches --- +echo "Fetching release branches from kubernetes/kubernetes..." +BRANCHES_JSON=$(curl -sSL "${GITHUB_API}/branches?per_page=100") + +SUPPORTED_SERIES=() +while IFS= read -r minor; do + [[ -z "$minor" ]] && continue + SUPPORTED_SERIES+=("v1.${minor}") +done < <(echo "$BRANCHES_JSON" | jq -r '.[].name | select(test("^release-1\\.[0-9]+$")) | sub("^release-1\\."; "")' | sort -n -r | head -3) + +# Fallback: if no branches found, use stable.txt +if [[ ${#SUPPORTED_SERIES[@]} -eq 0 ]]; then + echo "WARN: No release-1.* branches found, falling back to dl.k8s.io stable.txt" >&2 + LATEST=$(curl -sSL "${DL_K8S}/stable.txt") + LATEST="${LATEST//[$'\r']}" + if [[ "$LATEST" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then + MAJOR="${BASH_REMATCH[1]}" + MINOR="${BASH_REMATCH[2]}" + [[ "${BASH_REMATCH[3]}" == "0" ]] && MINOR=$((MINOR - 1)) + for i in 0 1 2; do + M=$((MINOR - i)) + [[ $M -lt 0 ]] && break + SUPPORTED_SERIES+=("v${MAJOR}.${M}") + done + fi +fi + +echo "Supported series: ${SUPPORTED_SERIES[*]:-none}" + +# Build regex for supported series: ^v1\.(35|34|33)\.[0-9]+$ +SERIES_REGEX="^v1\\.($(IFS='|'; echo "${SUPPORTED_SERIES[*]#v1.}"))\\.[0-9]+\$" + +# --- Step 2: Fetch all patch releases from GitHub (paginated) --- +echo "Fetching patch releases from GitHub..." +ALL_RELEASES_JSON="[]" +PAGE=1 +MAX_PAGES=15 + +while [[ $PAGE -le $MAX_PAGES ]]; do + PAGE_JSON=$(curl -sSL "${GITHUB_API}/releases?per_page=100&page=${PAGE}") + COUNT=$(echo "$PAGE_JSON" | jq 'length') + [[ "$COUNT" -eq 0 ]] && break + + FILTERED=$(echo "$PAGE_JSON" | jq --arg re "$SERIES_REGEX" ' + [.[] | select(.prerelease == false) | select(.tag_name | test($re)) | + {version: .tag_name, release_date: .published_at, series: (.tag_name | capture("^v(?[0-9]+)\\.(?[0-9]+)\\.") | "v\(.major).\(.minor)")}] + ') + ALL_RELEASES_JSON=$(echo "$ALL_RELEASES_JSON" "$FILTERED" | jq -s 'add') + + [[ "$COUNT" -lt 100 ]] && break + PAGE=$((PAGE + 1)) +done + +# Sort by version descending +ALL_RELEASES_JSON=$(echo "$ALL_RELEASES_JSON" | jq 'sort_by(.version) | reverse') + +# --- Step 3: Write output --- +SUPPORTED_SERIES_JSON=$(printf '%s\n' "${SUPPORTED_SERIES[@]}" | jq -R . | jq -s .) +LAST_UPDATED=$(date -u +"%Y-%m-%dT%H:%M:%SZ") + +OUTPUT=$(jq -n \ + --arg lastUpdated "$LAST_UPDATED" \ + --argjson supported_kubernetes_series "$SUPPORTED_SERIES_JSON" \ + --argjson latest_releases "$ALL_RELEASES_JSON" \ + '{lastUpdated: $lastUpdated, supported_kubernetes_series: $supported_kubernetes_series, latest_releases: $latest_releases}') + +mkdir -p "$(dirname "$OUTPUT_PATH")" +echo "$OUTPUT" | jq '.' > "$OUTPUT_PATH" +echo "Wrote $(basename "$OUTPUT_PATH") to $OUTPUT_PATH ($(echo "$ALL_RELEASES_JSON" | jq 'length') releases)" From d0f0205dab06529469b68ea61545a94f1d14b74e Mon Sep 17 00:00:00 2001 From: Wendy Ha Date: Mon, 16 Mar 2026 18:22:00 +1100 Subject: [PATCH 2/2] Schedule workflow to run on monthly rather than biweekly Signed-off-by: Wendy Ha --- .github/workflows/detect-k8s-releases.yml | 7 +++---- scripts/update-k8s-supported-versions.sh | 10 ---------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/.github/workflows/detect-k8s-releases.yml b/.github/workflows/detect-k8s-releases.yml index 40fa3dc56c..f5326075d7 100644 --- a/.github/workflows/detect-k8s-releases.yml +++ b/.github/workflows/detect-k8s-releases.yml @@ -2,8 +2,7 @@ name: detect-k8s-releases on: schedule: - # Run on the 1st and 15th of each month (fortnightly) - - cron: '0 0 1,15 * *' + - cron: '0 0 15 * *' # the workflow scheduled to run on the 15th of each month based on patch release calendar: https://kubernetes.io/releases/patch-releases/ workflow_dispatch: permissions: @@ -29,9 +28,9 @@ jobs: branch: k8s-versions-update delete-branch: true add-paths: hack/k8s-supported-versions.json - title: "chore: update K8s supported versions" + title: "🌱 chore: update K8s supported versions" body: | Automated update of the K8s supported versions file. - This PR updates `hack/k8s-supported-versions.json` with the current supported Kubernetes release series (from kubernetes/kubernetes release-1.* branches) and the latest patch version per series. + This PR updates `hack/k8s-supported-versions.json` with the current supported Kubernetes release series and the latest patch version per series. commit-message: "chore: update K8s supported versions" diff --git a/scripts/update-k8s-supported-versions.sh b/scripts/update-k8s-supported-versions.sh index b158804973..b5b6235a83 100755 --- a/scripts/update-k8s-supported-versions.sh +++ b/scripts/update-k8s-supported-versions.sh @@ -1,13 +1,4 @@ #!/bin/bash -# -# Updates hack/k8s-supported-versions.json by fetching all patch releases -# for the 3 latest Kubernetes series from GitHub. Runs fortnightly via workflow. -# -# Prerequisites: curl, jq -# -# Usage: ./scripts/update-k8s-supported-versions.sh [output_path] -# output_path defaults to hack/k8s-supported-versions.json -# set -euo pipefail @@ -26,7 +17,6 @@ for tool in curl jq; do done # --- Step 1: Fetch supported series from release-1.* branches --- -echo "Fetching release branches from kubernetes/kubernetes..." BRANCHES_JSON=$(curl -sSL "${GITHUB_API}/branches?per_page=100") SUPPORTED_SERIES=()