Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions .github/actions/deploy-to-gh-pages/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ runs:
- id: deploy
shell: bash
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
TARGET="${{ inputs.target }}"
git fetch origin gh-pages 2>/dev/null || true
if git rev-parse --verify origin/gh-pages >/dev/null 2>&1; then
Expand Down
22 changes: 22 additions & 0 deletions .github/actions/update-index/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Update index.html
description: Regenerate index.html, commit and push

inputs:
repo-name:
description: Repository name for the index page title
required: true
repo-url:
description: Repository URL for the GitHub link
required: true

runs:
using: composite
steps:
- shell: bash
run: |
python "${{ github.action_path }}/generate_index.py" \
"${{ inputs.repo-name }}" \
"${{ inputs.repo-url }}"
git add index.html
git diff --cached --quiet || git commit -m "Update index.html"
git push origin gh-pages
57 changes: 57 additions & 0 deletions .github/actions/update-index/generate_index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'''Generate index.html listing all doc versions on gh-pages.'''
import re
import sys
from pathlib import Path
from string import Template


def find_versions() -> list[str]:
'''Find version directories (e.g., 0.2.1, 1.0.0) sorted descending.'''
dirs = [
d.name for d in Path('.').iterdir()
if d.is_dir() and re.match(r'\d', d.name)
]
dirs.sort(key=lambda v: [int(x) for x in v.split('.')], reverse=True)
return dirs


def find_latest_version(versions: list[str]) -> str | None:
'''Return the version that /latest/ points to, if any.'''
if not versions or not Path('latest').is_dir():
return None
return versions[0]


def build_version_list(versions: list[str], latest_version: str | None) -> str:
'''Build HTML list items for all versions.'''
lines: list[str] = []
if latest_version:
lines.append(f' <li><a href="latest/">latest</a> <span class="meta">({latest_version})</span></li>')
if Path('dev').is_dir():
lines.append(' <li><a href="dev/">dev</a></li>')
for v in versions:
lines.append(f' <li><a href="{v}/">{v}</a></li>')
return '\n'.join(lines)


def main() -> None:
repo_name = sys.argv[1]
repo_url = sys.argv[2]

template_path = Path(__file__).parent / 'index.html'
template = Template(template_path.read_text())

versions = find_versions()
latest_version = find_latest_version(versions)
version_list = build_version_list(versions, latest_version)

html = template.substitute(
repo_name=repo_name,
repo_url=repo_url,
version_list=version_list,
)

Path('index.html').write_text(html)


main()
33 changes: 33 additions & 0 deletions .github/actions/update-index/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>$repo_name</title>
<style>
body {
font-family: system-ui, sans-serif;
max-width: 600px;
margin: 2rem auto;
padding: 0 1rem;
}
a { color: #1a73e8; text-decoration: none; }
a:hover { text-decoration: underline; }
ul { list-style: none; padding: 0; }
li { padding: 0.3rem 0; }
.meta { color: #666; font-size: 0.9rem; }
footer { margin-top: 2rem; font-size: 0.9rem; }
@media (prefers-color-scheme: dark) {
body { background: #1a1a1a; color: #e0e0e0; }
a { color: #8ab4f8; }
.meta { color: #999; }
}
</style>
</head>
<body>
<h1>$repo_name documentation</h1>
<ul>
$version_list
</ul>
<footer><a href="$repo_url">GitHub</a></footer>
</body>
</html>
10 changes: 10 additions & 0 deletions .github/workflows/docs-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,18 @@ jobs:
with:
subdir: dev

- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

- uses: ./.github/actions/deploy-to-gh-pages
with:
site-dir: ${{ steps.build.outputs.site-dir }}
target: dev
commit-message: Deploy dev docs

- uses: ./.github/actions/update-index
with:
repo-name: ${{ github.event.repository.name }}
repo-url: ${{ github.event.repository.html_url }}
5 changes: 4 additions & 1 deletion .github/workflows/docs-pr-cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ jobs:
steps:
- uses: actions/checkout@v6

- name: Remove PR preview
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

- name: Remove PR preview
run: |
git fetch origin gh-pages 2>/dev/null || true
if ! git rev-parse --verify origin/gh-pages >/dev/null 2>&1; then
echo "gh-pages branch does not exist, nothing to clean up"
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/docs-pr-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ jobs:
name: docs-preview
path: ${{ env.SITE_DIR }}

- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

# Reference the action from @main so deploy logic always comes from the
# trusted main branch.
- uses: TaiSakuma/improved-octo-fortnight/.github/actions/deploy-to-gh-pages@main
Expand Down
33 changes: 13 additions & 20 deletions .github/workflows/docs-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,25 @@ jobs:
with:
subdir: ${{ steps.version.outputs.version }}

- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

- uses: ./.github/actions/deploy-to-gh-pages
with:
site-dir: ${{ steps.build.outputs.site-dir }}
target: ${{ steps.version.outputs.version }}
commit-message: Deploy docs for v${{ steps.version.outputs.version }}

- name: Update latest and index.html
- name: Update latest
run: |
TARGET="${{ steps.version.outputs.version }}"
rm -rf latest
cp -r "${{ steps.build.outputs.site-dir }}" latest
# Generate root index.html
REPO_NAME="${{ github.event.repository.name }}"
{
echo '<!DOCTYPE html>'
echo "<html><head><meta charset=\"utf-8\"><title>${REPO_NAME}</title></head>"
echo "<body><h1>${REPO_NAME} documentation</h1><ul>"
echo '<li><a href="latest/">latest</a></li>'
if [ -d dev ]; then
echo '<li><a href="dev/">dev</a></li>'
fi
for d in $(find . -maxdepth 1 -type d -name '[0-9]*' | sed 's|^\./||' | sort -rV); do
echo "<li><a href=\"$d/\">$d</a></li>"
done
echo '</ul></body></html>'
} > index.html
git add latest index.html
git diff --cached --quiet || git commit -m "Update latest and index.html for v${TARGET}"
git push origin gh-pages
git add latest
git commit -m "Update latest"

- uses: ./.github/actions/update-index
with:
repo-name: ${{ github.event.repository.name }}
repo-url: ${{ github.event.repository.html_url }}
Loading