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