88 workflow_dispatch :
99 inputs :
1010 tag_ref :
11- description : ' Existing Git Tag to deploy (e.g., 1.0.0)'
11+ description : ' Existing Git Tag to deploy (e.g., 1.0.0): '
1212 required : true
13- default : ' 1.0.0' # Default can be left blank or set to a placeholder
13+ # Default can be left blank or set to a placeholder
14+ default : ' 99.0.0' # unlikely to conflict if accidentally used.
1415
1516jobs :
1617 build-and-deploy-javadoc :
1718 runs-on : ubuntu-latest
1819 permissions :
1920 contents : write
20- pages : write
21- id-token : write
2221
2322 steps :
2423 - name : Checkout Code at Specified Tag
@@ -35,33 +34,45 @@ jobs:
3534 cache : ' maven'
3635
3736 - name : Build and Generate Javadoc
37+ # POM is configured to output to target/site/apidocs
3838 run : mvn javadoc:javadoc
3939
40- - name : Deploy Javadoc to gh-pages/docs/${TAG}
40+ - name : Deploy Javadoc via Worktree
4141 env :
42- GH_PAGES_EMAIL : noreply@github.com
43- GH_PAGES_NAME : github-actions[bot]
44- GIT_TAG_NAME : ${{ github.event.inputs.tag_ref }}
45- TARGET_DIR : docs/${{ github.event.inputs.tag_ref }}
46- run : |
47- # 1. Configure Git user
48- git config user.email "${GH_PAGES_EMAIL}"
49- git config user.name "${GH_PAGES_NAME}"
42+ TAG_NAME : ${{ github.event.inputs.tag_ref }}
5043
51- # 2. Fetch and checkout the existing gh-pages branch
52- git fetch origin gh-pages:gh-pages
53- git checkout gh-pages
44+ run : |
45+ # 1. Configure Git Identity
46+ git config user.email "noreply@github.com"
47+ git config user.name "github-actions[bot]"
5448
55- # 3. Clean up any previous documentation for this tag (optional, but safer)
56- rm -rf $TARGET_DIR
49+ # 2. Ensure gh-pages exists and is fetched
50+ git fetch origin gh-pages --depth=1 || git branch gh-pages
51+
52+ # 3. Create a worktree for the gh-pages branch in a separate folder
53+ # This prevents switching the main directory and losing the 'target' folder
54+ git worktree add ./gh-pages-dir origin/gh-pages
55+
56+ # 4. Prepare the target directory inside the worktree
57+ TARGET_PATH="gh-pages-dir/docs/$TAG_NAME"
58+ mkdir -p $TARGET_PATH
59+
60+ # 5. Copy the generated docs (using . to copy contents, not the folder itself)
61+ cp -a target/site/apidocs/. $TARGET_PATH/
62+
63+ # 6. Commit and Push from the worktree directory
64+ cd gh-pages-dir
65+ git add .
5766
58- # 4. Create the versioned directory structure
59- mkdir -p $TARGET_DIR
67+ # Only commit and push if there are actual changes
68+ if git diff --staged --quiet; then
69+ echo "No changes detected for Javadoc $TAG_NAME."
70+ else
71+ git commit -m "Manual Javadoc deployment for tag $TAG_NAME"
72+ git push origin gh-pages
73+ fi
6074
61- # 5. Copy the generated Javadoc files into the versioned directory
62- cp -r target/reports/apidocs/* $TARGET_DIR/
75+ # 7. Cleanup the worktree
76+ cd ..
77+ git worktree remove ./gh-pages-dir
6378
64- # 6. Add the new directory and files, commit, and push
65- git add $TARGET_DIR
66- git commit -m "Manual Javadoc deployment for tag ${GIT_TAG_NAME} into $TARGET_DIR"
67- git push origin gh-pages
0 commit comments