Skip to content

Commit 4dd5136

Browse files
authored
Merge pull request #710 from apache/fix_javadoc_yml_2
Fix javadoc yml 2
2 parents 7df51fb + ecb1c27 commit 4dd5136

File tree

2 files changed

+79
-9
lines changed

2 files changed

+79
-9
lines changed

.github/workflows/javadoc.yml

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Deploy Versioned Javadoc (Manual Trigger)
33
# Select the target TAG where to run the workflow from.
44
# This TAG name becomes the subdirectory under branch gh-pages/docs/${TAG}
55
# where the javadocs will be copied to.
6+
# The gh-pages/docs branch/folder must exist.
67

78
on:
89
workflow_dispatch:
@@ -33,12 +34,14 @@ jobs:
3334
cache: 'maven'
3435

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

3839
- name: Deploy Javadoc via Worktree
3940
env:
4041
TAG_NAME: ${{ github.event.inputs.tag_ref }}
4142
run: |
43+
if [ -z "$TAG_NAME" ]; then echo "ERROR: No tag specified"; exit 1; fi
44+
4245
# 1. Initialize error tracking
4346
EXIT_CODE=0
4447
@@ -47,36 +50,49 @@ jobs:
4750
git config user.name "github-actions[bot]"
4851
4952
# 3. Ensure gh-pages exists and is fetched
50-
git fetch origin gh-pages --depth=1 || git branch gh-pages
53+
echo "ECHO: git fetch origin gh-pages"
54+
git fetch origin gh-pages
5155
5256
# 4. Create worktree for the gh-pages branch in a separate folder
53-
git worktree add ./gh-pages-dir origin/gh-pages
57+
echo "ECHO: git worktree add -B gh-pages ./gh-pages-dir origin/gh-pages"
58+
git worktree add -B gh-pages ./gh-pages-dir origin/gh-pages
5459
5560
# 5. Deployment Logic in a subshell to capture exit code
5661
(
57-
set -e # Exit subshell on any internal error
58-
TARGET_PATH="gh-pages-dir/docs/$TAG_NAME" # target directory inside the worktree
62+
set -e
63+
TARGET_PATH="gh-pages-dir/docs/$TAG_NAME"
5964
mkdir -p "$TARGET_PATH"
60-
cp -a target/site/apidocs/. "$TARGET_PATH/"
6165
66+
echo "ECHO: cp -a target/site/apidocs/. $TARGET_PATH/"
67+
cp -a target/site/apidocs/. "$TARGET_PATH/"
6268
cd gh-pages-dir
63-
git add .
69+
70+
echo "ECHO: git pull origin gh-pages --rebase"
71+
git pull origin gh-pages --rebase
72+
73+
echo "git add docs/$TAG_NAME"
74+
git add "docs/$TAG_NAME"
6475
6576
if git diff --staged --quiet; then
6677
echo "No changes detected for Javadoc $TAG_NAME."
6778
else
79+
echo "ECHO: Changes detected for Javadoc $TAG_NAME."
80+
echo "ECHO: git commit ..."
6881
git commit -m "Manual Javadoc deployment for tag $TAG_NAME"
82+
echo "ECHO: git push origin gh-pages"
6983
git push origin gh-pages
7084
fi
7185
) || EXIT_CODE=$?
7286
7387
# 6. Cleanup (Always runs)
74-
echo "Cleaning up worktree..."
88+
echo "ECHO: Cleaning up worktree..."
7589
git worktree remove --force ./gh-pages-dir || true
7690
7791
# 7. Final exit based on subshell success
7892
exit $EXIT_CODE
7993
8094
- name: Confirm Deployment
8195
if: success()
82-
run: echo "Javadoc for ${{ github.event.inputs.tag_ref }} is now live on gh-pages."
96+
run: |
97+
echo "ECHO: Javadoc for ${{ github.event.inputs.tag_ref }} is now live on gh-pages."
98+

tools/ManualJavadocsDeploy.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/bash
2+
set -e
3+
4+
TAG_NAME="test"
5+
# Build and Generate Javadoc
6+
# POM is configured to output to target/site/apidocs
7+
echo "ECHO: mvn clean javadoc:javadoc"
8+
mvn clean javadoc:javadoc
9+
10+
echo "ECHO: git fetch origin gh-pages"
11+
git fetch origin gh-pages
12+
13+
echo "ECHO: Create worktree"
14+
git worktree add -B gh-pages ./gh-pages-dir origin/gh-pages
15+
EXIT_CODE=0
16+
(
17+
set -e
18+
TARGET_PATH="gh-pages-dir/docs/$TAG_NAME"
19+
mkdir -p "$TARGET_PATH"
20+
cp -a target/site/apidocs/. "$TARGET_PATH/"
21+
cd gh-pages-dir
22+
23+
echo "ECHO: git pull origin gh-pages --rebase"
24+
git pull origin gh-pages --rebase
25+
26+
echo "ECHO: git add docs/$TAG_NAME"
27+
git add "docs/$TAG_NAME"
28+
29+
if git diff --staged --quiet; then
30+
echo "ECHO: No changes detected for Javadoc $TAG_NAME."
31+
else
32+
echo "ECHO: Changes detected for Javadoc $TAG_NAME."
33+
echo "ECHO: git status:"
34+
git status
35+
echo "ECHO: git commit ..."
36+
git commit -m "Manual Javadoc deployment for tag $TAG_NAME"
37+
echo "ECHO: git push origin gh-pages"
38+
git push origin gh-pages
39+
fi
40+
) || EXIT_CODE=$?
41+
42+
# Cleanup
43+
echo "ECHO: Cleaning up worktree..."
44+
git worktree remove --force ./gh-pages-dir || true
45+
46+
# Check the exit code and report success or failure
47+
if [ $EXIT_CODE -eq 0 ]; then
48+
echo "ECHO: Javadoc for $TAG_NAME is now live on gh-pages."
49+
else
50+
echo "ECHO: Javadoc deployment failed for $TAG_NAME."
51+
fi
52+
53+
# Final exit
54+
exit $EXIT_CODE

0 commit comments

Comments
 (0)