Skip to content

Commit eeff598

Browse files
Add script and workflow step to automate example version updates
Co-authored-by: thomasturrell <1552612+thomasturrell@users.noreply.github.com>
1 parent 9b15564 commit eeff598

2 files changed

Lines changed: 120 additions & 0 deletions

File tree

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/bin/bash
2+
3+
# Copyright 2016-2025 Berry Cloud Ltd. All rights reserved.
4+
5+
set -euo pipefail
6+
7+
# Script to update version numbers in documentation examples
8+
# This script is called during the release process to ensure documentation
9+
# examples always reference the current release version
10+
11+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
12+
REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
13+
14+
# Function to extract version from pom.xml
15+
get_version_from_pom() {
16+
local pom_file="$1"
17+
18+
# Extract version from the project section (not parent)
19+
# Use xmllint if available, otherwise use grep/sed
20+
if command -v xmllint &> /dev/null; then
21+
xmllint --xpath '//*[local-name()="project"]/*[local-name()="version"]/text()' "$pom_file" 2>/dev/null | head -1
22+
else
23+
# Fallback to grep/sed approach
24+
grep -m 1 "^ <version>" "$pom_file" | sed 's/.*<version>\(.*\)<\/version>.*/\1/'
25+
fi
26+
}
27+
28+
# Main script
29+
main() {
30+
cd "$REPO_ROOT"
31+
32+
echo "Updating example version numbers in documentation..."
33+
34+
# Get the current version from the root pom.xml
35+
CURRENT_VERSION=$(get_version_from_pom "pom.xml")
36+
37+
if [ -z "$CURRENT_VERSION" ]; then
38+
echo "ERROR: Could not extract version from pom.xml"
39+
exit 1
40+
fi
41+
42+
echo "Current version: $CURRENT_VERSION"
43+
44+
# Strip -SNAPSHOT suffix if present (we want the release version)
45+
RELEASE_VERSION="${CURRENT_VERSION%-SNAPSHOT}"
46+
47+
echo "Updating documentation to use version: $RELEASE_VERSION"
48+
49+
# Files to update
50+
FILES_TO_UPDATE=(
51+
"README.md"
52+
)
53+
54+
# Update version numbers in all specified files
55+
for file in "${FILES_TO_UPDATE[@]}"; do
56+
if [ ! -f "$file" ]; then
57+
echo "WARNING: File not found: $file"
58+
continue
59+
fi
60+
61+
echo "Updating $file..."
62+
63+
# Create a backup
64+
cp "$file" "$file.bak"
65+
66+
# Replace version numbers in Maven dependency examples
67+
# Pattern: <version>X.Y.Z</version> where X.Y.Z is a version number
68+
# Only replace in dependency blocks (between <dependency> and </dependency>)
69+
sed -i.tmp '/<dependency>/,/<\/dependency>/ s/<version>[0-9]\+\.[0-9]\+\.[0-9]\+<\/version>/<version>'"$RELEASE_VERSION"'<\/version>/g' "$file"
70+
71+
# Clean up temporary file
72+
rm -f "$file.tmp"
73+
74+
# Check if file was modified
75+
if ! diff -q "$file" "$file.bak" > /dev/null 2>&1; then
76+
echo "✓ Updated $file"
77+
rm "$file.bak"
78+
else
79+
echo "- No changes needed in $file"
80+
mv "$file.bak" "$file"
81+
fi
82+
done
83+
84+
echo ""
85+
echo "Example version update complete!"
86+
echo "Version updated to: $RELEASE_VERSION"
87+
echo ""
88+
echo "Modified files:"
89+
git --no-pager diff --name-only
90+
echo ""
91+
echo "Summary of changes:"
92+
git --no-pager diff --stat
93+
}
94+
95+
# Run main function
96+
main "$@"

.github/workflows/manual-release.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,30 @@ jobs:
184184
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
185185
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
186186

187+
- name: Update example version numbers in documentation
188+
run: |
189+
echo "Updating example version numbers in documentation..."
190+
191+
# Run the script to update version numbers in README.md and other docs
192+
bash .github/scripts/update-example-versions.sh
193+
194+
# Check if there are any changes
195+
if git diff --quiet; then
196+
echo "No version updates needed"
197+
else
198+
echo "Documentation examples updated with release version"
199+
200+
# Amend the release commit created by release:prepare to include doc updates
201+
git add README.md
202+
git commit --amend --no-edit
203+
204+
# Update the tag to point to the amended commit
205+
TAG_NAME="${{ steps.release.outputs.tag_name }}"
206+
git tag -f "$TAG_NAME"
207+
208+
echo "✅ Release commit amended with documentation updates"
209+
fi
210+
187211
- name: Run Maven release:perform
188212
run: |
189213
echo "Performing release and deploying to Maven Central"

0 commit comments

Comments
 (0)