|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -eu |
| 4 | + |
| 5 | +# Script to automatically update the version compatibility matrix in README.md |
| 6 | +# This script fetches the last N supported minor versions of Cilium, |
| 7 | +# gets all patch releases for each, and extracts the Envoy version from |
| 8 | +# each Cilium Docker image. |
| 9 | +# |
| 10 | +# Usage: |
| 11 | +# ./update_version_matrix.sh [OPTIONS] |
| 12 | +# |
| 13 | +# Options: |
| 14 | +# -n, --dry-run Show what would be updated without making changes |
| 15 | +# -v, --verbose Enable verbose output |
| 16 | +# -h, --help Show this help message |
| 17 | +# |
| 18 | +# Environment variables: |
| 19 | +# SUPPORTED_MINOR_VERSIONS Number of minor versions to include (default: 3) |
| 20 | + |
| 21 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 22 | +REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" |
| 23 | +README_FILE="${REPO_ROOT}/README.md" |
| 24 | + |
| 25 | +# Number of minor versions to support (Cilium supports last 3 minor versions) |
| 26 | +SUPPORTED_MINOR_VERSIONS=${SUPPORTED_MINOR_VERSIONS:-3} |
| 27 | + |
| 28 | +# Options |
| 29 | +DRY_RUN=false |
| 30 | +VERBOSE=false |
| 31 | + |
| 32 | +# Parse command line arguments |
| 33 | +while [[ $# -gt 0 ]]; do |
| 34 | + case $1 in |
| 35 | + -n|--dry-run) |
| 36 | + DRY_RUN=true |
| 37 | + shift |
| 38 | + ;; |
| 39 | + -v|--verbose) |
| 40 | + VERBOSE=true |
| 41 | + shift |
| 42 | + ;; |
| 43 | + -h|--help) |
| 44 | + echo "Update the version compatibility matrix in README.md" |
| 45 | + echo "" |
| 46 | + echo "Usage: $(basename "$0") [OPTIONS]" |
| 47 | + echo "" |
| 48 | + echo "Options:" |
| 49 | + echo " -n, --dry-run Show what would be updated without making changes" |
| 50 | + echo " -v, --verbose Enable verbose output" |
| 51 | + echo " -h, --help Show this help message" |
| 52 | + echo "" |
| 53 | + echo "Environment variables:" |
| 54 | + echo " SUPPORTED_MINOR_VERSIONS Number of minor versions to include (default: 3)" |
| 55 | + exit 0 |
| 56 | + ;; |
| 57 | + *) |
| 58 | + echo "Unknown option: $1" |
| 59 | + exit 1 |
| 60 | + ;; |
| 61 | + esac |
| 62 | +done |
| 63 | + |
| 64 | +log_verbose() { |
| 65 | + if [[ "${VERBOSE}" == "true" ]]; then |
| 66 | + echo "$@" >&2 |
| 67 | + fi |
| 68 | +} |
| 69 | + |
| 70 | +# Temporary file for building the matrix |
| 71 | +TEMP_MATRIX=$(mktemp) |
| 72 | +trap "rm -f ${TEMP_MATRIX}" EXIT |
| 73 | + |
| 74 | +echo "Fetching Cilium releases..." |
| 75 | + |
| 76 | +# Get all Cilium release tags from GitHub API |
| 77 | +# Filter to stable releases (vX.Y.Z format, no rc/beta/alpha) |
| 78 | +get_cilium_releases() { |
| 79 | + local page=1 |
| 80 | + local releases="" |
| 81 | + |
| 82 | + while true; do |
| 83 | + local response |
| 84 | + response=$(curl -s "https://api.github.com/repos/cilium/cilium/releases?per_page=100&page=${page}") |
| 85 | + |
| 86 | + # Check if we got any results |
| 87 | + if [[ $(echo "${response}" | jq 'length') -eq 0 ]]; then |
| 88 | + break |
| 89 | + fi |
| 90 | + |
| 91 | + # Extract tag names, filter stable releases only (vX.Y.Z) |
| 92 | + local page_releases |
| 93 | + page_releases=$(echo "${response}" | jq -r '.[].tag_name' | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' || true) |
| 94 | + |
| 95 | + if [[ -n "${page_releases}" ]]; then |
| 96 | + releases="${releases}${page_releases}"$'\n' |
| 97 | + fi |
| 98 | + |
| 99 | + # Check if there are more pages |
| 100 | + if [[ $(echo "${response}" | jq 'length') -lt 100 ]]; then |
| 101 | + break |
| 102 | + fi |
| 103 | + |
| 104 | + page=$((page + 1)) |
| 105 | + done |
| 106 | + |
| 107 | + echo "${releases}" | grep -v '^$' | sort -V -r |
| 108 | +} |
| 109 | + |
| 110 | +# Extract minor version from a full version string (e.g., v1.18.1 -> 1.18) |
| 111 | +get_minor_version() { |
| 112 | + echo "$1" | sed -E 's/^v([0-9]+\.[0-9]+)\.[0-9]+$/\1/' |
| 113 | +} |
| 114 | + |
| 115 | +# Get the main branch Envoy version from Cilium main branch Dockerfile |
| 116 | +get_main_envoy_version() { |
| 117 | + local dockerfile_url="https://raw.githubusercontent.com/cilium/cilium/main/images/cilium/Dockerfile" |
| 118 | + local dockerfile_content |
| 119 | + dockerfile_content=$(curl -sf "${dockerfile_url}" 2>/dev/null || true) |
| 120 | + |
| 121 | + if [[ -n "${dockerfile_content}" ]]; then |
| 122 | + # Extract version from CILIUM_ENVOY_IMAGE line and convert to vX.Y.x format |
| 123 | + local version |
| 124 | + version=$(echo "${dockerfile_content}" | grep -E "CILIUM_ENVOY_IMAGE=" | grep -oE 'cilium-envoy:v[0-9]+\.[0-9]+\.[0-9]+' | grep -oE '[0-9]+\.[0-9]+' | head -1 || true) |
| 125 | + if [[ -n "${version}" ]]; then |
| 126 | + echo "v${version}.x" |
| 127 | + return |
| 128 | + fi |
| 129 | + fi |
| 130 | + |
| 131 | + echo " Warning: Could not fetch main branch Envoy version" >&2 |
| 132 | + echo "unknown" |
| 133 | +} |
| 134 | + |
| 135 | +# Get the Envoy version from Cilium GitHub source (Dockerfile) |
| 136 | +get_envoy_version() { |
| 137 | + local cilium_version=$1 |
| 138 | + local envoy_version |
| 139 | + |
| 140 | + log_verbose " Fetching Envoy version for Cilium ${cilium_version} from GitHub..." |
| 141 | + |
| 142 | + # Fetch the Dockerfile from GitHub and extract CILIUM_ENVOY_IMAGE version |
| 143 | + # Format: ARG CILIUM_ENVOY_IMAGE=quay.io/cilium/cilium-envoy:v1.35.9-... |
| 144 | + local dockerfile_url="https://raw.githubusercontent.com/cilium/cilium/${cilium_version}/images/cilium/Dockerfile" |
| 145 | + local dockerfile_content |
| 146 | + dockerfile_content=$(curl -sf "${dockerfile_url}" 2>/dev/null || true) |
| 147 | + |
| 148 | + if [[ -z "${dockerfile_content}" ]]; then |
| 149 | + echo " Warning: Failed to fetch Dockerfile for ${cilium_version}" >&2 |
| 150 | + echo "unknown" |
| 151 | + return |
| 152 | + fi |
| 153 | + |
| 154 | + # Extract version from CILIUM_ENVOY_IMAGE line |
| 155 | + # Pattern: quay.io/cilium/cilium-envoy:vX.Y.Z-... |
| 156 | + envoy_version=$(echo "${dockerfile_content}" | grep -E "CILIUM_ENVOY_IMAGE=" | grep -oE 'cilium-envoy:v[0-9]+\.[0-9]+\.[0-9]+' | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+' | head -1 || true) |
| 157 | + |
| 158 | + if [[ -n "${envoy_version}" ]]; then |
| 159 | + echo "${envoy_version}" |
| 160 | + return |
| 161 | + fi |
| 162 | + |
| 163 | + echo " Warning: Could not extract Envoy version for ${cilium_version}" >&2 |
| 164 | + echo "unknown" |
| 165 | +} |
| 166 | + |
| 167 | +# Get all releases |
| 168 | +ALL_RELEASES=$(get_cilium_releases) |
| 169 | + |
| 170 | +if [[ -z "${ALL_RELEASES}" ]]; then |
| 171 | + echo "Error: Failed to fetch Cilium releases" |
| 172 | + exit 1 |
| 173 | +fi |
| 174 | + |
| 175 | +# Get unique minor versions and select the latest N |
| 176 | +MINOR_VERSIONS=$(echo "${ALL_RELEASES}" | while read -r version; do |
| 177 | + get_minor_version "${version}" |
| 178 | +done | sort -V -r | uniq | head -n "${SUPPORTED_MINOR_VERSIONS}") |
| 179 | + |
| 180 | +echo "Supported minor versions: $(echo ${MINOR_VERSIONS} | tr '\n' ' ')" |
| 181 | + |
| 182 | +# Build the matrix |
| 183 | +echo "Building version matrix..." |
| 184 | + |
| 185 | +# Collect all versions we need to process |
| 186 | +VERSIONS_TO_PROCESS="" |
| 187 | +for minor in ${MINOR_VERSIONS}; do |
| 188 | + # Get all patch releases for this minor version |
| 189 | + PATCH_RELEASES=$(echo "${ALL_RELEASES}" | grep "^v${minor}\." | sort -V -r) |
| 190 | + VERSIONS_TO_PROCESS="${VERSIONS_TO_PROCESS}${PATCH_RELEASES}"$'\n' |
| 191 | +done |
| 192 | + |
| 193 | +# Remove empty lines and process each version |
| 194 | +echo "${VERSIONS_TO_PROCESS}" | grep -v '^$' | while read -r version; do |
| 195 | + envoy_ver=$(get_envoy_version "${version}") |
| 196 | + echo "${version}|${envoy_ver}" |
| 197 | +done > "${TEMP_MATRIX}" |
| 198 | + |
| 199 | +# Generate the new table content |
| 200 | +generate_table() { |
| 201 | + local main_envoy_version |
| 202 | + main_envoy_version=$(get_main_envoy_version) |
| 203 | + |
| 204 | + echo "| Cilium Version | Envoy version |" |
| 205 | + echo "|----------------|---------------|" |
| 206 | + printf "| %-14s | %-13s |\n" "(main)" "${main_envoy_version}" |
| 207 | + |
| 208 | + while IFS='|' read -r cilium_ver envoy_ver; do |
| 209 | + printf "| %-14s | %-13s |\n" "${cilium_ver}" "${envoy_ver}" |
| 210 | + done < "${TEMP_MATRIX}" |
| 211 | + echo "" |
| 212 | +} |
| 213 | + |
| 214 | +# Find the line numbers for the table |
| 215 | +TABLE_START=$(grep -n "| Cilium Version | Envoy version |" "${README_FILE}" | cut -d: -f1) |
| 216 | + |
| 217 | +if [[ -z "${TABLE_START}" ]]; then |
| 218 | + echo "Error: Could not find version matrix table in README.md" |
| 219 | + exit 1 |
| 220 | +fi |
| 221 | + |
| 222 | +# Find where the table ends (first non-table line after the header) |
| 223 | +TABLE_END=$(tail -n +"${TABLE_START}" "${README_FILE}" | grep -n -m 1 "^[^|]" | cut -d: -f1) |
| 224 | +TABLE_END=$((TABLE_START + TABLE_END - 2)) |
| 225 | + |
| 226 | +if [[ "${DRY_RUN}" == "true" ]]; then |
| 227 | + echo "" |
| 228 | + echo "=== DRY RUN - Would update README.md with: ===" |
| 229 | + echo "" |
| 230 | + generate_table |
| 231 | + echo "" |
| 232 | + echo "=== End of table ===" |
| 233 | + echo "" |
| 234 | + echo "Versions collected:" |
| 235 | + cat "${TEMP_MATRIX}" |
| 236 | +else |
| 237 | + # Update the README.md |
| 238 | + echo "Updating README.md..." |
| 239 | + |
| 240 | + # Create new README content |
| 241 | + { |
| 242 | + head -n "$((TABLE_START - 1))" "${README_FILE}" |
| 243 | + generate_table |
| 244 | + tail -n "+$((TABLE_END + 1))" "${README_FILE}" |
| 245 | + } > "${README_FILE}.new" |
| 246 | + |
| 247 | + mv "${README_FILE}.new" "${README_FILE}" |
| 248 | + |
| 249 | + echo "Done! Version matrix updated in README.md" |
| 250 | + echo "" |
| 251 | + echo "Updated versions:" |
| 252 | + cat "${TEMP_MATRIX}" |
| 253 | +fi |
0 commit comments