|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Helm Documentation Update Script |
| 4 | +# |
| 5 | +# This script automatically updates the Helm website (helm.sh) with the latest |
| 6 | +# release information for versions of Helm. It performs the following tasks: |
| 7 | +# |
| 8 | +# 1. Fetches the latest stable releases from GitHub API |
| 9 | +# 2. Compares with current versions in config.toml |
| 10 | +# 3. Updates version references if a new significant release is found |
| 11 | +# 4. For v3 updates: also updates go.mod dependencies and CLI documentation |
| 12 | +# 5. For v2 updates: only updates version references (legacy support) |
| 13 | +# |
| 14 | +# Usage: ./update-docs.sh <v2|v3> |
| 15 | +# |
| 16 | +# The script only updates for significant releases (minor version bumps or |
| 17 | +# newer patch versions). It creates backups and validates all changes before |
| 18 | +# committing them. |
| 19 | +# |
| 20 | +# Dependencies: curl, jq, docker (for CLI docs), go (for v3 go.mod updates) |
| 21 | +# |
| 22 | +set -euo pipefail |
| 23 | + |
| 24 | +# Colors for output |
| 25 | +RED='\033[0;31m' |
| 26 | +GREEN='\033[0;32m' |
| 27 | +YELLOW='\033[1;33m' |
| 28 | +NC='\033[0m' # No Color |
| 29 | + |
| 30 | +# Validate command line arguments |
| 31 | +if [ $# -ne 1 ] || { [ "$1" != "v2" ] && [ "$1" != "v3" ]; }; then |
| 32 | + echo -e "${RED}Usage: $0 <v2|v3>${NC}" |
| 33 | + echo -e "${YELLOW}Specify either 'v2' or 'v3' to update only that major version${NC}" |
| 34 | + exit 1 |
| 35 | +fi |
| 36 | + |
| 37 | +# Global configuration |
| 38 | +VERSION="$1" # Version to update (v2 or v3) |
| 39 | +PRIMARY_VERSION="v3" # Primary version for go.mod and CLI docs |
| 40 | + |
| 41 | +echo -e "${GREEN}🔄 Starting Helm documentation update process for $VERSION only...${NC}" |
| 42 | + |
| 43 | +# ============================================================================= |
| 44 | +# UTILITY FUNCTIONS |
| 45 | +# ============================================================================= |
| 46 | + |
| 47 | +# Logging functions with timestamps and color coding |
| 48 | +log() { |
| 49 | + echo -e "${GREEN}[$(date +'%Y-%m-%d %H:%M:%S')] $1${NC}" |
| 50 | +} |
| 51 | + |
| 52 | +warn() { |
| 53 | + echo -e "${YELLOW}[$(date +'%Y-%m-%d %H:%M:%S')] WARNING: $1${NC}" |
| 54 | +} |
| 55 | + |
| 56 | +error() { |
| 57 | + echo -e "${RED}[$(date +'%Y-%m-%d %H:%M:%S')] ERROR: $1${NC}" |
| 58 | +} |
| 59 | + |
| 60 | +# Compare semantic versions - returns 0 if $1 > $2 |
| 61 | +version_gt() { |
| 62 | + printf '%s\n%s\n' "$2" "$1" | sort -V -C |
| 63 | +} |
| 64 | + |
| 65 | +# Extract major.minor version from full version string (e.g., v3.15.2 -> 3.15) |
| 66 | +get_major_minor() { |
| 67 | + echo "$1" | sed -E 's/^v([0-9]+\.[0-9]+)\..*$/\1/' |
| 68 | +} |
| 69 | + |
| 70 | +# ============================================================================= |
| 71 | +# DATA RETRIEVAL FUNCTIONS |
| 72 | +# ============================================================================= |
| 73 | + |
| 74 | +# Fetch all stable releases from GitHub API (excludes pre-releases) |
| 75 | +get_latest_releases() { |
| 76 | + log "Fetching latest releases from GitHub API..." |
| 77 | + |
| 78 | + # Get releases and filter out pre-releases |
| 79 | + local api_response |
| 80 | + curl -s "https://api.github.com/repos/helm/helm/releases?per_page=100" | jq -r '.[] | select(.prerelease == false) | .tag_name' |
| 81 | +} |
| 82 | + |
| 83 | +# Get current version for the specified major version from config.toml |
| 84 | +get_current_version() { |
| 85 | + REGEX="version = \"${VERSION}\." |
| 86 | + grep -A 1 "${REGEX}" config.toml | head -1 | sed -E 's/.*version = "([^"]+)".*/\1/' |
| 87 | +} |
| 88 | + |
| 89 | +# Check if we're updating the primary version (which requires additional updates) |
| 90 | +is_primary_version() { |
| 91 | + test "$VERSION" == "${PRIMARY_VERSION}" |
| 92 | +} |
| 93 | + |
| 94 | +# Get current Helm version from go.mod (only relevant for primary version) |
| 95 | +get_current_gomod_version() { |
| 96 | + grep "helm.sh/helm/${PRIMARY_VERSION}" sdkexamples/go.mod | awk '{print $2}' | head -1 |
| 97 | +} |
| 98 | + |
| 99 | +# ============================================================================= |
| 100 | +# UPDATE FUNCTIONS |
| 101 | +# ============================================================================= |
| 102 | + |
| 103 | +# Update version reference in Hugo config.toml with backup and validation |
| 104 | +update_config_version() { |
| 105 | + local old_version="$1" |
| 106 | + local new_version="$2" |
| 107 | + |
| 108 | + log "Updating config.toml $VERSION version from $old_version to $new_version" |
| 109 | + |
| 110 | + # Create a backup |
| 111 | + cp config.toml config.toml.bak |
| 112 | + |
| 113 | + # Update the version in config.toml |
| 114 | + cat config.toml.bak | sed "s/version = \"$old_version\"/version = \"$new_version\"/" >config.toml |
| 115 | + |
| 116 | + # Verify the change |
| 117 | + if grep -q "version = \"$new_version\"" config.toml; then |
| 118 | + log "✅ Successfully updated config.toml" |
| 119 | + rm -f config.toml.bak |
| 120 | + return 0 |
| 121 | + else |
| 122 | + error "Failed to update config.toml" |
| 123 | + mv config.toml.bak config.toml |
| 124 | + return 1 |
| 125 | + fi |
| 126 | +} |
| 127 | + |
| 128 | +# Update Go module dependencies to use the new Helm version (v3 only) |
| 129 | +update_gomod() { |
| 130 | + local new_version="$1" |
| 131 | + |
| 132 | + log "Updating sdkexamples/go.mod to Helm $new_version" |
| 133 | + |
| 134 | + cd sdkexamples |
| 135 | + |
| 136 | + # Update the go.mod file to require the new version |
| 137 | + go mod edit -require="helm.sh/helm/${PRIMARY_VERSION}@$new_version" |
| 138 | + go mod tidy # Clean up dependencies |
| 139 | + |
| 140 | + cd .. |
| 141 | + |
| 142 | + log "✅ Successfully updated go.mod" |
| 143 | +} |
| 144 | + |
| 145 | +# Generate fresh CLI documentation using Docker (v3 only) |
| 146 | +# This uses the get-helm-3 script to install the latest Helm and generate docs |
| 147 | +update_helm_docs() { |
| 148 | + log "Updating Helm CLI documentation..." |
| 149 | + |
| 150 | + # Check if docker is available |
| 151 | + if ! command -v docker &> /dev/null; then |
| 152 | + warn "Docker not available, skipping documentation update" |
| 153 | + return 0 |
| 154 | + fi |
| 155 | + |
| 156 | + # Run the docker command to update docs with better error handling |
| 157 | + if docker run --rm -v "$(pwd):/output" --entrypoint /bin/bash ubuntu:latest -c " |
| 158 | + set -e |
| 159 | + apt-get update -qq && apt-get install -y -qq curl ca-certificates |
| 160 | + curl -fsSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash |
| 161 | + export HOME='~' |
| 162 | + /usr/local/bin/helm docs --type markdown --generate-headers --dir /output/content/en/docs/helm/ || true |
| 163 | + "; then |
| 164 | + log "✅ Successfully updated Helm documentation" |
| 165 | + else |
| 166 | + warn "Failed to update Helm documentation, but continuing with other updates" |
| 167 | + fi |
| 168 | +} |
| 169 | + |
| 170 | +# ============================================================================= |
| 171 | +# MAIN EXECUTION LOGIC |
| 172 | +# ============================================================================= |
| 173 | + |
| 174 | +# Main function that orchestrates the update process |
| 175 | +main() { |
| 176 | + local changes_made=false |
| 177 | + |
| 178 | + local current_version=$(get_current_version) |
| 179 | + local current_gomod=$(get_current_gomod_version) |
| 180 | + |
| 181 | + # Display current state |
| 182 | + log "Current versions:" |
| 183 | + log " $VERSION in config.toml: $current_version" |
| 184 | + if is_primary_version; then |
| 185 | + log " $VERSION in go.mod: $current_gomod" |
| 186 | + fi |
| 187 | + |
| 188 | + # Find the latest stable release for this major version |
| 189 | + local latest_version=$(get_latest_releases | grep "^${VERSION}\." | head -1) |
| 190 | + |
| 191 | + log "Latest releases found:" |
| 192 | + log " ${VERSION}: $latest_version" |
| 193 | + |
| 194 | + # Determine if an update is needed and perform it |
| 195 | + if [ -n "$latest_version" ] && [ "$latest_version" != "$current_version" ]; then |
| 196 | + # Check if this is a new minor release (not just patch) |
| 197 | + local current_minor=$(get_major_minor "$current_version") |
| 198 | + local latest_minor=$(get_major_minor "$latest_version") |
| 199 | + |
| 200 | + # Only update for significant releases (minor bumps or newer patches) |
| 201 | + if [ "$current_minor" != "$latest_minor" ] || version_gt "$latest_version" "$current_version"; then |
| 202 | + log "🔄 New ${VERSION} release detected: $latest_version (current: $current_version)" |
| 203 | + |
| 204 | + # Update the version in config.toml |
| 205 | + if update_config_version "$current_version" "$latest_version"; then |
| 206 | + changes_made=true |
| 207 | + |
| 208 | + # For primary version (v3), also update go.mod and documentation |
| 209 | + if is_primary_version; then |
| 210 | + # Update go.mod dependencies if version differs |
| 211 | + if [ "$latest_version" != "$current_gomod" ]; then |
| 212 | + update_gomod "$latest_version" |
| 213 | + fi |
| 214 | + |
| 215 | + # Regenerate CLI documentation |
| 216 | + update_helm_docs |
| 217 | + fi |
| 218 | + fi |
| 219 | + else |
| 220 | + log "${VERSION} version $latest_version is not a significant update from $current_version" |
| 221 | + fi |
| 222 | + else |
| 223 | + log "No new ${VERSION} releases found or version is already current" |
| 224 | + fi |
| 225 | + |
| 226 | + # Report final status |
| 227 | + if [ "$changes_made" = true ]; then |
| 228 | + log "✅ Documentation update completed with changes for $VERSION" |
| 229 | + exit 0 |
| 230 | + else |
| 231 | + log "ℹ️ No updates needed - $VERSION version is current" |
| 232 | + exit 0 |
| 233 | + fi |
| 234 | +} |
| 235 | + |
| 236 | +# Run main function |
| 237 | +main "$@" |
0 commit comments