diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml index af2f1ab..cb052a8 100644 --- a/.github/workflows/publish-docs.yml +++ b/.github/workflows/publish-docs.yml @@ -4,9 +4,10 @@ on: push: branches: - 'main' - paths: - - 'docs/**' - - 'src/**' + - 'develop' + tags: + - 'v*.*' + workflow_dispatch: permissions: @@ -36,10 +37,58 @@ jobs: - name: Install dependencies run: make install-docs + - name: Determine Documentation Context + id: version + run: | + if [ "${{ github.ref }}" == "refs/heads/main" ]; then + echo "VERSION=latest" >> $GITHUB_ENV + elif [ "${{ github.ref }}" == "refs/heads/develop" ]; then + echo "VERSION=develop" >> $GITHUB_ENV + elif [[ "${{ github.ref }}" == refs/tags/v* ]]; then + echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV + else + echo "Unknown branch or tag" && exit 1 + fi + + - name: Generate switcher.json + run: | + cat < generate_switcher.py + import json + import subprocess + + tags_output = subprocess.run( + ["git", "tag", "-l", "v*.*"], capture_output=True, text=True + ).stdout.strip() + + tags = tags_output.split("\n") if tags_output else [] + + versions = [ + {"version": "latest", "url": "https://patcher.liquidzoo.io/latest/"}, + {"version": "develop", "url": "https://patcher.liquidzoo.io/develop/"}, + ] + + for tag in tags: + if tag: + versions.append({"version": tag, "url": f"https://patcher.liquidzoo.io/{tag}/"}) + + with open("docs/_build/_static/switcher.json", "w") as f: + json_data = json.dump(versions, f, indent=4) + EOF + python3 generate_switcher.py + rm generate_switcher.py + + - name: Copy CNAME to build + run: | + cp CNAME docs/_build/${{ env.VERSION }} + - name: Build Sphinx Docs env: PYTHONPATH: ${{ github.workspace }} - run: make docs + run: make docs-version VERSION=${{ env.VERSION }} + + - name: Ensure switcher is deployed + run: | + cp docs/_build/_static/switcher.json docs/_build/ - name: Upload Artifact uses: actions/upload-pages-artifact@v3 diff --git a/Makefile b/Makefile index c38a0f3..e088a9c 100644 --- a/Makefile +++ b/Makefile @@ -31,4 +31,11 @@ build: python3 -m build --sdist --wheel docs: - sphinx-build -b html docs/ docs/_build/ + @echo "Building Sphinx Docs for version $(VERSION)..." + sphinx-build -b html docs/ docs/_build/$(VERSION) + +docs-latest: + $(MAKE) docs VERSION=latest + +docs-version: + $(MAKE) docs VERSION=$(VERSION) diff --git a/docs/conf.py b/docs/conf.py index 33b4332..3b52b2b 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -102,7 +102,11 @@ "navbar_align": "left", "announcement": "https://raw.githubusercontent.com/liquidz00/Patcher/main/docs/_templates/custom-template.html", "show_prev_next": False, - "navbar_start": ["navbar-logo"], + "navbar_start": ["navbar-logo", "version-switcher"], + "switcher": { + "json_url": "https://patcher.liquidzoo.io/_static/switcher.json", + "version_match": version, + }, "navbar_center": ["navbar-nav"], "navbar_end": ["theme-switcher", "navbar-icon-links"], "icon_links": [