diff --git a/.github/workflows/javadoc.yml b/.github/workflows/javadoc.yml index 401cda867..070543273 100644 --- a/.github/workflows/javadoc.yml +++ b/.github/workflows/javadoc.yml @@ -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: @@ -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 @@ -47,31 +50,42 @@ 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 @@ -79,4 +93,6 @@ jobs: - 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." + diff --git a/tools/ManualJavadocsDeploy.sh b/tools/ManualJavadocsDeploy.sh new file mode 100755 index 000000000..78637ee02 --- /dev/null +++ b/tools/ManualJavadocsDeploy.sh @@ -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 \ No newline at end of file