Skip to content

Commit 12a72a9

Browse files
committed
fix: enhance GitHub Pages deployment workflow with improved version handling and documentation build steps
1 parent 0286c88 commit 12a72a9

1 file changed

Lines changed: 130 additions & 47 deletions

File tree

.github/workflows/site.yml

Lines changed: 130 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,23 @@ on:
1111
- 'pom.xml'
1212
- '.github/workflows/site.yml'
1313

14-
# Runs on release publish (publishes to / and /vX.Y.Z/)
14+
# Runs on release publish (publishes to /latest/ and /vX.Y.Z/)
1515
release:
1616
types: [published]
1717

1818
# Allows manual trigger
1919
workflow_dispatch:
2020
inputs:
21+
version:
22+
description: 'Specific version/tag to build (leave empty for snapshot from main)'
23+
type: string
24+
default: ''
2125
publish_as_latest:
22-
description: 'Also publish as latest (root path)?'
26+
description: 'Also publish as latest?'
27+
type: boolean
28+
default: false
29+
rebuild_all_versions:
30+
description: 'Rebuild documentation for all release tags?'
2331
type: boolean
2432
default: false
2533

@@ -44,7 +52,6 @@ jobs:
4452
- name: Checkout
4553
uses: actions/checkout@v6
4654
with:
47-
ref: ${{ github.event_name == 'release' && github.event.release.tag_name || github.ref }}
4855
fetch-depth: 0
4956

5057
- name: Set up JDK 17
@@ -53,26 +60,6 @@ jobs:
5360
java-version: '17'
5461
distribution: 'temurin'
5562

