11#! /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+ #
222set -euo pipefail
323
424# Colors for output
@@ -7,18 +27,24 @@ GREEN='\033[0;32m'
727YELLOW=' \033[1;33m'
828NC=' \033[0m' # No Color
929
10- # Check for required parameter
30+ # Validate command line arguments
1131if [ $# -ne 1 ] || { [ " $1 " != " v2" ] && [ " $1 " != " v3" ]; }; then
1232 echo -e " ${RED} Usage: $0 <v2|v3>${NC} "
1333 echo -e " ${YELLOW} Specify either 'v2' or 'v3' to update only that major version${NC} "
1434 exit 1
1535fi
16- VERSION=" $1 "
17- PRIMARY_VERSION=" v3"
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
1840
1941echo -e " ${GREEN} 🔄 Starting Helm documentation update process for $VERSION only...${NC} "
2042
21- # Function to log messages
43+ # =============================================================================
44+ # UTILITY FUNCTIONS
45+ # =============================================================================
46+
47+ # Logging functions with timestamps and color coding
2248log () {
2349 echo -e " ${GREEN} [$( date +' %Y-%m-%d %H:%M:%S' ) ] $1 ${NC} "
2450}
@@ -31,18 +57,21 @@ error() {
3157 echo -e " ${RED} [$( date +' %Y-%m-%d %H:%M:%S' ) ] ERROR: $1 ${NC} "
3258}
3359
34- # Function to compare semantic versions
60+ # Compare semantic versions - returns 0 if $1 > $2
3561version_gt () {
36- # Returns true if $1 > $2
3762 printf ' %s\n%s\n' " $2 " " $1 " | sort -V -C
3863}
3964
40- # Function to extract major.minor from version
65+ # Extract major.minor version from full version string (e.g., v3.15.2 -> 3.15)
4166get_major_minor () {
4267 echo " $1 " | sed -E ' s/^v([0-9]+\.[0-9]+)\..*$/\1/'
4368}
4469
45- # Function to get latest releases from GitHub API
70+ # =============================================================================
71+ # DATA RETRIEVAL FUNCTIONS
72+ # =============================================================================
73+
74+ # Fetch all stable releases from GitHub API (excludes pre-releases)
4675get_latest_releases () {
4776 log " Fetching latest releases from GitHub API..."
4877
@@ -51,23 +80,27 @@ get_latest_releases() {
5180 curl -s " https://api.github.com/repos/helm/helm/releases?per_page=100" | jq -r ' .[] | select(.prerelease == false) | .tag_name'
5281}
5382
54- # Function to get current versions from config.toml
83+ # Get current version for the specified major version from config.toml
5584get_current_version () {
5685 REGEX=" version = \" ${VERSION} \."
5786 grep -A 1 " ${REGEX} " config.toml | head -1 | sed -E ' s/.*version = "([^"]+)".*/\1/'
5887}
5988
60- # Function to get current Helm version from go.mod
89+ # Check if we're updating the primary version (which requires additional updates)
6190is_primary_version () {
6291 test " $VERSION " == " ${PRIMARY_VERSION} "
6392}
6493
65- # Function to get current Helm version from go.mod
94+ # Get current Helm version from go.mod (only relevant for primary version)
6695get_current_gomod_version () {
6796 grep " helm.sh/helm/${PRIMARY_VERSION} " sdkexamples/go.mod | awk ' {print $2}' | head -1
6897}
6998
70- # Function to update config.toml version
99+ # =============================================================================
100+ # UPDATE FUNCTIONS
101+ # =============================================================================
102+
103+ # Update version reference in Hugo config.toml with backup and validation
71104update_config_version () {
72105 local old_version=" $1 "
73106 local new_version=" $2 "
@@ -76,7 +109,7 @@ update_config_version() {
76109
77110 # Create a backup
78111 cp config.toml config.toml.bak
79-
112+
80113 # Update the version in config.toml
81114 cat config.toml.bak | sed " s/version = \" $old_version \" /version = \" $new_version \" /" > config.toml
82115
@@ -92,24 +125,25 @@ update_config_version() {
92125 fi
93126}
94127
95- # Function to update go.mod
128+ # Update Go module dependencies to use the new Helm version (v3 only)
96129update_gomod () {
97130 local new_version=" $1 "
98131
99132 log " Updating sdkexamples/go.mod to Helm $new_version "
100133
101134 cd sdkexamples
102135
103- # Update the go.mod file
136+ # Update the go.mod file to require the new version
104137 go mod edit -require=" helm.sh/helm/${PRIMARY_VERSION} @$new_version "
105- go mod tidy
138+ go mod tidy # Clean up dependencies
106139
107140 cd ..
108141
109142 log " ✅ Successfully updated go.mod"
110143}
111144
112- # Function to run helm docs command
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
113147update_helm_docs () {
114148 log " Updating Helm CLI documentation..."
115149
@@ -133,53 +167,63 @@ update_helm_docs() {
133167 fi
134168}
135169
136- # Main execution
170+ # =============================================================================
171+ # MAIN EXECUTION LOGIC
172+ # =============================================================================
173+
174+ # Main function that orchestrates the update process
137175main () {
138176 local changes_made=false
139177
140178 local current_version=$( get_current_version)
141179 local current_gomod=$( get_current_gomod_version)
142180
181+ # Display current state
143182 log " Current versions:"
144183 log " $VERSION in config.toml: $current_version "
145- if is_primary_version
146- then
184+ if is_primary_version; then
147185 log " $VERSION in go.mod: $current_gomod "
148186 fi
149187
150- # Find latest release only
188+ # Find the latest stable release for this major version
151189 local latest_version=$( get_latest_releases | grep " ^${VERSION} \." | head -1)
152190
153191 log " Latest releases found:"
154192 log " ${VERSION} : $latest_version "
155193
156- # Check if we need to update version in config.toml
194+ # Determine if an update is needed and perform it
157195 if [ -n " $latest_version " ] && [ " $latest_version " != " $current_version " ]; then
158196 # Check if this is a new minor release (not just patch)
159197 local current_minor=$( get_major_minor " $current_version " )
160198 local latest_minor=$( get_major_minor " $latest_version " )
161199
200+ # Only update for significant releases (minor bumps or newer patches)
162201 if [ " $current_minor " != " $latest_minor " ] || version_gt " $latest_version " " $current_version " ; then
163202 log " 🔄 New ${VERSION} release detected: $latest_version (current: $current_version )"
203+
204+ # Update the version in config.toml
164205 if update_config_version " $current_version " " $latest_version " ; then
165206 changes_made=true
166207
167- if is_primary_version
168- then
169- # Update go.mod if it's different
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
170211 if [ " $latest_version " != " $current_gomod " ]; then
171212 update_gomod " $latest_version "
172213 fi
173214
174- # Update documentation
215+ # Regenerate CLI documentation
175216 update_helm_docs
176217 fi
177218 fi
178219 else
179- log " V3 version $latest_version is not a significant update from $current_version "
220+ log " ${VERSION} version $latest_version is not a significant update from $current_version "
180221 fi
222+ else
223+ log " No new ${VERSION} releases found or version is already current"
181224 fi
182225
226+ # Report final status
183227 if [ " $changes_made " = true ]; then
184228 log " ✅ Documentation update completed with changes for $VERSION "
185229 exit 0
0 commit comments