Skip to content

Commit cdd039c

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

File tree

3 files changed

+358
-0
lines changed

3 files changed

+358
-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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
VERSION = v3
2+
13
clean:
24
rm -rf app resources
35

@@ -27,6 +29,10 @@ check-links-ci: set-up-link-checker run-link-checker
2729
sdkexamples:
2830
make -C sdkexamples
2931

32+
.PHONY: update-docs
33+
update-docs:
34+
./scripts/update-docs.sh $(VERSION)
35+
3036
serve:
3137
hugo server --buildDrafts --buildFuture --bind 0.0.0.0
3238

scripts/update-docs.sh

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

Comments
 (0)