Skip to content

Commit 0ebe1dd

Browse files
committed
feat: publish-javadoc wf using artifacts -> single deployment
1 parent 53c9d83 commit 0ebe1dd

File tree

1 file changed

+63
-57
lines changed

1 file changed

+63
-57
lines changed

.github/workflows/callable.publish-javadoc.yml

Lines changed: 63 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,55 @@ on:
55
workflow_call:
66

77
jobs:
8-
deploy_basics:
8+
build_package_javadoc:
99
name: Build & deploy
1010
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@v3
18+
with:
19+
distribution: 'corretto'
20+
java-version: '17'
21+
cache: 'gradle'
22+
- uses: gradle/wrapper-validation-action@v1
23+
- name: Setup Gradle
24+
uses: gradle/[email protected]
25+
26+
- name: Run build (incl. test)
27+
run: gradle javadoc
28+
29+
- name: Conclude javadoc version and set env
30+
run: |
31+
if [[ "$GITHUB_REF" == "refs/heads/main" || "$GITHUB_REF" == "refs/heads/master" ]]; then
32+
echo "PUBLISH_VERSION=current" >> $GITHUB_ENV
33+
else
34+
echo "PUBLISH_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
35+
fi
36+
37+
- name: Conclude library name and set env
38+
run: echo "LIBRARY_NAME=$(grep -o '^rootProject.name.*' settings.gradle.kts | sed -e 's/rootProject.name.*"\(.*\)"/\1/')" >> $GITHUB_ENV
39+
40+
- name: zip javadoc folder\
41+
env:
42+
LIBRARY_NAME: ${{ env.LIBRARY_NAME }}
43+
run: |
44+
cd "$LIBRARY_NAME/build/docs/javadoc"
45+
zip -r ../../../../javadoc.zip .
46+
47+
- name: Upload artifact
48+
uses: actions/upload-artifact@v3
49+
with:
50+
name: javadoc
51+
path: javadoc.zip
52+
53+
deploy_javadoc:
54+
name: Build & deploy
55+
runs-on: ubuntu-latest
56+
needs: build_package_javadoc
1157
permissions:
1258
contents: write
1359
steps:
@@ -16,7 +62,7 @@ jobs:
1662
with:
1763
ref: main
1864
token: ${{ secrets.GITHUB_TOKEN }}
19-
- name: Checkout create new empty or checkout branch 'gh-pages'
65+
- name: Checkout or create empty branch 'gh-pages'
2066
run: |
2167
git fetch origin gh-pages || true
2268
git checkout gh-pages || git switch --orphan gh-pages
@@ -35,29 +81,30 @@ jobs:
3581
run: |
3682
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
3783
84+
- name: Download artifact from build job
85+
uses: actions/download-artifact@v3
86+
with:
87+
name: javadoc
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+
3898
- name: Create javadoc index.html listing versions
3999
env:
40100
PUBLISH_VERSION: ${{ env.PUBLISH_VERSION }}
41-
GH_API_CONTENTS_URL: https://api.github.com/repos/${{ github.repository }}/contents/javadoc?ref=gh-pages
42101
GITHUB_REPOSITORY_NAME: ${{ github.event.repository.name }}
43102
run: |
44103
mkdir -p javadoc
45104
rm javadoc/index.html || true
46105
touch javadoc/index.html
47106
48-
response=$(curl -s -w "%{http_code}" $GH_API_CONTENTS_URL)
49-
http_code=$(tail -n1 <<< "$response") # get the last line
50-
content=$(sed '$ d' <<< "$response") # get all but the last line which contains the status code
51-
52-
if [[ "$http_code" == 200 ]]; then
53-
echo "Success"
54-
versions=( $(echo "$content" | jq -r "[.[] | select( .type == \"dir\" ) | .name] + [\"$PUBLISH_VERSION\"] | unique | .[]") )
55-
else
56-
echo "Fail"
57-
echo "$http_code"
58-
echo "$content"
59-
versions=("$PUBLISH_VERSION")
60-
fi
107+
versions=( $(cd javadoc && find . -maxdepth 1 -type d | jq -srR 'split("\n") | unique | .[][2:] | select(length > 0)') )
61108
62109
echo "javadoc versions:"
63110
for value in "${versions[@]}"
@@ -104,44 +151,3 @@ jobs:
104151
run: |
105152
git push --set-upstream origin gh-pages
106153
107-
deploy_javadoc:
108-
name: Build & deploy
109-
runs-on: ubuntu-latest
110-
permissions:
111-
contents: write
112-
needs: deploy_basics
113-
114-
steps:
115-
- name: Checkout project sources
116-
uses: actions/checkout@v4
117-
118-
- uses: actions/setup-java@v3
119-
with:
120-
distribution: 'corretto'
121-
java-version: '17'
122-
cache: 'gradle'
123-
- uses: gradle/wrapper-validation-action@v1
124-
- name: Setup Gradle
125-
uses: gradle/[email protected]
126-
127-
- name: Run build (incl. test)
128-
run: gradle javadoc
129-
130-
- name: Conclude javadoc version and set env
131-
run: |
132-
if [[ "$GITHUB_REF" == "refs/heads/main" || "$GITHUB_REF" == "refs/heads/master" ]]; then
133-
echo "PUBLISH_VERSION=current" >> $GITHUB_ENV
134-
else
135-
echo "PUBLISH_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
136-
fi
137-
138-
- name: Conclude library name and set env
139-
run: echo "LIBRARY_NAME=$(grep -o '^rootProject.name.*' settings.gradle.kts | sed -e 's/rootProject.name.*"\(.*\)"/\1/')" >> $GITHUB_ENV
140-
141-
- name: Deploy to GitHub Page 🚀 with Gradle
142-
uses: JamesIves/[email protected]
143-
with:
144-
branch: gh-pages
145-
clean: true
146-
folder: ${{ env.LIBRARY_NAME }}/build/docs/javadoc
147-
target-folder: javadoc/${{ env.PUBLISH_VERSION }}

0 commit comments

Comments
 (0)