|
1 | 1 | # improved-octo-fortnight |
2 | 2 |
|
3 | | -A reference implementation of a documentation workflow using [zensical](https://zensical.org/) and GitHub Pages. |
| 3 | +[![GitHub Release][release-badge]][release-url] |
| 4 | +[![GitHub Pages][pages-badge]][pages-url] |
4 | 5 |
|
5 | | -- [latest](https://taisakuma.github.io/improved-octo-fortnight/latest/) |
6 | | -- [dev](https://taisakuma.github.io/improved-octo-fortnight/dev/) |
| 6 | +[![Deploy dev docs][dev-badge]][dev-url] |
| 7 | +[![Deploy release docs][release-docs-badge]][release-docs-url] |
| 8 | +[![Deploy docs preview][preview-badge]][preview-url] |
| 9 | + |
| 10 | +[release-badge]: https://img.shields.io/github/v/release/TaiSakuma/improved-octo-fortnight |
| 11 | +[release-url]: https://github.com/TaiSakuma/improved-octo-fortnight/releases/latest |
| 12 | +[pages-badge]: https://img.shields.io/website?url=https://taisakuma.github.io/improved-octo-fortnight/ |
| 13 | +[pages-url]: https://taisakuma.github.io/improved-octo-fortnight/ |
| 14 | +[dev-badge]: https://github.com/TaiSakuma/improved-octo-fortnight/actions/workflows/docs-dev.yml/badge.svg |
| 15 | +[dev-url]: https://github.com/TaiSakuma/improved-octo-fortnight/actions/workflows/docs-dev.yml |
| 16 | +[release-docs-badge]: https://github.com/TaiSakuma/improved-octo-fortnight/actions/workflows/docs-release.yml/badge.svg |
| 17 | +[release-docs-url]: https://github.com/TaiSakuma/improved-octo-fortnight/actions/workflows/docs-release.yml |
| 18 | +[preview-badge]: https://github.com/TaiSakuma/improved-octo-fortnight/actions/workflows/docs-pr-preview.yml/badge.svg |
| 19 | +[preview-url]: https://github.com/TaiSakuma/improved-octo-fortnight/actions/workflows/docs-pr-preview.yml |
| 20 | + |
| 21 | +A reference implementation of documentation workflows. |
| 22 | + |
| 23 | +📚 [Demo site](https://taisakuma.github.io/improved-octo-fortnight/) |
7 | 24 |
|
8 | 25 | ## Features |
9 | 26 |
|
10 | | -- **Versioned docs** -- Release docs at `/<version>/`, dev docs at `/dev/`, and a `/latest/` alias |
11 | | -- **PR previews** -- Every PR gets a preview deployment at `/pr/<number>/` with an automatic comment linking to it |
12 | | -- **PR cleanup** -- Preview deployments are removed when PRs are closed |
13 | | -- **Version index** -- An auto-generated root `index.html` lists all available versions |
14 | | -- **Deploy verification** -- The preview URL is polled before posting the PR comment; a note is added if the site isn't ready yet |
15 | | -- **Custom domain support** -- Works with both default GitHub Pages URLs and custom domains |
16 | | -- **API reference** -- Auto-generated from Python docstrings using [mkdocstrings](https://mkdocstrings.github.io/). Add `:::` directives in Markdown to render any module (see `docs/api.md` for an example) |
| 27 | +### Content |
17 | 28 |
|
18 | | -## How it works |
| 29 | +- Built with [zensical](https://zensical.org/) |
| 30 | +- API reference auto-generated using [mkdocstrings](https://mkdocstrings.github.io/) |
19 | 31 |
|
20 | | -Documentation is built with [zensical](https://zensical.org/) and deployed by pushing subdirectories to a `gh-pages` branch. Four workflows handle the different deployment scenarios: |
| 32 | +This repo documents a Python package. The setup should work for other languages with minor modifications. |
21 | 33 |
|
22 | | -| Workflow | Trigger | Deploys to | |
23 | | -| --------------------- | -------------------------------- | ----------------------------------------- | |
24 | | -| `docs-dev.yml` | Push to `main` | `/dev/` | |
25 | | -| `docs-release.yml` | Release (via changelog workflow) | `/<version>/` + `/latest/` + `index.html` | |
26 | | -| `docs-pr-preview.yml` | PR opened/updated (incl. forks) | `/pr/<number>/` | |
27 | | -| `docs-pr-cleanup.yml` | PR closed | removes `/pr/<number>/` | |
| 34 | +### Deployment |
28 | 35 |
|
29 | | -The `gh-pages` branch has the following structure: |
| 36 | +- Deployed to [GitHub Pages](https://pages.github.com/) via [GitHub |
| 37 | + Actions](https://github.com/features/actions) |
| 38 | +- Separate docs for each release and development branch |
| 39 | +- Docs preview for each PR |
30 | 40 |
|
31 | | -``` |
32 | | -gh-pages |
33 | | -├── .nojekyll |
| 41 | +## GitHub Pages structure |
| 42 | + |
| 43 | +The deployed site is structured as follows: |
| 44 | + |
| 45 | +```text |
| 46 | +/ |
34 | 47 | ├── index.html # auto-generated version index |
35 | 48 | ├── latest/ # copy of the latest release |
36 | 49 | ├── dev/ # built from main |
37 | | -├── 0.2.1/ # release versions |
38 | | -├── 0.2.0/ |
| 50 | +├── 2.0.0/ # release versions |
| 51 | +├── 1.1.0/ |
| 52 | +├── 1.0.0/ |
39 | 53 | └── pr/ |
40 | 54 | ├── 14/ # PR preview |
41 | 55 | └── 13/ |
42 | 56 | ``` |
43 | 57 |
|
44 | | -Shared logic is extracted into two composite actions: |
| 58 | +## GitHub Actions workflows |
| 59 | + |
| 60 | +These workflows build, deploy, and clean up the documentation: |
45 | 61 |
|
46 | | -- **`.github/actions/build-docs`** -- Overrides `site_url` for the target subdirectory, builds the site, and stages the output |
47 | | -- **`.github/actions/deploy-to-gh-pages`** -- Checks out (or creates) the `gh-pages` branch and pushes the built site to a target subdirectory |
| 62 | +| Workflow | Trigger | Deploys to | |
| 63 | +| ----------------------- | ----------------- | --------------------------------------- | |
| 64 | +| [`docs-dev.yml`] | Push to `main` | `/dev/`, `index.html` | |
| 65 | +| [`docs-release.yml`] | Release | `/<version>/`, `/latest/`, `index.html` | |
| 66 | +| [`docs-pr-preview.yml`] | PR opened/updated | `/pr/<number>/` | |
| 67 | +| [`docs-pr-cleanup.yml`] | PR closed | removes `/pr/<number>/` | |
48 | 68 |
|
49 | | -A Python script (`.github/actions/build-docs/override_site_url.py`) uses [tomlkit](https://github.com/sdispater/tomlkit) to modify `site_url` in `zensical.toml` so that navigation and search work correctly in each subdirectory. |
| 69 | +[`docs-dev.yml`]: .github/workflows/docs-dev.yml |
| 70 | +[`docs-release.yml`]: .github/workflows/docs-release.yml |
| 71 | +[`docs-pr-preview.yml`]: .github/workflows/docs-pr-preview.yml |
| 72 | +[`docs-pr-cleanup.yml`]: .github/workflows/docs-pr-cleanup.yml |
50 | 73 |
|
51 | | -## Setup |
| 74 | +The workflows require the GitHub settings |
52 | 75 |
|
53 | | -1. Install [uv](https://docs.astral.sh/uv/) |
54 | | -2. Build docs locally: |
55 | | - ``` |
56 | | - uv run --group docs zensical serve |
57 | | - ``` |
58 | | -3. Set GitHub Pages source to **Deploy from a branch** > `gh-pages` (root `/`) |
| 76 | +- `Settings` > `Pages` > `Source` > `Deploy from a branch` > `gh-pages` (root `/`) |
0 commit comments