Skip to content

Generate Docs on 479/merge #31

Generate Docs on 479/merge

Generate Docs on 479/merge #31

Workflow file for this run

name: Generate Docs
run-name: "Generate Docs on ${{ github.ref_name }}"
on:
pull_request:
branches:
- main
types:
- opened
- synchronize
release:
types: [published]
workflow_dispatch: {}
jobs:
generate-docs:
name: Generate SDK reference docs
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
outputs:
sdk-version: ${{ steps.sdk-version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get SDK version
id: sdk-version
run: echo "version=$(jq -r '.version' package.json)" >> "$GITHUB_OUTPUT"
- name: Install Doxygen
run: |
sudo apt-get update
sudo apt-get install -y doxygen graphviz
- name: Generate docs
run: bash .doxygen/generate-doxygen-docs.sh
- name: Upload docs artifact
uses: actions/upload-artifact@v4
with:
name: unity-sdk-docs-${{ steps.sdk-version.outputs.version }}
path: docs/html/
retention-days: 30
attach-release:
name: Attach docs to release
runs-on: ubuntu-latest
needs: generate-docs
if: github.event_name == 'release'
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download docs artifact
uses: actions/download-artifact@v4
with:
name: unity-sdk-docs-${{ needs.generate-docs.outputs.sdk-version }}
path: docs/html/
- name: Package docs for release
run: zip -r docs-${{ github.ref_name }}.zip docs/html/
- name: Attach docs to GitHub release
run: gh release upload --clobber ${{ github.ref_name }} docs-${{ github.ref_name }}.zip
env:
GH_TOKEN: ${{ github.token }}
deploy-pages:
name: Deploy docs to GitHub Pages
runs-on: ubuntu-latest
needs: generate-docs
# Deploy on release or manual dispatch only
if: github.event_name == 'release' || github.event_name == 'workflow_dispatch'
permissions:
contents: write
steps:
- name: Download docs artifact
uses: actions/download-artifact@v4
with:
name: unity-sdk-docs-${{ needs.generate-docs.outputs.sdk-version }}
path: site/
- name: Checkout gh-pages branch
uses: actions/checkout@v4
with:
ref: gh-pages
path: gh-pages-branch
continue-on-error: true # first run — branch may not exist yet
- name: Determine deploy target(s)
id: targets
run: |
if [ "${{ github.event_name }}" = "release" ]; then
echo "target_dir=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
echo "deploy_latest=true" >> "$GITHUB_OUTPUT"
echo "is_release=true" >> "$GITHUB_OUTPUT"
else
BRANCH="${{ github.ref_name }}"
if [ "$BRANCH" = "main" ]; then
echo "target_dir=latest" >> "$GITHUB_OUTPUT"
else
SAFE_BRANCH="branch-$(echo "$BRANCH" | tr '/' '-')"
echo "target_dir=$SAFE_BRANCH" >> "$GITHUB_OUTPUT"
fi
echo "deploy_latest=false" >> "$GITHUB_OUTPUT"
echo "is_release=false" >> "$GITHUB_OUTPUT"
fi
- name: Build versions.json
run: |
python3 - << 'PYEOF'
import json, os, re
existing_path = "gh-pages-branch/versions.json"
versions = []
if os.path.exists(existing_path):
with open(existing_path) as f:
versions = json.load(f)
target_dir = os.environ.get("TARGET_DIR", "")
is_release = os.environ.get("IS_RELEASE", "false") == "true"
# Update or add the new entry
paths = {v["path"] for v in versions}
if target_dir and target_dir + "/" not in paths:
versions.append({"version": target_dir, "path": target_dir + "/"})
def semver_key(v):
m = re.match(r"v?(\d+)\.(\d+)\.(\d+)", v["version"])
return tuple(int(x) for x in m.groups()) if m else (0, 0, 0)
if is_release:
# latest always first, release versions desc, branch previews last
release_vs = [v for v in versions if v["version"] != "latest" and not v["version"].startswith("branch-")]
branch_vs = [v for v in versions if v["version"].startswith("branch-")]
release_vs.sort(key=semver_key, reverse=True)
versions = [{"version": "latest", "path": "latest/"}] + release_vs + branch_vs
else:
# Dispatch: always include latest entry; branch previews at end
latest_entry = next((v for v in versions if v["version"] == "latest"), {"version": "latest", "path": "latest/"})
release_vs = [v for v in versions if v["version"] != "latest" and not v["version"].startswith("branch-")]
branch_vs = [v for v in versions if v["version"].startswith("branch-")]
release_vs.sort(key=semver_key, reverse=True)
versions = [latest_entry] + release_vs + branch_vs
os.makedirs("site-root", exist_ok=True)
with open("site-root/versions.json", "w") as f:
json.dump(versions, f, indent=2)
print("versions.json:", json.dumps(versions, indent=2))
PYEOF
env:
TARGET_DIR: ${{ steps.targets.outputs.target_dir }}
IS_RELEASE: ${{ steps.targets.outputs.is_release }}
- name: Build root redirect page
run: |
cat > site-root/index.html << 'EOF'
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta http-equiv="refresh" content="0;url=latest/"/>
<title>LootLocker Unity SDK — Reference Docs</title>
</head>
<body>
<p>Redirecting to <a href="latest/">latest documentation</a>…</p>
</body>
</html>
EOF
- name: Deploy to target directory
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./site
destination_dir: ${{ steps.targets.outputs.target_dir }}
keep_files: true
- name: Deploy to latest (release only)
if: steps.targets.outputs.deploy_latest == 'true'
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./site
destination_dir: latest
keep_files: true
- name: Deploy site root (versions.json + index.html)
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./site-root
destination_dir: .
keep_files: true