|
10 | 10 | tag_ref: |
11 | 11 | description: 'Existing Git Tag to deploy (e.g., 1.0.0):' |
12 | 12 | required: true |
13 | | - # Default can be left blank or set to a placeholder |
14 | | - default: '99.0.0' # unlikely to conflict if accidentally used. |
| 13 | + default: '99.0.0' # unlikely to conflict if accidentally used. Can be left blank |
15 | 14 |
|
16 | 15 | jobs: |
17 | 16 | build-and-deploy-javadoc: |
18 | 17 | runs-on: ubuntu-latest |
19 | 18 | permissions: |
20 | 19 | contents: write |
21 | 20 |
|
22 | | - steps: |
23 | | - - name: Checkout Code at Specified Tag |
24 | | - uses: actions/checkout@v5 |
25 | | - with: |
26 | | - ref: ${{ github.event.inputs.tag_ref }} # from manual trigger input |
27 | | - fetch-depth: 0 |
| 21 | + steps: |
| 22 | + - name: Checkout Code at Specified Tag |
| 23 | + uses: actions/checkout@v5 |
| 24 | + with: |
| 25 | + ref: ${{ github.event.inputs.tag_ref }} # from manual trigger input |
| 26 | + fetch-depth: 0 |
28 | 27 |
|
29 | | - - name: Set up JDK |
30 | | - uses: actions/setup-java@v4 |
31 | | - with: |
32 | | - java-version: '25' |
33 | | - distribution: 'temurin' |
34 | | - cache: 'maven' |
| 28 | + - name: Set up JDK |
| 29 | + uses: actions/setup-java@v4 |
| 30 | + with: |
| 31 | + java-version: '25' |
| 32 | + distribution: 'temurin' |
| 33 | + cache: 'maven' |
35 | 34 |
|
36 | | - - name: Build and Generate Javadoc |
37 | | - # POM is configured to output to target/site/apidocs |
38 | | - run: mvn javadoc:javadoc |
| 35 | + - name: Build and Generate Javadoc # POM is configured to output to target/site/apidocs |
| 36 | + run: mvn javadoc:javadoc |
39 | 37 |
|
40 | | - - name: Deploy Javadoc via Worktree |
41 | | - env: |
42 | | - TAG_NAME: ${{ github.event.inputs.tag_ref }} |
| 38 | + - name: Deploy Javadoc via Worktree |
| 39 | + env: |
| 40 | + TAG_NAME: ${{ github.event.inputs.tag_ref }} |
| 41 | + run: | |
| 42 | + # 1. Initialize error tracking |
| 43 | + EXIT_CODE=0 |
| 44 | + |
| 45 | + # 2. Configure Git Identity |
| 46 | + git config user.email "noreply@github.com" |
| 47 | + git config user.name "github-actions[bot]" |
| 48 | + |
| 49 | + # 3. Ensure gh-pages exists and is fetched |
| 50 | + git fetch origin gh-pages --depth=1 || git branch gh-pages |
| 51 | + |
| 52 | + # 4. Create worktree for the gh-pages branch in a separate folder |
| 53 | + git worktree add ./gh-pages-dir origin/gh-pages |
| 54 | + |
| 55 | + # 5. Deployment Logic in a subshell to capture exit code |
| 56 | + ( |
| 57 | + set -e # Exit subshell on any internal error |
| 58 | + TARGET_PATH="gh-pages-dir/docs/$TAG_NAME" # target directory inside the worktree |
| 59 | + mkdir -p "$TARGET_PATH" |
| 60 | + cp -a target/site/apidocs/. "$TARGET_PATH/" |
| 61 | + |
| 62 | + cd gh-pages-dir |
| 63 | + git add . |
| 64 | + |
| 65 | + if git diff --staged --quiet; then |
| 66 | + echo "No changes detected for Javadoc $TAG_NAME." |
| 67 | + else |
| 68 | + git commit -m "Manual Javadoc deployment for tag $TAG_NAME" |
| 69 | + git push origin gh-pages |
| 70 | + fi |
| 71 | + ) || EXIT_CODE=$? |
| 72 | + |
| 73 | + # 6. Cleanup (Always runs) |
| 74 | + echo "Cleaning up worktree..." |
| 75 | + git worktree remove --force ./gh-pages-dir || true |
| 76 | + |
| 77 | + # 7. Final exit based on subshell success |
| 78 | + exit $EXIT_CODE |
43 | 79 |
|
44 | | - run: | |
45 | | - # 1. Configure Git Identity |
46 | | - git config user.email "noreply@github.com" |
47 | | - git config user.name "github-actions[bot]" |
48 | | - |
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 . |
66 | | - |
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 |
74 | | - |
75 | | - # 7. Cleanup the worktree |
76 | | - cd .. |
77 | | - git worktree remove ./gh-pages-dir |
| 80 | + - name: Confirm Deployment |
| 81 | + if: success() |
| 82 | + run: echo "Javadoc for ${{ github.event.inputs.tag_ref }} is now live on gh-pages." |
78 | 83 |
|
0 commit comments