name: Update Wiki Documentation on: push: branches: - main jobs: generate-docs: runs-on: ubuntu-latest permissions: wiki: write contents: write steps: - name: Checkout Code uses: actions/checkout@v3 - name: Set up JDK 17 uses: actions/setup-java@v3 with: java-version: '17' distribution: 'temurin' - name: Build Markdown Docs run: | chmod +x gradlew ./gradlew dokkaGfm - name: Sync to Wiki run: | git config --global user.name "Gitea Actions" git config --global user.email "actions@gitea.io" WIKI_URL="https://x-access-token:${{ secrets.GITEA_TOKEN }}@gitea.archvium.eu/KrzysztofC/Retro_HA.wiki.git" # Clone the wiki repository git clone "$WIKI_URL" wiki_dir # Clean up old files except .git find wiki_dir -mindepth 1 -maxdepth 1 ! -name '.git' -exec rm -rf {} + # Copy new documentation files # Check for multi-module output or fallback to individual modules if [ -d "build/dokka/gfm" ]; then cp -r build/dokka/gfm/* wiki_dir/ else [ -d "shared/build/dokka/gfm" ] && cp -r shared/build/dokka/gfm/* wiki_dir/ [ -d "app/build/dokka/gfm" ] && cp -r app/build/dokka/gfm/* wiki_dir/ fi cd wiki_dir # TRANSFORM LINKS FOR GITEA WIKI # 1. Remove .md extension from all internal markdown links # 2. Handle both [text](path.md) and [text](path.md#anchor) # 3. Remove './' prefixes which confuse Gitea routing find . -type f -name "*.md" -exec perl -pi -e 's/\]\((?!http)(\.?\/)?(.*?)\.md(?:#(.*?))?\)/\]\($2#$3\)/g' {} + # Clean up trailing '#' if no anchor was present find . -type f -name "*.md" -exec perl -pi -e 's/#\)/)/g' {} + # CREATE SIDEBAR FOR GLOBAL NAVIGATION echo "### RetroHA API" > _Sidebar.md echo "* [Home](Home)" >> _Sidebar.md [ -d "shared" ] && echo "* [Shared Module](shared/index)" >> _Sidebar.md [ -d "app" ] && echo "* [App Module](app/index)" >> _Sidebar.md echo "" >> _Sidebar.md echo "---" >> _Sidebar.md echo "*Generated by Dokka*" >> _Sidebar.md # CREATE HOME PAGE (ENTRY POINT) echo "# RetroHA Developer Wiki" > Home.md echo "Welcome to the autogenerated technical documentation for the RetroHA project." >> Home.md echo "" >> Home.md echo "### Project Modules" >> Home.md [ -f "shared/index.md" ] || [ -f "shared/index" ] && echo "* **[Shared Module](shared/index)**: Core data models and HA client logic." >> Home.md [ -f "app/index.md" ] || [ -f "app/index" ] && echo "* **[App Module](app/index)**: Android application UI and Bauhaus Canvas engine." >> Home.md echo "" >> Home.md echo "---" >> Home.md echo "Use the sidebar on the right to navigate between packages and classes." >> Home.md # COMMIT AND PUSH git add . if ! git diff --cached --quiet; then git commit -m "docs: sync transformed documentation to gitea wiki" git branch -M main git push -u origin main --force else echo "No changes to sync." fi