Add Java Doc Resource / API Registration

This commit is contained in:
Kam committed 2026-03-11 05:55:21 -04:00
1 parent 3d5d819105
commit 7f6a52ae7c
34 files changed
+4675 -44

No files matched your search

+137 -3
View File
@@ -1,4 +1,3 @@
name: Build and test
on:
@@ -9,5 +8,140 @@ on:
jobs:
build-and-test:
uses: GTNewHorizons/GTNH-Actions-Workflows/.github/workflows/build-and-test.yml@master
secrets: inherit
runs-on: ubuntu-24.04
env:
WORKSPACE_TASK: ${{ vars.WORKSPACE_TASK || 'setupCIWorkspace' }}
RUN_SERVER_TIMEOUT: ${{ vars.RUN_SERVER_TIMEOUT || 90 }}
RUN_SERVER_ENABLED: ${{ vars.RUN_SERVER_ENABLED || 'true' }}
steps:
- name: Install Ubuntu dependencies
run: |
sudo apt-get update -y
sudo apt-get install -y mesa-utils xvfb x11-xserver-utils
- name: Checkout mod repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Initialize submodules
run: git submodule update --init --recursive
- name: Checkout workflows repo
uses: actions/checkout@v4
with:
repository: GTNewHorizons/GTNH-Actions-Workflows
path: .gtnh-workflows
fetch-depth: 0
- name: Set up JDK versions
uses: actions/setup-java@v4
with:
java-version: |
8
17
21
distribution: 'zulu'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
build-scan-publish: true
build-scan-terms-of-use-url: "https://gradle.com/terms-of-service"
build-scan-terms-of-use-agree: "yes"
validate-wrappers: true
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Setup the workspace
run: ./gradlew --build-cache --info --stacktrace "${WORKSPACE_TASK}"
- name: Compile the mod
run: ./gradlew --build-cache --info --stacktrace assemble
- name: Attach compilation artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ github.repository_id }}-build-libs
path: build/libs/
retention-days: 90
- name: Run post-build checks
id: build_mod
run: xvfb-run --server-args="-screen 0 1366x768x24" ./gradlew --build-cache --info --stacktrace build
- name: Attach gradle reports
if: failure() && steps.build_mod.conclusion == 'failure'
uses: actions/upload-artifact@v4
continue-on-error: true
with:
name: ${{ github.repository_id }}-reports
path: build/reports/
retention-days: 31
- name: Attempt to make a PR fixing spotless errors
if: >-
${{ failure() && steps.build_mod.conclusion == 'failure'
&& github.event_name == 'pull_request'
&& !github.event.pull_request.draft
&& github.event.pull_request.head.repo.full_name == github.repository }}
run: |
git reset --hard
git checkout "${PR_BRANCH}"
./gradlew --build-cache --info --stacktrace spotlessApply || exit 1
git diff --exit-code && exit 1
git config user.name "GitHub GTNH Actions"
git config user.email "<>"
git switch -c "${FIXED_BRANCH}"
git commit -am "spotlessApply"
git push --force-with-lease origin "${FIXED_BRANCH}"
gh pr create \
--head "${FIXED_BRANCH}" \
--base "${PR_BRANCH}" \
--title "Spotless apply for branch ${PR_BRANCH} for #${{ github.event.pull_request.number }}" \
--body "Automatic spotless apply to fix formatting errors, applies to PR #${{ github.event.pull_request.number }}" \
2>&1 | tee pr-message.log || true
gh pr comment "${PR_BRANCH}" -F pr-message.log || true
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_BRANCH: ${{ github.head_ref }}
FIXED_BRANCH: ${{ github.head_ref }}-spotless-fixes
- name: Run server for up to ${{ env.RUN_SERVER_TIMEOUT }} seconds
if: ${{ env.RUN_SERVER_ENABLED == 'true' }}
run: |
mkdir -p run
echo "eula=true" > run/eula.txt
echo "level-seed=-6202107849386030209\nonline-mode=true\n" > run/server.properties
echo "stop" > run/stop.txt
timeout "${RUN_SERVER_TIMEOUT}" ./gradlew --build-cache --info --stacktrace runServer 2>&1 < run/stop.txt | tee -a server.log || true
- name: Test no errors reported during server run
if: ${{ env.RUN_SERVER_ENABLED == 'true' }}
run: |
chmod +x .gtnh-workflows/scripts/test_no_error_reports
.gtnh-workflows/scripts/test_no_error_reports
- name: Test no prerelease dependencies used
run: |
! grep -P -- "-pre(?!shadow)" dependencies.gradle*
- name: Make sure asset files are not overoptimized
if: github.event_name == 'pull_request'
run: |
echo "Checking for grayscale asset files which are not supported by the java8 image loader"
fail=0
set -o pipefail
while IFS= read -r -d $'\n' file; do
if $(file --brief -- "$file" | grep -q grayscale); then
printf "found grayscale image '%s'\n" "$file"
fail=1
fi
done < <(gh pr diff --name-only "${PR_NUMBER}" | grep 'src/main/resources/.*\.png$')
exit $fail
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.number }}
@@ -1,39 +0,0 @@
# This workflow only meant for the source mod you shouldn't bring it into your own project
name: Buildscript maintenance
on:
push:
branches: [ master, main ]
paths:
- build.gradle
workflow_dispatch: { }
jobs:
buildscript-maintenance:
runs-on: ubuntu-latest
# Avoid running this workflow on forks
if: github.repository == 'GTNewHorizons/ExampleMod1.7.10'
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Ensure build script version is up to date
id: update-buildscript
run: |
new_version="$(date +%s)"
sed --in-place "1s!^//version:.*!//version: $new_version!g" build.gradle
echo "::set-output name=new_version::$new_version"
- name: Create Pull Request
id: create-pull-request
uses: peter-evans/create-pull-request@v4
with:
add-paths: build.gradle
commit-message: '[ci skip] update build script version to ${{ steps.update-buildscript.outputs.new_version }}'
branch: buildscript-maintenance
title: Update build script version to ${{ steps.update-buildscript.outputs.new_version }}
body: This pull request is created by the buildscript-maintenance workflow
+260
View File
@@ -0,0 +1,260 @@
name: Generate and Deploy Javadoc
on:
push:
branches:
- main
- '**'
delete:
workflow_dispatch:
inputs:
force_deploy:
description: 'Force redeploy Javadocs without a new commit'
required: false
default: 'true'
jobs:
sanity-check:
runs-on: ubuntu-latest
outputs:
should_deploy: ${{ steps.deploy_check.outputs.should_deploy }}
steps:
- uses: actions/checkout@v4
- name: Check for deploy tag
id: deploy_check
run: |
source .github/scripts/doc-config.sh
BRANCH="${GITHUB_REF#refs/heads/}"
# Always deploy on manual trigger
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "should_deploy=true" >> $GITHUB_OUTPUT
echo "Reason: workflow_dispatch"
exit 0
fi
# Main branch: only deploy if commit message contains [deploy-docs]
if [ "$BRANCH" = "$MAIN_BRANCH_NAME" ]; then
if echo "${{ github.event.head_commit.message }}" | grep -q "\[deploy-docs\]"; then
echo "should_deploy=true" >> $GITHUB_OUTPUT
echo "Reason: main branch with [deploy-docs] tag"
else
echo "should_deploy=false" >> $GITHUB_OUTPUT
echo "Reason: main branch without [deploy-docs] tag, skipping"
fi
exit 0
fi
# Experimental branches: only deploy if whitelisted
for ALLOWED in "${EXPERIMENTAL_WHITELIST[@]}"; do
if [ "$BRANCH" = "$ALLOWED" ]; then
echo "should_deploy=true" >> $GITHUB_OUTPUT
echo "Reason: branch '$BRANCH' is whitelisted"
exit 0
fi
done
echo "should_deploy=false" >> $GITHUB_OUTPUT
echo "Reason: branch '$BRANCH' is not whitelisted, skipping"
build-and-deploy-javadoc:
needs: sanity-check
if: needs.sanity-check.outputs.should_deploy == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout source branch
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
- name: Setup JDK 8 (compile)
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'temurin'
- name: Setup JDK 11 (javadoc)
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'temurin'
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Extract convention plugin version
id: convention
run: |
VERSION=$(grep "id 'com.gtnewhorizons.gtnhsettingsconvention'" settings.gradle settings.gradle.kts 2>/dev/null | grep -o "version '[0-9]\+\.[0-9]\+\.[0-9]\+'" | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Detected convention version: $VERSION"
- name: Get source commit info
id: source_commit
run: |
echo "hash=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "date=$(git log -1 --format='%cI')" >> $GITHUB_OUTPUT
- name: Cache Gradle wrapper
uses: actions/cache@v4
with:
path: ~/.gradle/wrapper
key: gradle-wrapper-${{ hashFiles('**/gradle-wrapper.properties') }}
- name: Cache Gradle dependencies
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/caches/modules-*
~/.gradle/caches/jars-*
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties', '**/gradle.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Cache RFG
uses: actions/cache@v4
with:
path: |
build/rfg
build/tmp/.cache/expanded
build/tmp/deobfuscateMergedJarToSrg
key: ${{ runner.os }}-rfg-convention${{ steps.convention.outputs.version }}
restore-keys: |
${{ runner.os }}-rfg-
- name: Cache Node modules
uses: actions/cache@v4
with:
path: .github/pages/node_modules
key: ${{ runner.os }}-node-${{ hashFiles('.github/pages/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Resolve CNPC+ Javadoc URL
id: cnpc_docs
run: |
BRANCH="${GITHUB_REF#refs/heads/}"
CNPC_BASE="https://kamkeel.github.io/CustomNPC-Plus"
if [ "$BRANCH" = "main" ]; then
# Main branch links to CNPC+ master (releases/<version>)
cd CustomNPC-Plus
if [ -f "gradle.properties" ] && grep -q "^modVersion=" gradle.properties; then
CNPC_VER=$(grep "^modVersion=" gradle.properties | cut -d'=' -f2 | tr -d '[:space:]')
elif [ -f "gradle.properties" ] && grep -q "^version=" gradle.properties; then
CNPC_VER=$(grep "^version=" gradle.properties | cut -d'=' -f2 | tr -d '[:space:]')
elif [ -f "build.gradle" ]; then
CNPC_VER=$(grep "^version" build.gradle | head -1 | sed "s/version\s*=\s*['\"]//;s/['\"].*//;s/\s//g")
else
CNPC_VER="unknown"
fi
cd ..
CNPC_DOC_URL="${CNPC_BASE}/releases/${CNPC_VER}"
echo "Linking Gecko main -> CNPC+ releases/${CNPC_VER}"
else
# Dev / experimental branches link to CNPC+ experimental/<branch>
SAFE_BRANCH="${BRANCH//\//-}"
CNPC_DOC_URL="${CNPC_BASE}/experimental/${SAFE_BRANCH}"
echo "Linking Gecko ${BRANCH} -> CNPC+ experimental/${SAFE_BRANCH}"
fi
# Download the element-list so javadoc can resolve cross-references
mkdir -p build/cnpc-element-list
if curl -fsSL "${CNPC_DOC_URL}/element-list" -o build/cnpc-element-list/element-list; then
echo "Downloaded element-list from ${CNPC_DOC_URL}"
elif curl -fsSL "${CNPC_DOC_URL}/package-list" -o build/cnpc-element-list/element-list; then
echo "Downloaded package-list (JDK 8 format) from ${CNPC_DOC_URL}"
else
echo "::warning::Could not download element-list from ${CNPC_DOC_URL}. Cross-links to CNPC+ will not work."
fi
echo "url=${CNPC_DOC_URL}" >> $GITHUB_OUTPUT
- name: Generate Javadoc
run: |
./gradlew javadoc \
-PcnpcDocUrl=${{ steps.cnpc_docs.outputs.url }} \
-PcnpcDocElementList=build/cnpc-element-list
- name: Get deploy path
id: deploy_path
run: bash .github/scripts/resolve-doc-path.sh
- name: Deploy to gh-pages
if: steps.deploy_path.outputs.path != ''
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./build/docs/javadoc
destination_dir: ${{ steps.deploy_path.outputs.path }}
keep_files: true
# Give GitHub a moment to settle after the peaceiris push
- name: Wait for gh-pages to settle
run: sleep 10
- name: Checkout gh-pages
uses: actions/checkout@v4
with:
ref: gh-pages
path: gh-pages-index
- name: Generate manifest
run: |
cd gh-pages-index
SOURCE_HASH="${{ steps.source_commit.outputs.hash }}" \
SOURCE_DATE="${{ steps.source_commit.outputs.date }}" \
DEPLOY_PATH="${{ steps.deploy_path.outputs.path }}" \
bash ../.github/scripts/generate-index.sh
- name: Install page dependencies
run: npm ci --prefix .github/pages
- name: Build index page
run: |
mkdir -p .github/pages/public
cp gh-pages-index/manifest.json .github/pages/public/manifest.json
npm run build --prefix .github/pages
- name: Deploy index to gh-pages
run: |
cp -r .github/pages-dist/* gh-pages-index/
cd gh-pages-index
git config user.name "github-actions"
git config user.email "[email protected]"
git add -A
git commit -m "Regenerate index and manifest [skip ci]" || echo "Unchanged"
git push
cleanup-on-delete:
if: github.event_name == 'delete' && github.event.ref_type == 'branch'
runs-on: ubuntu-latest
steps:
- name: Checkout gh-pages
uses: actions/checkout@v4
with:
ref: 'gh-pages'
- name: Remove deleted branch docs
run: |
BRANCH="${{ github.event.ref }}"
SAFE="experimental/${BRANCH//\//-}"
if [ -d "./$SAFE" ]; then
rm -rf "./$SAFE"
META_KEY="${SAFE//\//_}"
rm -f ".doc-meta/${META_KEY}.json"
git config user.name "github-actions"
git config user.email "[email protected]"
git add -A
git commit -m "Remove docs for deleted branch: $BRANCH"
git push
else
echo "No docs found for $SAFE, skipping."
fi