Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions .github/workflows/javadoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Deploy Versioned Javadoc (Manual Trigger)
# Select the target TAG where to run the workflow from.
# This TAG name becomes the subdirectory under branch gh-pages/docs/${TAG}
# where the javadocs will be copied to.
# The gh-pages/docs branch/folder must exist.

on:
workflow_dispatch:
Expand Down Expand Up @@ -33,12 +34,14 @@ jobs:
cache: 'maven'

- name: Build and Generate Javadoc # POM is configured to output to target/site/apidocs
run: mvn javadoc:javadoc
run: mvn clean javadoc:javadoc

- name: Deploy Javadoc via Worktree
env:
TAG_NAME: ${{ github.event.inputs.tag_ref }}
run: |
if [ -z "$TAG_NAME" ]; then echo "ERROR: No tag specified"; exit 1; fi

# 1. Initialize error tracking
EXIT_CODE=0

Expand All @@ -47,36 +50,49 @@ jobs:
git config user.name "github-actions[bot]"

# 3. Ensure gh-pages exists and is fetched
git fetch origin gh-pages --depth=1 || git branch gh-pages
echo "ECHO: git fetch origin gh-pages"
git fetch origin gh-pages

# 4. Create worktree for the gh-pages branch in a separate folder
git worktree add ./gh-pages-dir origin/gh-pages
echo "ECHO: git worktree add -B gh-pages ./gh-pages-dir origin/gh-pages"
git worktree add -B gh-pages ./gh-pages-dir origin/gh-pages

# 5. Deployment Logic in a subshell to capture exit code
(
set -e # Exit subshell on any internal error
TARGET_PATH="gh-pages-dir/docs/$TAG_NAME" # target directory inside the worktree
set -e
TARGET_PATH="gh-pages-dir/docs/$TAG_NAME"
mkdir -p "$TARGET_PATH"
cp -a target/site/apidocs/. "$TARGET_PATH/"

echo "ECHO: cp -a target/site/apidocs/. $TARGET_PATH/"
cp -a target/site/apidocs/. "$TARGET_PATH/"
cd gh-pages-dir
git add .

echo "ECHO: git pull origin gh-pages --rebase"
git pull origin gh-pages --rebase

echo "git add docs/$TAG_NAME"
git add "docs/$TAG_NAME"

if git diff --staged --quiet; then
echo "No changes detected for Javadoc $TAG_NAME."
else
echo "ECHO: Changes detected for Javadoc $TAG_NAME."
echo "ECHO: git commit ..."
git commit -m "Manual Javadoc deployment for tag $TAG_NAME"
echo "ECHO: git push origin gh-pages"
git push origin gh-pages
fi
) || EXIT_CODE=$?

# 6. Cleanup (Always runs)
echo "Cleaning up worktree..."
echo "ECHO: Cleaning up worktree..."
git worktree remove --force ./gh-pages-dir || true

# 7. Final exit based on subshell success
exit $EXIT_CODE

- name: Confirm Deployment
if: success()
run: echo "Javadoc for ${{ github.event.inputs.tag_ref }} is now live on gh-pages."
run: |
echo "ECHO: Javadoc for ${{ github.event.inputs.tag_ref }} is now live on gh-pages."

54 changes: 54 additions & 0 deletions tools/ManualJavadocsDeploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash
set -e

TAG_NAME="test"
# Build and Generate Javadoc
# POM is configured to output to target/site/apidocs
echo "ECHO: mvn clean javadoc:javadoc"
mvn clean javadoc:javadoc

echo "ECHO: git fetch origin gh-pages"
git fetch origin gh-pages

echo "ECHO: Create worktree"
git worktree add -B gh-pages ./gh-pages-dir origin/gh-pages
EXIT_CODE=0
(
set -e
TARGET_PATH="gh-pages-dir/docs/$TAG_NAME"
mkdir -p "$TARGET_PATH"
cp -a target/site/apidocs/. "$TARGET_PATH/"
cd gh-pages-dir

echo "ECHO: git pull origin gh-pages --rebase"
git pull origin gh-pages --rebase

echo "ECHO: git add docs/$TAG_NAME"
git add "docs/$TAG_NAME"

if git diff --staged --quiet; then
echo "ECHO: No changes detected for Javadoc $TAG_NAME."
else
echo "ECHO: Changes detected for Javadoc $TAG_NAME."
echo "ECHO: git status:"
git status
echo "ECHO: git commit ..."
git commit -m "Manual Javadoc deployment for tag $TAG_NAME"
echo "ECHO: git push origin gh-pages"
git push origin gh-pages
fi
) || EXIT_CODE=$?

# Cleanup
echo "ECHO: Cleaning up worktree..."
git worktree remove --force ./gh-pages-dir || true

# Check the exit code and report success or failure
if [ $EXIT_CODE -eq 0 ]; then
echo "ECHO: Javadoc for $TAG_NAME is now live on gh-pages."
else
echo "ECHO: Javadoc deployment failed for $TAG_NAME."
fi

# Final exit
exit $EXIT_CODE
Loading