Skip to content

Commit 439af89

Browse files
authored
Merge pull request #746 from apache/update_javadoc-yml
update javadoc.yml
2 parents c2ea76d + d66b0d3 commit 439af89

1 file changed

Lines changed: 46 additions & 78 deletions

File tree

.github/workflows/javadoc.yml

Lines changed: 46 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,69 @@
1-
name: Deploy Versioned Javadoc (Manual Trigger)
2-
3-
# Select the target TAG where to run the workflow from.
4-
# This TAG name becomes the subdirectory under branch gh-pages/docs/${TAG}
5-
# where the javadocs will be copied to.
6-
# The gh-pages/docs branch/folder must exist.
1+
name: Stage Versioned Javadocs (Manual Trigger)
2+
3+
# This workflow is triggered manually via Workflow Dispatch on GitHub.
4+
# It automatically extracts the project version from the root pom.xml
5+
# of the branch or tag that you trigger this workflow from.
6+
# It compiles and packages the javadocs into a structured ZIP.
7+
#
8+
# To deploy:
9+
# 1. Kick off the workflow on your chosen branch or tag.
10+
# 2. Download the resulting versioned-javadocs-*.zip from the run summary.
11+
# 3. You have 30 days to download before they are deleted from the server.
12+
# 4. Extract it directly into your local gh-pages repository clone and push.
713

814
on:
915
workflow_dispatch:
10-
inputs:
11-
tag_ref:
12-
description: 'Existing Git Tag to deploy (e.g., 1.0.0):'
13-
required: true
14-
default: '99.0.0' # unlikely to conflict if accidentally used. Can be left blank
1516

1617
jobs:
17-
build-and-deploy-javadoc:
18+
build-and-package-javadoc:
1819
runs-on: ubuntu-latest
1920
permissions:
20-
contents: write
21+
contents: read
2122

2223
steps:
23-
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
24-
uses: actions/checkout@v5
24+
- name: 1. Checkout Current (triggered) Workspace Context
25+
uses: actions/checkout@v7
2526
with:
26-
ref: ${{ github.event.inputs.tag_ref }} # from manual trigger input
27+
ref: ${{ github.ref }}
2728
fetch-depth: 0
2829

29-
- name: Set up JDK
30-
uses: actions/setup-java@v4
30+
- name: 2. Provision JDK 25 Runtime
31+
uses: actions/setup-java@v5
3132
with:
3233
java-version: '25'
3334
distribution: 'temurin'
3435
java-package: jdk
3536
architecture: x64
3637
cache: 'maven'
37-
overwrite-settings: true # ensures the runner's .m2/settings.xml is current
38-
39-
- name: Build and Generate Javadoc # POM is configured to output to target/site/apidocs
40-
run: mvn clean javadoc:javadoc
4138

42-
- name: Deploy Javadoc via Worktree
43-
env:
44-
TAG_NAME: ${{ github.event.inputs.tag_ref }}
39+
- name: 3. Extract POM Project Version
40+
id: get-version
41+
shell: bash
4542
run: |
46-
if [ -z "$TAG_NAME" ]; then echo "ERROR: No tag specified"; exit 1; fi
47-
48-
# 1. Initialize error tracking
49-
EXIT_CODE=0
50-
51-
# 2. Configure Git Identity
52-
git config user.email "noreply@github.com"
53-
git config user.name "github-actions[bot]"
54-
55-
# 3. Ensure gh-pages exists and is fetched
56-
echo "ECHO: git fetch origin gh-pages"
57-
git fetch origin gh-pages
58-
59-
# 4. Create worktree for the gh-pages branch in a separate folder
60-
echo "ECHO: git worktree add -B gh-pages ./gh-pages-dir origin/gh-pages"
61-
git worktree add -B gh-pages ./gh-pages-dir origin/gh-pages
62-
63-
# 5. Deployment Logic in a subshell to capture exit code
64-
(
65-
set -e
66-
TARGET_PATH="gh-pages-dir/docs/$TAG_NAME"
67-
mkdir -p "$TARGET_PATH"
68-
69-
echo "ECHO: cp -a target/site/apidocs/. $TARGET_PATH/"
70-
cp -a target/site/apidocs/. "$TARGET_PATH/"
71-
cd gh-pages-dir
43+
POM_VERSION=$(mvn help:evaluate -B -Dexpression=project.version -q -DforceStdout)
44+
echo "Discovered Project Version: $POM_VERSION"
45+
echo "POM_VERSION=$POM_VERSION" >> $GITHUB_ENV
7246
73-
echo "ECHO: git pull origin gh-pages --rebase"
74-
git pull origin gh-pages --rebase
75-
76-
echo "git add docs/$TAG_NAME"
77-
git add "docs/$TAG_NAME"
78-
79-
if git diff --staged --quiet; then
80-
echo "No changes detected for Javadoc $TAG_NAME."
81-
else
82-
echo "ECHO: Changes detected for Javadoc $TAG_NAME."
83-
echo "ECHO: git commit ..."
84-
git commit -m "Manual Javadoc deployment for tag $TAG_NAME"
85-
echo "ECHO: git push origin gh-pages"
86-
git push origin gh-pages
87-
fi
88-
) || EXIT_CODE=$?
89-
90-
# 6. Cleanup (Always runs)
91-
echo "ECHO: Cleaning up worktree..."
92-
git worktree remove --force ./gh-pages-dir || true
93-
94-
# 7. Final exit based on subshell success
95-
exit $EXIT_CODE
96-
97-
- name: Confirm Deployment
98-
if: success()
47+
- name: 4. Compile and Generate Javadoc
48+
shell: bash
9949
run: |
100-
echo "ECHO: Javadoc for ${{ github.event.inputs.tag_ref }} is now live on gh-pages."
50+
echo "Generating Javadoc..."
51+
mvn clean compile javadoc:javadoc -B
10152
53+
- name: 5. Stage Artifacts for Review
54+
shell: bash
55+
run: |
56+
STAGE_DIR="javadoc-staging/docs/${{ env.POM_VERSION }}"
57+
echo "Creating staging directory for version ${{ env.POM_VERSION }}..."
58+
mkdir -p "${STAGE_DIR}"
59+
60+
echo "Copying generated HTML assets into staging..."
61+
cp -r target/site/apidocs/* "${STAGE_DIR}/"
62+
63+
- name: 6. Upload Generated Javadocs as Workflow Zip Artifact
64+
uses: actions/upload-artifact@v7
65+
with:
66+
name: versioned-javadocs-${{ env.POM_VERSION }}
67+
path: javadoc-staging/
68+
retention-days: 30
69+
s

0 commit comments

Comments
 (0)