Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 78 additions & 17 deletions .github/workflows/javadoc.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
name: Build and Publish Javadoc
name: Build and Publish Versioned Javadoc

on:
push:
branches: [main]
paths:
- '**/*.java'
- 'build.gradle.kts'
- '**/build.gradle.kts'
tags:
- 'v*'
workflow_dispatch:

permissions:
contents: read
pages: write
id-token: write
contents: write

concurrency:
group: "javadoc"
cancel-in-progress: true
group: "javadoc-pages"
cancel-in-progress: false

jobs:
build-javadoc:
publish-javadoc:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -37,9 +32,75 @@ jobs:
- name: Generate Javadoc
run: ./gradlew aggregateJavadoc

- name: Upload Javadoc artifact
uses: actions/upload-artifact@v4
- name: Compute version
id: vars
run: |
version="$GITHUB_REF_NAME"
version="${version//\//-}"
echo "version=$version" >> "$GITHUB_OUTPUT"

- name: Publish versioned Javadoc
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: gh-pages
publish_dir: build/docs/javadoc
destination_dir: ${{ steps.vars.outputs.version }}
keep_files: true

- name: Checkout gh-pages (for index)
uses: actions/checkout@v4
continue-on-error: true
with:
ref: gh-pages
path: gh-pages
fetch-depth: 1

- name: Generate index.html
env:
CURRENT_VERSION: ${{ steps.vars.outputs.version }}
run: |
mkdir -p site

versions=""
if [ -d gh-pages ]; then
versions=$(find gh-pages -maxdepth 1 -mindepth 1 -type d -printf '%f\n' | grep -v '^latest$' | sort -V || true)
fi

if [ -n "${CURRENT_VERSION:-}" ]; then
versions=$(printf "%s\n%s\n" "$versions" "$CURRENT_VERSION" | sed '/^$/d' | sort -V | uniq)
fi

{
echo '<!doctype html>'
echo '<html lang="en">'
echo '<meta charset="utf-8">'
echo '<meta name="viewport" content="width=device-width, initial-scale=1">'
echo '<title>Javadoc</title>'
echo '<body>'
echo '<h1>Javadoc</h1>'
echo '<p><a href="latest/">Latest</a></p>'
echo '<h2>Versions</h2>'
echo '<ul>'

if [ -n "$versions" ]; then
printf '%s\n' "$versions" | while IFS= read -r v; do
[ -z "$v" ] && continue
echo " <li><a href=\"${v}/\">${v}</a></li>"
done
else
echo ' <li><em>No versions published yet.</em></li>'
fi

echo '</ul>'
echo '</body>'
echo '</html>'
} > site/index.html

- name: Publish index.html
uses: peaceiris/actions-gh-pages@v4
with:
name: javadoc
path: build/docs/javadoc
retention-days: 7
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: gh-pages
publish_dir: site
keep_files: true
92 changes: 92 additions & 0 deletions .github/workflows/latest-javadoc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Build and Publish Latest Javadoc

on:
push:
branches: [main]
workflow_dispatch:

permissions:
contents: write

concurrency:
group: "javadoc-latest"
cancel-in-progress: true

jobs:
publish-latest-javadoc:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up JDK 24
uses: actions/setup-java@v4
with:
java-version: '24'
distribution: 'temurin'

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3

- name: Generate Javadoc
run: ./gradlew --no-configuration-cache aggregateJavadoc

- name: Publish latest Javadoc
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: gh-pages
publish_dir: build/docs/javadoc
destination_dir: latest
keep_files: true

- name: Checkout gh-pages (for index)
uses: actions/checkout@v4
continue-on-error: true
with:
ref: gh-pages
path: gh-pages
fetch-depth: 1

- name: Generate index.html
run: |
mkdir -p site

versions=""
if [ -d gh-pages ]; then
versions=$(find gh-pages -maxdepth 1 -mindepth 1 -type d -printf '%f\n' | grep -v '^latest$' | sort -V || true)
fi

{
echo '<!doctype html>'
echo '<html lang="en">'
echo '<meta charset="utf-8">'
echo '<meta name="viewport" content="width=device-width, initial-scale=1">'
echo '<title>Javadoc</title>'
echo '<body>'
echo '<h1>Javadoc</h1>'
echo '<p><a href="latest/">Latest</a></p>'
echo '<h2>Versions</h2>'
echo '<ul>'

if [ -n "$versions" ]; then
printf '%s\n' "$versions" | while IFS= read -r v; do
[ -z "$v" ] && continue
echo " <li><a href=\"${v}/\">${v}</a></li>"
done
else
echo ' <li><em>No versions published yet.</em></li>'
fi

echo '</ul>'
echo '</body>'
echo '</html>'
} > site/index.html

- name: Publish index.html
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: gh-pages
publish_dir: site
keep_files: true
Loading