Skip to content
Merged
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
56 changes: 45 additions & 11 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,17 @@ on:
paths:
- 'weac/**'
- 'docs/sphinx/**'
- 'pyproject.toml'
- 'README.md'
- '.github/workflows/docs.yml'
pull_request:
branches: [ main, develop ]
paths:
- 'weac/**'
- 'docs/sphinx/**'
- 'pyproject.toml'
- 'README.md'
- '.github/workflows/docs.yml'
workflow_dispatch:

permissions:
Expand Down Expand Up @@ -37,14 +46,17 @@ jobs:

- name: Build documentation
run: |
# Clean any previous build artifacts
make -C docs/sphinx clean

# Generate API docs
sphinx-apidoc -o docs/sphinx/ weac --force --separate

# Build HTML docs (do not fail on warnings)
make -C docs/sphinx clean html SPHINXOPTS="--keep-going -n"

# Build HTML docs (do not fail on warnings)
make -C docs/sphinx clean html SPHINXOPTS="--keep-going -n"
make -C docs/sphinx html SPHINXOPTS="--keep-going -n"
# Ensure .nojekyll file exists for GitHub Pages
touch docs/sphinx/_build/html/.nojekyll

- name: Deploy documentation
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
Expand All @@ -53,9 +65,18 @@ jobs:
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"

# Build verification - ensure required files exist
if [ ! -f docs/sphinx/_build/html/index.html ]; then
echo "Build output missing (docs/sphinx/_build/html/index.html not found). Aborting deploy."
exit 1
fi

echo "Build verification passed - index.html found"

# Prepare a clean worktree for the documentation branch
git worktree remove -f docs-deploy || true
git worktree prune

# Ensure we know about the remote branch if it exists
git fetch origin documentation || true
if git show-ref --verify --quiet refs/remotes/origin/documentation; then
Expand All @@ -65,22 +86,35 @@ jobs:
# Create a new local 'documentation' branch starting from current HEAD (content will be replaced)
git worktree add --force -b documentation docs-deploy HEAD
fi
# Copy built HTML to the worktree root
if [ ! -f docs/sphinx/_build/html/index.html ]; then
echo "Build output missing (docs/sphinx/_build/html/index.html not found). Aborting deploy."
exit 1

# Clean the documentation branch but preserve .gitignore if it exists
pushd docs-deploy
# Preserve .gitignore if it exists
if [ -f .gitignore ]; then
cp .gitignore /tmp/preserve-gitignore
fi
git rm -rf . || true
git clean -fxd
# Restore .gitignore if it existed
if [ -f /tmp/preserve-gitignore ]; then
cp /tmp/preserve-gitignore .gitignore
rm /tmp/preserve-gitignore
fi
popd

# Create proper directory structure for GitHub Pages
mkdir -p docs-deploy/docs

# Copy files to deployment directory
cp -r docs/sphinx/_build/html/* docs-deploy/
# Copy built HTML to the docs directory (for GitHub Pages)
cp -r docs/sphinx/_build/html/* docs-deploy/docs/

pushd docs-deploy
git add -A
if git diff --cached --quiet; then
echo "No changes to publish"
exit 0
else
git commit -m "Update documentation"
git commit -m "Update documentation" -m "🪬 Generated with Sphinx from main branch"
git fetch origin documentation --quiet || true
git push --force-with-lease origin HEAD:documentation
fi
Expand Down