1+ name : Publish javadoc (GitHub Pages)
2+
3+ on :
4+ workflow_dispatch :
5+ workflow_call :
6+
7+ jobs :
8+ build_package_javadoc :
9+ name : Generate Javadoc
10+ runs-on : ubuntu-latest
11+ permissions :
12+ contents : write
13+ steps :
14+ - name : Checkout project sources
15+ uses : actions/checkout@v4
16+
17+ - uses : actions/setup-java@v4
18+ with :
19+ distribution : ' corretto'
20+ java-version : ' 21'
21+
22+ - uses : gradle/actions/wrapper-validation@v3
23+ - name : Setup Gradle
24+ uses :
gradle/actions/[email protected] 25+ with :
26+ cache-read-only : true
27+
28+ - name : Generate javadoc (gradle)
29+ run : ./gradlew javadoc
30+
31+ - name : Conclude javadoc version and set env
32+ run : |
33+ if [[ "$GITHUB_REF" == "refs/heads/main" || "$GITHUB_REF" == "refs/heads/master" ]]; then
34+ echo "PUBLISH_VERSION=current" >> $GITHUB_ENV
35+ else
36+ echo "PUBLISH_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
37+ fi
38+
39+ - name : zip javadoc folder
40+ env :
41+ LIBRARY_NAME : ${{ env.LIBRARY_NAME }}
42+ run : |
43+ cd "lib/build/docs/javadoc"
44+ zip -r ../../../../javadoc.zip .
45+
46+ - name : Upload artifact
47+ uses : actions/upload-artifact@v4
48+ with :
49+ name : javadoc.zip
50+ path : javadoc.zip
51+
52+ deploy_javadoc :
53+ name : Deploy (GH Pages)
54+ runs-on : ubuntu-latest
55+ needs : build_package_javadoc
56+ permissions :
57+ contents : write
58+ steps :
59+ - name : Checkout project sources
60+ uses : actions/checkout@v4
61+ with :
62+ ref : main
63+ token : ${{ secrets.CI_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
64+
65+ - name : Checkout or create empty branch 'gh-pages'
66+ run : |
67+ git fetch origin gh-pages || true
68+ git checkout gh-pages || git switch --orphan gh-pages
69+
70+ - name : Conclude javadoc version and set env
71+ run : |
72+ if [[ "$GITHUB_REF" == "refs/heads/main" || "$GITHUB_REF" == "refs/heads/master" ]]; then
73+ echo "PUBLISH_VERSION=current" >> $GITHUB_ENV
74+ else
75+ echo "PUBLISH_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
76+ fi
77+
78+ - name : Create root index redirect
79+ env :
80+ GITHUB_REPOSITORY_NAME : ${{ github.event.repository.name }}
81+ run : |
82+ echo "<!DOCTYPE html><html lang=en><meta content=\"text/html; charset=utf-8\"http-equiv=Content-Type><meta content=\"index redirect\"name=description><link href=/$GITHUB_REPOSITORY_NAME/javadoc/ rel=canonical><link href=stylesheet.css rel=stylesheet title=Style><script>window.location.replace(\"/$GITHUB_REPOSITORY_NAME/javadoc/\")</script><noscript><meta content=0;/$GITHUB_REPOSITORY_NAME/javadoc/ http-equiv=Refresh></noscript><main role=main><noscript><p>JavaScript is disabled on your browser.</p></noscript><p><a href=/$GITHUB_REPOSITORY_NAME/javadoc/ >/$GITHUB_REPOSITORY_NAME/javadoc/</a></main>" > index.html
83+
84+ - name : Download artifact from build job
85+ uses : actions/download-artifact@v4
86+ with :
87+ name : javadoc.zip
88+
89+ - name : unzip javadoc folder
90+ env :
91+ PUBLISH_VERSION : ${{ env.PUBLISH_VERSION }}
92+ run : |
93+ mkdir -p javadoc
94+ rm -Rf "javadoc/$PUBLISH_VERSION" || true
95+ unzip -d "javadoc/$PUBLISH_VERSION" javadoc.zip
96+ rm javadoc.zip
97+
98+ - name : Create javadoc index.html listing versions
99+ env :
100+ PUBLISH_VERSION : ${{ env.PUBLISH_VERSION }}
101+ GITHUB_REPOSITORY_NAME : ${{ github.event.repository.name }}
102+ run : |
103+ mkdir -p javadoc
104+ rm javadoc/index.html || true
105+ touch javadoc/index.html
106+
107+ versions=( $(cd javadoc && find . -maxdepth 1 -type d | jq -srR 'split("\n") | unique | .[][2:] | select(length > 0)') )
108+
109+ echo "javadoc versions:"
110+ for value in "${versions[@]}"
111+ do
112+ echo "- $value"
113+ done
114+
115+ echo "<!DOCTYPE HTML>" >> javadoc/index.html
116+ echo "<html lang=\"en\">" >> javadoc/index.html
117+ echo "<head>" >> javadoc/index.html
118+ echo " <title>Javadoc | '$GITHUB_REPOSITORY_NAME'</title>" >> javadoc/index.html
119+ echo " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">" >> javadoc/index.html
120+ echo " <meta charset=\"UTF-8\">" >> javadoc/index.html
121+ echo " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">" >> javadoc/index.html
122+ echo " <meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">" >> javadoc/index.html
123+ echo " <meta name=\"description\" content=\"Javadoc for library '$GITHUB_REPOSITORY_NAME'\">" >> javadoc/index.html
124+ echo "</head>" >> javadoc/index.html
125+ echo "<body>" >> javadoc/index.html
126+ echo "<main style=\"font-family: sans-serif;\">" >> javadoc/index.html
127+ echo " <h1>Javadoc</h1>" >> javadoc/index.html
128+ echo " <h2>Versions</h2>" >> javadoc/index.html
129+ echo " <ul>" >> javadoc/index.html
130+
131+ for value in "${versions[@]}"
132+ do
133+ echo " <li><a href=\"$value\">$value</a></li>" >> javadoc/index.html
134+ done
135+
136+ echo " </ul>" >> javadoc/index.html
137+ echo "</main>" >> javadoc/index.html
138+ echo "</body>" >> javadoc/index.html
139+ echo "</html>" >> javadoc/index.html
140+
141+ - name : Commit files
142+ run : |
143+ git config --local user.email "[email protected] " 144+ git config --local user.name "github-actions[bot]"
145+ git add .
146+ git status
147+ git diff-index --quiet HEAD || git commit -m "chore: update index.html files incl. javadoc versions"
148+
149+ # Push changes
150+ - name : Push changes
151+ run : |
152+ git push --set-upstream origin gh-pages
0 commit comments