Skip to content

Commit 18fde6e

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 18fde6e

1 file changed

Lines changed: 108 additions & 0 deletions

File tree

.github/workflows/docs.yml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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. wait-for-pages-deployment blocks until Pages
70+
# has actually rebuilt with the new content before posting the PR
71+
# comment/link, otherwise the link 404s for whatever GitHub Pages'
72+
# build lag happens to be.
73+
- name: Deploy or remove PR preview
74+
uses: rossjrw/pr-preview-action@v1
75+
with:
76+
source-dir: ./_site
77+
wait-for-pages-deployment: true
78+
79+
deploy:
80+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
81+
runs-on: ubuntu-latest
82+
permissions:
83+
contents: write
84+
steps:
85+
- uses: actions/checkout@v4
86+
87+
- uses: actions/setup-python@v5
88+
with:
89+
python-version: '3'
90+
91+
- name: Install package doc generator dependencies
92+
run: pip install -r docs/requirements.txt
93+
94+
- name: Generate package pages from YAML
95+
run: python docs/packages/generate_packages_doc.py
96+
97+
- name: Build with Jekyll
98+
uses: actions/jekyll-build-pages@v1
99+
with:
100+
source: ./docs
101+
destination: ./_site
102+
103+
- name: Deploy to GitHub Pages
104+
uses: peaceiris/actions-gh-pages@v4
105+
with:
106+
github_token: ${{ secrets.GITHUB_TOKEN }}
107+
publish_dir: ./_site
108+
keep_files: true

0 commit comments

Comments
 (0)