Skip to content

Add versioned docs to GitHub Pages #8

Add versioned docs to GitHub Pages

Add versioned docs to GitHub Pages #8

Workflow file for this run

name: Deploy Sphinx docs to GitHub Pages
on:
push:
branches: [master]
tags: ['v*']
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: pip install sphinx sphinx-rtd-theme
- name: Build latest docs from master
run: |
mkdir -p _site/latest
sphinx-build -b html docs _site/latest
- name: Build docs for each release tag
run: |
for tag in $(git tag --list 'v*' --sort=-version:refname); do
echo "Building docs for $tag"
git checkout "$tag" -- docs/ solr/ 2>/dev/null || continue
version_dir="_site/${tag}"
mkdir -p "$version_dir"
sphinx-build -b html docs "$version_dir" 2>/dev/null || echo " Skipped $tag (build failed)"
git checkout master -- docs/ solr/ 2>/dev/null
done
- name: Generate version index page
run: |
LATEST_TAG=$(git tag --list 'v*' --sort=-version:refname | head -1)
cat > _site/index.html << 'HEADER'
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>solrpy Documentation</title>
<style>
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; max-width: 700px; margin: 60px auto; padding: 0 20px; color: #333; }
h1 { border-bottom: 2px solid #2980b9; padding-bottom: 10px; }
a { color: #2980b9; text-decoration: none; }
a:hover { text-decoration: underline; }
ul { list-style: none; padding: 0; }
li { padding: 8px 0; border-bottom: 1px solid #eee; }
.latest { font-weight: bold; }
.badge { background: #2980b9; color: #fff; padding: 2px 8px; border-radius: 4px; font-size: 0.8em; margin-left: 8px; }
</style>
</head>
<body>
<h1>solrpy Documentation</h1>
<p><a href="latest/">Latest (master)</a></p>
<h2>Versions</h2>
<ul>
HEADER
for tag in $(git tag --list 'v*' --sort=-version:refname); do
if [ -d "_site/${tag}" ]; then
badge=""
if [ "$tag" = "$LATEST_TAG" ]; then
badge='<span class="badge">latest release</span>'
fi
echo " <li><a href=\"${tag}/\">${tag}</a>${badge}</li>" >> _site/index.html
fi
done
cat >> _site/index.html << 'FOOTER'
</ul>
<hr>
<p><a href="https://github.com/search5/solrpy">GitHub</a> · <a href="https://pypi.org/project/solrpy/">PyPI</a></p>
</body>
</html>
FOOTER
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: _site
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4