56-
- name: Determine version and paths
57-
id: version
58-
run: |
59-
if [[ "${{ github.event_name }}" == "release" ]]; then
60-
VERSION="${{ github.event.release.tag_name }}"
61-
VERSION="${VERSION#v}" # Remove 'v' prefix if present
62-
echo "version=$VERSION" >> $GITHUB_OUTPUT
63-
echo "is_release=true" >> $GITHUB_OUTPUT
64-
echo "deploy_path=$VERSION" >> $GITHUB_OUTPUT
65-
else
66-
# For main branch pushes
67-
CURRENT_VERSION=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout)
68-
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
69-
echo "is_release=false" >> $GITHUB_OUTPUT
70-
echo "deploy_path=snapshot" >> $GITHUB_OUTPUT
71-
fi
72-
73-
- name: Build Maven Site with Javadoc
74-
run: ./mvnw clean site -DskipTests -Dcheckstyle.skip=true
75-
7663
- name: Checkout site branch
7764
uses: actions/checkout@v6
7865
with:
@@ -91,52 +78,138 @@ jobs:
9178
git remote add origin "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git"
9279
fi
9380
94-
- name: Prepare versioned documentation
81+
- name: Get all release tags
82+
id: tags
9583
run: |
96-
DEPLOY_PATH="${{ steps.version.outputs.deploy_path }}"
84+
# Get all tags that look like version numbers (v1.0.0 or 1.0.0)
85+
TAGS=$(git tag -l | grep -E '^v?[0-9]+\.[0-9]+' | sort -Vr)
86+
echo "all_tags<<EOF" >> $GITHUB_OUTPUT
87+
echo "$TAGS" >> $GITHUB_OUTPUT
88+
echo "EOF" >> $GITHUB_OUTPUT
9789
98-
# Remove old version of this specific path (if exists)
99-
rm -rf "site/$DEPLOY_PATH"
90+
# Get the latest tag
91+
LATEST_TAG=$(echo "$TAGS" | head -n 1)
92+
echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT
10093
101-
# Copy new site to versioned path
102-
mkdir -p "site/$DEPLOY_PATH"
103-
cp -r target/site/* "site/$DEPLOY_PATH/"
94+
# Determine what to build
95+
if [[ "${{ github.event_name }}" == "release" ]]; then
96+
echo "build_tag=${{ github.event.release.tag_name }}" >> $GITHUB_OUTPUT
97+
echo "is_release=true" >> $GITHUB_OUTPUT
98+
elif [[ -n "${{ inputs.version }}" ]]; then
99+
# Manual trigger with specific version
100+
VERSION="${{ inputs.version }}"
101+
# Add 'v' prefix if not present for tag lookup
102+
if [[ ! "$VERSION" =~ ^v ]]; then
103+
TAG="v$VERSION"
104+
else
105+
TAG="$VERSION"
106+
fi
107+
echo "build_tag=$TAG" >> $GITHUB_OUTPUT
108+
echo "is_release=true" >> $GITHUB_OUTPUT
109+
else
110+
echo "build_tag=" >> $GITHUB_OUTPUT
111+
echo "is_release=false" >> $GITHUB_OUTPUT
112+
fi
113+
114+
- name: Build snapshot documentation (main branch)
115+
if: steps.tags.outputs.is_release == 'false' && inputs.rebuild_all_versions != true
116+
run: |
117+
./mvnw clean site -DskipTests -Dcheckstyle.skip=true
104118
105-
# For releases, also update the root (latest)
106-
if [[ "${{ steps.version.outputs.is_release }}" == "true" ]] || [[ "${{ inputs.publish_as_latest }}" == "true" ]]; then
107-
# Preserve versioned folders when updating root
108-
find site -maxdepth 1 -type f -delete
109-
find site -maxdepth 1 -type d -name "[0-9]*" -prune -o -type d ! -name site ! -name snapshot ! -name .git -exec rm -rf {} + 2>/dev/null || true
110-
111-
# Copy site to root (latest release)
112-
cp -r target/site/* site/
119+
rm -rf "site/snapshot"
120+
mkdir -p "site/snapshot"
121+
cp -r target/site/* "site/snapshot/"
122+
123+
- name: Build documentation for specific version
124+
if: steps.tags.outputs.is_release == 'true' && inputs.rebuild_all_versions != true
125+
run: |
126+
TAG="${{ steps.tags.outputs.build_tag }}"
127+
VERSION="${TAG#v}" # Remove 'v' prefix
128+
129+
echo "Building documentation for $TAG (version $VERSION)"
130+
git checkout "$TAG"
131+
132+
./mvnw clean site -DskipTests -Dcheckstyle.skip=true
133+
134+
rm -rf "site/$VERSION"
135+
mkdir -p "site/$VERSION"
136+
cp -r target/site/* "site/$VERSION/"
137+
138+
# Update /latest/ if this is a release event or publish_as_latest is true
139+
if [[ "${{ github.event_name }}" == "release" ]] || [[ "${{ inputs.publish_as_latest }}" == "true" ]]; then
140+
rm -rf "site/latest"
141+
mkdir -p "site/latest"
142+
cp -r target/site/* "site/latest/"
113143
fi
114144
115-
# Copy version index page from template
145+
git checkout main
146+
147+
- name: Build documentation for all release tags
148+
if: inputs.rebuild_all_versions == true
149+
run: |
150+
LATEST_TAG="${{ steps.tags.outputs.latest_tag }}"
151+
152+
while IFS= read -r TAG; do
153+
if [[ -z "$TAG" ]]; then continue; fi
154+
155+
VERSION="${TAG#v}" # Remove 'v' prefix
156+
echo "Building documentation for $TAG (version $VERSION)"
157+
158+
git checkout "$TAG"
159+
./mvnw clean site -DskipTests -Dcheckstyle.skip=true
160+
161+
rm -rf "site/$VERSION"
162+
mkdir -p "site/$VERSION"
163+
cp -r target/site/* "site/$VERSION/"
164+
165+
# If this is the latest tag, also update /latest/
166+
if [[ "$TAG" == "$LATEST_TAG" ]]; then
167+
rm -rf "site/latest"
168+
mkdir -p "site/latest"
169+
cp -r target/site/* "site/latest/"
170+
fi
171+
172+
done <<< "${{ steps.tags.outputs.all_tags }}"
173+
174+
# Return to main and build snapshot
175+
git checkout main
176+
./mvnw clean site -DskipTests -Dcheckstyle.skip=true
177+
178+
rm -rf "site/snapshot"
179+
mkdir -p "site/snapshot"
180+
cp -r target/site/* "site/snapshot/"
181+
182+
- name: Copy version index page
183+
run: |
116184
cp .github/templates/versions.html site/versions.html
117185
118-
- name: Update version list
186+
- name: Update version list from git tags
119187
run: |
120188
cd site
121189
122-
# Find all version directories
123-
VERSIONS=$(find . -maxdepth 1 -type d -name "[0-9]*" | sed 's|./||' | sort -Vr)
190+
# Get versions from git tags (already sorted by version, descending)
191+
VERSIONS=$(git -C .. tag -l | grep -E '^v?[0-9]+\.[0-9]+' | sed 's/^v//' | sort -Vr)
124192
HAS_SNAPSHOT=$([ -d "snapshot" ] && echo "true" || echo "false")
193+
HAS_LATEST=$([ -d "latest" ] && echo "true" || echo "false")
125194
126195
# Generate version links
127196
VERSION_HTML=""
128197
129-
# Add latest (root) link
130-
VERSION_HTML+='<li><a href="./">Latest Release</a><span class="badge latest">latest</span></li>'
198+
# Add latest link if exists
199+
if [ "$HAS_LATEST" = "true" ]; then
200+
VERSION_HTML+='<li><a href="./latest/">Latest Release</a><span class="badge latest">latest</span></li>'
201+
fi
131202
132203
# Add snapshot if exists
133204
if [ "$HAS_SNAPSHOT" = "true" ]; then
134205
VERSION_HTML+='<li><a href="./snapshot/">Development (main branch)</a><span class="badge snapshot">snapshot</span></li>'
135206
fi
136207
137-
# Add versioned releases
208+
# Add versioned releases from tags
138209
for v in $VERSIONS; do
139-
VERSION_HTML+="<li><a href=\"./$v/\">Version $v</a><span class=\"badge archived\">$v</span></li>"
210+
if [ -d "$v" ]; then
211+
VERSION_HTML+="<li><a href=\"./$v/\">Version $v</a><span class=\"badge archived\">$v</span></li>"
212+
fi
140213
done
141214
142215
# Update the versions.html using the placeholder
@@ -153,7 +226,17 @@ jobs:
153226
git remote add origin "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git"
154227
155228
git add -A
156-
git diff --staged --quiet || git commit -m "Deploy documentation: ${{ steps.version.outputs.deploy_path }}"
229+
230+
# Create descriptive commit message
231+
if [[ "${{ inputs.rebuild_all_versions }}" == "true" ]]; then
232+
COMMIT_MSG="Rebuild documentation for all versions"
233+
elif [[ "${{ steps.tags.outputs.is_release }}" == "true" ]]; then
234+
COMMIT_MSG="Deploy documentation: ${{ steps.tags.outputs.build_tag }}"
235+
else
236+
COMMIT_MSG="Deploy documentation: snapshot"
237+
fi
238+
239+
git diff --staged --quiet || git commit -m "$COMMIT_MSG"
157240
158241
# Push, creating the branch if it doesn't exist
159242
git push -u origin site --force

0 commit comments

Comments
 (0)