|
| 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 docusaurus.config.js |
| 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, node (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 docusaurus.config.js |
| 84 | +get_current_version() { |
| 85 | + # Extract the major version number (2 or 3 from v2 or v3) |
| 86 | + local major_version="${VERSION:1}" |
| 87 | + |
| 88 | + # For v2, look for something like: 2: { label: "2.17.0" |
| 89 | + # For v3, look for: 3 something like: { label: "3.19.0" |
| 90 | + # Note: Using [[:space:]] instead of \s for better compatibility |
| 91 | + grep -E "^[[:space:]]*${major_version}:[[:space:]]*\{[[:space:]]*label:[[:space:]]*\"" docusaurus.config.js | \ |
| 92 | + sed -E 's/.*label:[[:space:]]*"([0-9]+\.[0-9]+\.[0-9]+)".*/\1/' |
| 93 | +} |
| 94 | + |
| 95 | +# Check if we're updating the primary version (which requires additional updates) |
| 96 | +is_primary_version() { |
| 97 | + test "$VERSION" == "${PRIMARY_VERSION}" |
| 98 | +} |
| 99 | + |
| 100 | +# Get current Helm version from go.mod (only relevant for primary version) |
| 101 | +get_current_gomod_version() { |
| 102 | + grep "helm.sh/helm/${PRIMARY_VERSION}" sdkexamples/go.mod | awk '{print $2}' | head -1 |
| 103 | +} |
| 104 | + |
| 105 | +# ============================================================================= |
| 106 | +# UPDATE FUNCTIONS |
| 107 | +# ============================================================================= |
| 108 | + |
| 109 | +# Update version reference in docusaurus.config.js with backup and validation |
| 110 | +update_config_version() { |
| 111 | + local old_version="$1" |
| 112 | + local new_version="$2" |
| 113 | + local major_version="${VERSION:1}" |
| 114 | + |
| 115 | + # Strip 'v' prefix from versions if present (GitHub API returns v3.19.0, but config has 3.19.0) |
| 116 | + old_version="${old_version#v}" |
| 117 | + new_version="${new_version#v}" |
| 118 | + |
| 119 | + log "Updating docusaurus.config.js $VERSION version from $old_version to $new_version" |
| 120 | + |
| 121 | + # Create a backup |
| 122 | + cp docusaurus.config.js docusaurus.config.js.bak |
| 123 | + |
| 124 | + # Update the version in docusaurus.config.js |
| 125 | + # This replaces patterns like: 3: { label: "3.19.0" } |
| 126 | + # Note: Using [[:space:]] instead of \s for better compatibility across sed implementations |
| 127 | + cat docusaurus.config.js.bak | sed -E "s/^([[:space:]]*${major_version}:[[:space:]]*\{[[:space:]]*label:[[:space:]]*\")${old_version}(\".*)$/\1${new_version}\2/" > docusaurus.config.js |
| 128 | + |
| 129 | + # Verify the change |
| 130 | + if grep -q "label: \"$new_version\"" docusaurus.config.js; then |
| 131 | + log "✅ Successfully updated docusaurus.config.js" |
| 132 | + rm -f docusaurus.config.js.bak |
| 133 | + return 0 |
| 134 | + else |
| 135 | + error "Failed to update docusaurus.config.js" |
| 136 | + mv docusaurus.config.js.bak docusaurus.config.js |
| 137 | + return 1 |
| 138 | + fi |
| 139 | +} |
| 140 | + |
| 141 | +# Update Go module dependencies to use the new Helm version (v3 only) |
| 142 | +update_gomod() { |
| 143 | + local new_version="$1" |
| 144 | + |
| 145 | + log "Updating sdkexamples/go.mod to Helm $new_version" |
| 146 | + |
| 147 | + cd sdkexamples |
| 148 | + |
| 149 | + # Update the go.mod file to require the new version |
| 150 | + go mod edit -require="helm.sh/helm/${PRIMARY_VERSION}@$new_version" |
| 151 | + go mod tidy # Clean up dependencies |
| 152 | + |
| 153 | + cd .. |
| 154 | + |
| 155 | + log "✅ Successfully updated go.mod" |
| 156 | +} |
| 157 | + |
| 158 | +# Generate fresh CLI documentation using regenerate-cli-docs.mjs (v3 only) |
| 159 | +update_helm_docs() { |
| 160 | + local new_version="$1" |
| 161 | + |
| 162 | + log "Updating Helm CLI documentation..." |
| 163 | + |
| 164 | + # Check if node is available |
| 165 | + if ! command -v node &> /dev/null; then |
| 166 | + warn "Node.js not available, skipping documentation update" |
| 167 | + return 0 |
| 168 | + fi |
| 169 | + |
| 170 | + # Determine the target directory based on version |
| 171 | + local target_dir="versioned_docs/version-${VERSION:1}" |
| 172 | + |
| 173 | + # Run the regenerate-cli-docs.mjs script |
| 174 | + if node scripts/regenerate-cli-docs.mjs "$new_version" "$target_dir"; then |
| 175 | + log "✅ Successfully updated Helm documentation" |
| 176 | + else |
| 177 | + warn "Failed to update Helm documentation, but continuing with other updates" |
| 178 | + fi |
| 179 | +} |
| 180 | + |
| 181 | +# ============================================================================= |
| 182 | +# MAIN EXECUTION LOGIC |
| 183 | +# ============================================================================= |
| 184 | + |
| 185 | +# Main function that orchestrates the update process |
| 186 | +main() { |
| 187 | + local changes_made=false |
| 188 | + |
| 189 | + local current_version=$(get_current_version) |
| 190 | + local current_gomod=$(get_current_gomod_version) |
| 191 | + |
| 192 | + # Display current state |
| 193 | + log "Current versions:" |
| 194 | + log " $VERSION in docusaurus.config.js: $current_version" |
| 195 | + if is_primary_version; then |
| 196 | + log " $VERSION in go.mod: $current_gomod" |
| 197 | + fi |
| 198 | + |
| 199 | + # Find the latest stable release for this major version |
| 200 | + local latest_version=$(get_latest_releases | grep "^${VERSION}\." | head -1) |
| 201 | + |
| 202 | + log "Latest releases found:" |
| 203 | + log " ${VERSION}: $latest_version" |
| 204 | + |
| 205 | + # Determine if an update is needed and perform it |
| 206 | + if [ -n "$latest_version" ] && [ "$latest_version" != "$current_version" ]; then |
| 207 | + # Check if this is a new minor release (not just patch) |
| 208 | + local current_minor=$(get_major_minor "$current_version") |
| 209 | + local latest_minor=$(get_major_minor "$latest_version") |
| 210 | + |
| 211 | + # Only update for significant releases (minor bumps or newer patches) |
| 212 | + if [ "$current_minor" != "$latest_minor" ] || version_gt "$latest_version" "$current_version"; then |
| 213 | + log "🔄 New ${VERSION} release detected: $latest_version (current: $current_version)" |
| 214 | + |
| 215 | + # Update the version in docusaurus.config.js |
| 216 | + if update_config_version "$current_version" "$latest_version"; then |
| 217 | + changes_made=true |
| 218 | + |
| 219 | + # For primary version (v3), also update go.mod and documentation |
| 220 | + if is_primary_version; then |
| 221 | + # Update go.mod dependencies if version differs |
| 222 | + if [ "$latest_version" != "$current_gomod" ]; then |
| 223 | + update_gomod "$latest_version" |
| 224 | + fi |
| 225 | + |
| 226 | + # Regenerate CLI documentation |
| 227 | + update_helm_docs "$latest_version" |
| 228 | + fi |
| 229 | + fi |
| 230 | + else |
| 231 | + log "${VERSION} version $latest_version is not a significant update from $current_version" |
| 232 | + fi |
| 233 | + else |
| 234 | + log "No new ${VERSION} releases found or version is already current" |
| 235 | + fi |
| 236 | + |
| 237 | + # Report final status |
| 238 | + if [ "$changes_made" = true ]; then |
| 239 | + log "✅ Documentation update completed with changes for $VERSION" |
| 240 | + exit 0 |
| 241 | + else |
| 242 | + log "ℹ️ No updates needed - $VERSION version is current" |
| 243 | + exit 0 |
| 244 | + fi |
| 245 | +} |
| 246 | + |
| 247 | +# Run main function |
| 248 | +main "$@" |
0 commit comments