|
1 | | -name: JavaDoc |
| 1 | +name: JavaDoc Releases |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | | - branches: main |
| 5 | + tags: |
| 6 | + - "*" # Only publish docs for tags |
| 7 | + delete: |
| 8 | + tags: |
| 9 | + - "*" # Auto-remove docs when tags are deleted |
6 | 10 | workflow_dispatch: |
7 | 11 |
|
8 | 12 | permissions: |
9 | 13 | contents: write |
| 14 | + pages: write |
| 15 | + id-token: write |
10 | 16 |
|
11 | 17 | jobs: |
12 | | - javadoc: |
| 18 | + build: |
| 19 | + name: Build JavaDoc |
13 | 20 | runs-on: ubuntu-latest |
14 | 21 |
|
15 | 22 | steps: |
16 | | - - name: Checkout |
| 23 | + - name: Checkout source |
17 | 24 | uses: actions/checkout@v5 |
18 | 25 |
|
19 | | - - name: Setup Java |
| 26 | + - name: Set up JDK |
20 | 27 | uses: actions/setup-java@v5 |
21 | 28 | with: |
22 | | - java-version: '25' |
23 | | - distribution: 'temurin' |
| 29 | + distribution: temurin |
| 30 | + java-version: 25 |
24 | 31 |
|
25 | | - - name: Echo Java Version |
26 | | - run: java -version |
| 32 | + - name: Set up Maven cache |
| 33 | + uses: actions/cache@v4 |
| 34 | + with: |
| 35 | + path: | |
| 36 | + ~/.m2/repository |
| 37 | + key: maven-${{ runner.os }}-${{ hashFiles('**/pom.xml') }} |
| 38 | + restore-keys: | |
| 39 | + maven-${{ runner.os }}- |
| 40 | +
|
| 41 | + - name: Build JavaDoc |
| 42 | + run: mvn -B javadoc:javadoc |
| 43 | + |
| 44 | + # Upload for GitHub Pages preview (this is optional) |
| 45 | + - name: Upload Pages Artifact |
| 46 | + uses: actions/upload-pages-artifact@v4 |
| 47 | + with: |
| 48 | + path: target/site/apidocs |
| 49 | + |
| 50 | + update-gh-pages: |
| 51 | + name: Update gh-pages |
| 52 | + needs: build |
| 53 | + runs-on: ubuntu-latest |
| 54 | + |
| 55 | + if: github.event_name != 'delete' # skip this job on delete events |
| 56 | + |
| 57 | + steps: |
| 58 | + - name: Checkout gh-pages branch |
| 59 | + uses: actions/checkout@v5 |
| 60 | + with: |
| 61 | + ref: gh-pages |
| 62 | + path: gh-pages |
| 63 | + |
| 64 | + - name: Copy Javadoc into versioned folder |
| 65 | + run: | |
| 66 | + TAG="${GITHUB_REF_NAME}" |
| 67 | + VERSION_DIR="docs/${TAG}" |
| 68 | +
|
| 69 | + rm -rf "gh-pages/${VERSION_DIR}" |
| 70 | + mkdir -p "gh-pages/${VERSION_DIR}" |
| 71 | + cp -r target/site/apidocs/* "gh-pages/${VERSION_DIR}/" |
| 72 | +
|
| 73 | + - name: Regenerate multi-version index.html |
| 74 | + run: | |
| 75 | + cd gh-pages |
| 76 | +
|
| 77 | + # Create index header |
| 78 | + cat > index.html << 'EOF' |
| 79 | + <!DOCTYPE html> |
| 80 | + <html> |
| 81 | + <head> |
| 82 | + <meta charset="UTF-8"/> |
| 83 | + <title>Javadoc Versions</title> |
| 84 | + <style> |
| 85 | + body { font-family: Arial; padding: 2rem; max-width: 800px; margin: auto; } |
| 86 | + h1 { font-size: 2rem; } |
| 87 | + ul { line-height: 1.8; font-size: 1.1rem; } |
| 88 | + </style> |
| 89 | + </head> |
| 90 | + <body> |
| 91 | + <h1>Available Javadoc Versions</h1> |
| 92 | + <ul> |
| 93 | + EOF |
| 94 | +
|
| 95 | + # Insert entries for each version directory |
| 96 | + for dir in docs/*; do |
| 97 | + [ -d "$dir" ] || continue |
| 98 | + ver=$(basename "$dir") |
| 99 | + echo "<li><a href=\"docs/$ver/\">$ver</a></li>" >> index.html |
| 100 | + done |
27 | 101 |
|
28 | | - - name: Print Current workflow |
29 | | - run: > |
30 | | - cat .github/workflows/javadoc.yml |
| 102 | + # Close HTML |
| 103 | + cat >> index.html << 'EOF' |
| 104 | + </ul> |
| 105 | + </body> |
| 106 | + </html> |
| 107 | + EOF |
31 | 108 |
|
32 | | - - name: Generate JavaDoc |
33 | | - run: mvn javadoc:javadoc |
| 109 | + - name: Commit & push changes |
| 110 | + run: | |
| 111 | + cd gh-pages |
| 112 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 113 | + git config user.name "github-actions[bot]" |
34 | 114 |
|
35 | | - - name: Deploy JavaDoc |
36 | | - uses: JamesIves/github-pages-deploy-action@881db5376404c5c8d621010bcbec0310b58d5e29 |
| 115 | + if git diff --quiet; then |
| 116 | + echo "No changes to commit" |
| 117 | + exit 0 |
| 118 | + fi |
| 119 | +
|
| 120 | + git add . |
| 121 | + git commit -m "Update release Javadoc for ${GITHUB_REF_NAME}" |
| 122 | + git push origin gh-pages |
| 123 | +
|
| 124 | + delete-tag-docs: |
| 125 | + name: Remove deleted tag docs |
| 126 | + runs-on: ubuntu-latest |
| 127 | + |
| 128 | + if: github.event_name == 'delete' && github.event.ref_type == 'tag' |
| 129 | + |
| 130 | + steps: |
| 131 | + - name: Checkout gh-pages |
| 132 | + uses: actions/checkout@v5 |
37 | 133 | with: |
38 | | - token: ${{ secrets.GITHUB_TOKEN }} |
39 | | - folder: target/reports/apidocs |
40 | | - target-folder: docs/${{ github.ref_name }} |
41 | | - branch: gh-pages |
| 134 | + ref: gh-pages |
| 135 | + path: gh-pages |
| 136 | + |
| 137 | + - name: Remove documentation for deleted tag |
| 138 | + run: | |
| 139 | + TAG="${GITHUB_REF_NAME}" |
| 140 | + VERSION_DIR="docs/${TAG}" |
| 141 | + rm -rf "gh-pages/${VERSION_DIR}" |
| 142 | +
|
| 143 | + - name: Rebuild index.html |
| 144 | + run: | |
| 145 | + cd gh-pages |
| 146 | +
|
| 147 | + # Regenerate index.html (same as above) |
| 148 | + cat > index.html << 'EOF' |
| 149 | + <!DOCTYPE html> |
| 150 | + <html> |
| 151 | + <head> |
| 152 | + <meta charset="UTF-8"/> |
| 153 | + <title>Javadoc Versions</title> |
| 154 | + <style> |
| 155 | + body { font-family: Arial; padding: 2rem; max-width: 800px; margin: auto; } |
| 156 | + h1 { font-size: 2rem; } |
| 157 | + ul { line-height: 1.8; font-size: 1.1rem; } |
| 158 | + </style> |
| 159 | + </head> |
| 160 | + <body> |
| 161 | + <h1>Available Javadoc Versions</h1> |
| 162 | + <ul> |
| 163 | + EOF |
| 164 | +
|
| 165 | + for dir in docs/*; do |
| 166 | + [ -d "$dir" ] || continue |
| 167 | + ver=$(basename "$dir") |
| 168 | + echo "<li><a href=\"docs/$ver/\">$ver</a></li>" >> index.html |
| 169 | + done |
| 170 | +
|
| 171 | + cat >> index.html << 'EOF' |
| 172 | + </ul> |
| 173 | + </body> |
| 174 | + </html> |
| 175 | + EOF |
| 176 | +
|
| 177 | + - name: Commit & push removal |
| 178 | + run: | |
| 179 | + cd gh-pages |
| 180 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 181 | + git config user.name "github-actions[bot]" |
| 182 | +
|
| 183 | + if git diff --quiet; then |
| 184 | + echo "No changes to commit" |
| 185 | + exit 0 |
| 186 | + fi |
| 187 | +
|
| 188 | + git add . |
| 189 | + git commit -m "Remove Javadoc for deleted tag ${GITHUB_REF_NAME}" |
| 190 | + git push origin gh-pages |
| 191 | +
|
| 192 | +# Summary of Features |
| 193 | +# Multi-version docs (docs/<tag>/) |
| 194 | +# Auto-generated index.html |
| 195 | +# Only publish for tags |
| 196 | +# Delete docs when tags are deleted |
| 197 | +# Upload Pages artifact |
| 198 | +# Maven dependency caching |
| 199 | +# No third-party actions |
| 200 | +# No force-push |
| 201 | +# Clean HTML layout |
0 commit comments