Skip to content

Commit 9418191

Browse files
committed
workflows: docs: add
Create a custom workflow for deploying our documentation to GitHub Pages. This allows us to retain the original YAML-to-documentation generation process we've used in the past, and stops us from relying solely on files already being on the main branch for documentation build and review. We have to incorporate two new community actions for this: 1. `peaceiris/actions-gh-pages`, for deploying the actual docs using a `gh-pages` branch 2. `rossjrew/pr-preview-action`, for creating docs previews so we're able to review the changes before merge. Comments will be posted on the PR providing preview links. The `gh-pages` branch also requires a `.nojekyll` file at the project root to avoid a manual rebuild, which can take a lot of time. Finally, the `Deploy from a branch` option in the Pages setting needs to point at `root/`, not `docs/` or it won't find the `.nojekyll` file. AI-Generated: Uses Claude Sonnet 5 Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com>
1 parent d7eb49c commit 9418191

1 file changed

Lines changed: 113 additions & 0 deletions

File tree

.github/workflows/docs.yml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# SPDX-FileCopyrightText: 2026 The RISE Project
2+
# SPDX-License-Identifier: MIT
3+
4+
name: Build and deploy documentation
5+
6+
on:
7+
push:
8+
branches: [main]
9+
paths:
10+
- "docs/**"
11+
pull_request:
12+
types: [opened, synchronize, reopened, closed]
13+
workflow_dispatch:
14+
15+
concurrency:
16+
group: docs-${{ github.ref }}
17+
18+
jobs:
19+
preview:
20+
if: github.event_name == 'pull_request'
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: write
24+
pull-requests: write
25+
steps:
26+
- uses: actions/checkout@v4
27+
28+
- uses: actions/setup-python@v5
29+
if: github.event.action != 'closed'
30+
with:
31+
python-version: '3'
32+
33+
- name: Install package doc generator dependencies
34+
if: github.event.action != 'closed'
35+
run: pip install -r docs/requirements.txt
36+
37+
- name: Generate package pages from YAML
38+
if: github.event.action != 'closed'
39+
run: python docs/packages/generate_packages_doc.py
40+
41+
- name: Compute preview baseurl
42+
if: github.event.action != 'closed'
43+
id: preview_baseurl
44+
run: |
45+
base=$(python3 -c "import yaml; print(yaml.safe_load(open('docs/_config.yml'))['baseurl'])")
46+
echo "value=${base}/pr-preview/pr-${{ github.event.number }}" >> "$GITHUB_OUTPUT"
47+
48+
- uses: ruby/setup-ruby@v1
49+
if: github.event.action != 'closed'
50+
with:
51+
ruby-version: '3.3'
52+
53+
# actions/jekyll-build-pages has no way to override _config.yml's
54+
# hardcoded baseurl, but a preview is served one path segment deeper
55+
# (.../pr-preview/pr-<N>/) than the production site, so it needs its
56+
# own baseurl or every internal link/asset would point at production.
57+
- name: Build with Jekyll
58+
if: github.event.action != 'closed'
59+
run: |
60+
# jekyll-remote-theme only fetches just-the-docs' layouts/assets;
61+
# its own gem dependencies (jekyll-seo-tag, jekyll-include-cache,
62+
# rake) still have to be installed separately.
63+
gem install jekyll jekyll-remote-theme jekyll-seo-tag jekyll-include-cache rake --no-document
64+
jekyll build --source docs --destination _site \
65+
--baseurl "${{ steps.preview_baseurl.outputs.value }}"
66+
67+
# Auto-detects deploy vs. removal from the pull_request event action,
68+
# so this same step both publishes updates and tears down the preview
69+
# when the PR is closed.
70+
#
71+
# wait-for-pages-deployment is deliberately left at its default
72+
# (false): on classic "deploy from a branch" Pages, its lookup against
73+
# the legacy Pages Builds API doesn't reliably find an exact-commit
74+
# build within its hardcoded 180s timeout, and that timeout is a hard,
75+
# non-configurable `exit 1` that fails the whole step/PR check even
76+
# when the preview deployed and is serving correctly. A link that's
77+
# occasionally not live for a few seconds is a smaller problem than a
78+
# misleading red X on an otherwise-working PR.
79+
- name: Deploy or remove PR preview
80+
uses: rossjrw/pr-preview-action@v1
81+
with:
82+
source-dir: ./_site
83+
84+
deploy:
85+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
86+
runs-on: ubuntu-latest
87+
permissions:
88+
contents: write
89+
steps:
90+
- uses: actions/checkout@v4
91+
92+
- uses: actions/setup-python@v5
93+
with:
94+
python-version: '3'
95+
96+
- name: Install package doc generator dependencies
97+
run: pip install -r docs/requirements.txt
98+
99+
- name: Generate package pages from YAML
100+
run: python docs/packages/generate_packages_doc.py
101+
102+
- name: Build with Jekyll
103+
uses: actions/jekyll-build-pages@v1
104+
with:
105+
source: ./docs
106+
destination: ./_site
107+
108+
- name: Deploy to GitHub Pages
109+
uses: peaceiris/actions-gh-pages@v4
110+
with:
111+
github_token: ${{ secrets.GITHUB_TOKEN }}
112+
publish_dir: ./_site
113+
keep_files: true

0 commit comments

Comments
 (0)