Skip to content

Commit 98d0400

Browse files
committed
Implement periodic document update job with GitHub Actions workflow
Signed-off-by: Terry Howe <[email protected]>
1 parent 638db6f commit 98d0400

File tree

3 files changed

+368
-0
lines changed

3 files changed

+368
-0
lines changed

.github/workflows/update-docs.yml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: Update Helm Documentation
2+
3+
on:
4+
schedule:
5+
# Run v3 daily at 2am Pacific (9am UTC)
6+
- cron: '0 9 * * *'
7+
# Run v2 daily at 3am Pacific (10am UTC)
8+
- cron: '0 10 * * *'
9+
workflow_dispatch: # Allow manual trigger
10+
inputs:
11+
version:
12+
description: 'Helm version to update (v2 or v3)'
13+
required: true
14+
default: 'v3'
15+
type: choice
16+
options:
17+
- v2
18+
- v3
19+
20+
permissions:
21+
contents: write
22+
pull-requests: write
23+
24+
jobs:
25+
update-docs:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # [email protected]
30+
with:
31+
token: ${{ secrets.GITHUB_TOKEN }}
32+
33+
- name: Setup Go
34+
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # [email protected]
35+
with:
36+
go-version-file: 'sdkexamples/go.mod'
37+
check-latest: true
38+
39+
- name: Install dependencies
40+
run: |
41+
sudo apt-get update
42+
sudo apt-get install -y jq curl
43+
44+
- name: Determine version
45+
id: version
46+
run: |
47+
if [ "${{ github.event_name }}" = "schedule" ]; then
48+
# For scheduled runs, determine version based on time
49+
current_hour=$(date -u +%H)
50+
if [ "$current_hour" = "09" ]; then
51+
echo "version=v3" >> $GITHUB_OUTPUT
52+
elif [ "$current_hour" = "10" ]; then
53+
echo "version=v2" >> $GITHUB_OUTPUT
54+
else
55+
echo "version=v3" >> $GITHUB_OUTPUT # fallback
56+
fi
57+
else
58+
# For manual runs, use the input
59+
echo "version=${{ inputs.version || 'v3' }}" >> $GITHUB_OUTPUT
60+
fi
61+
62+
- name: Run periodic update
63+
run: make update-docs VERSION=${{ steps.version.outputs.version }}
64+
65+
- name: Check for changes
66+
id: changes
67+
run: |
68+
if git diff --quiet; then
69+
echo "has_changes=false" >> $GITHUB_OUTPUT
70+
else
71+
echo "has_changes=true" >> $GITHUB_OUTPUT
72+
fi
73+
74+
- name: Check for existing PRs
75+
id: existing-pr
76+
run: |
77+
existing_pr=$(gh pr list --state open --author "github-actions[bot]" --head-match "update-docs-*" --json number --jq '.[0].number // empty')
78+
if [ -n "$existing_pr" ]; then
79+
echo "existing_pr=true" >> $GITHUB_OUTPUT
80+
echo "Existing PR #$existing_pr found, skipping creation"
81+
else
82+
echo "existing_pr=false" >> $GITHUB_OUTPUT
83+
fi
84+
env:
85+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
86+
87+
- name: Create Pull Request
88+
if: steps.changes.outputs.has_changes == 'true' && steps.existing-pr.outputs.existing_pr == 'false'
89+
uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # [email protected]
90+
with:
91+
token: ${{ secrets.GITHUB_TOKEN }}
92+
commit-message: "chore: update helm documentation for new releases"
93+
title: "chore: update helm documentation for new releases"
94+
body: |
95+
This is an automated pull request to update Helm documentation based on new releases.
96+
97+
## Changes
98+
This PR includes automatic updates for:
99+
- ✅ Version numbers in config.toml
100+
- ✅ Go module dependencies in sdkexamples/go.mod
101+
- ✅ Regenerated CLI documentation (if applicable)
102+
103+
## Details
104+
The update process checked for new Helm releases and updated the documentation accordingly.
105+
Only non-pre-release versions are considered, and updates are made for new minor versions.
106+
107+
Generated by the periodic update workflow at $(date).
108+
109+
## Review Notes
110+
Please verify that:
111+
- [ ] Version numbers are correct
112+
- [ ] Go dependencies are properly updated
113+
- [ ] CLI documentation is current
114+
branch: "update-docs-$(date +%Y%m%d-%H%M%S)"
115+
delete-branch: true

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
SITE_URL := http://localhost:3000
22
BASE_URL := /
3+
VERSION = v3
34

45
clean:
56
rm -rf node_modules/ build/ .docusaurus .cache-loader
@@ -27,6 +28,10 @@ netlify-build: install-if-needed
2728
sdkexamples:
2829
make -C sdkexamples
2930

31+
.PHONY: update-docs
32+
update-docs:
33+
./scripts/update-docs.sh $(VERSION)
34+
3035
serve:
3136
SITE_URL=$(SITE_URL) BASE_URL=$(BASE_URL) yarn run start --host 0.0.0.0
3237

scripts/update-docs.sh

Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
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

Comments
 (0)