Skip to content

Commit 02216db

Browse files
authored
ci(docs): build the docs site in Actions and stop committing generated docs (#2874)
* ci(docs): build the docs site in Actions and stop committing generated docs Stop tracking docs build output and let .github/workflows/docs.yml build and publish it, so docs PRs stop conflicting on docs/search-index.json and docs/llms-full.txt (output computed from every page, never from the page the PR touches). - remove docs/*.html, docs/.nojekyll, docs/assets/, docs/llms.txt, docs/llms-full.txt, docs/search-index.json from the tree (history kept) and gitignore them; main now tracks only docs/*.md + docs/nav.json - docs.yml: build on push to main for docs/** + workflow_dispatch, concurrency group docs, contents:read on build, pages:write/id-token:write only on deploy, upload-pages-artifact + deploy-pages, no commit-back, explicit --repo-url, and if: github.ref == 'refs/heads/main' on both jobs so a manual run cannot publish a branch - docs-guard.yml: fail a PR that adds/modifies/copies/renames any docs path except **/*.md and nav.json (deletions allowed — the migration is a deletion); -z diff parsing so non-ASCII and newline-containing paths cannot slip through - CONTRIBUTING.md/AGENTS.md: edit the .md, never run pi-docsite in a PR; drop the now-dead generated-docs globs from .pr_agent.toml Refs #2873 Assisted-by: PI (rits/deepseek-ai/DeepSeek-V4.1-Flash-1017) Signed-off-by: Meni Yakove <myakove@gmail.com> * fix(docs): harden the docs workflows per review - guard: run on pull_request_target and read the changed paths from the REST API instead of a git diff, so a PR can no longer rewrite the check that inspects it (a pull_request workflow definition comes from the PR under review). Nothing is checked out, so no PR code executes; typechanges and non-ASCII/newline paths are covered as API statuses and JSON strings - docs.yml: pin pi-docsite@4.18.0 — the build output is what `deploy` publishes, so @latest would let an upstream release change the live site with no commit here; persist-credentials: false on checkout so the token is not left in .git/config for the third-party generator; rebuild when docs.yml itself changes (it carries the tagline) - CONTRIBUTING.md: pin the local build command to the same version Refs #2873 Assisted-by: PI (rits/deepseek-ai/DeepSeek-V4.1-Flash-1017) Signed-off-by: Meni Yakove <myakove@gmail.com> * docs(contributing): document the Pages publishing prerequisites The docs guard and the deletion of the generated output only make sense when Pages builds from the workflow: record how to check build_type, that Pages keeps serving the last successful deployment until the next one replaces it, that the merge push is what triggers the first workflow deploy, and the live-URL check. Refs #2873 Assisted-by: PI (rits/deepseek-ai/DeepSeek-V4.1-Flash-1017) Signed-off-by: Meni Yakove <myakove@gmail.com> * fix(docs): fail closed when a PR is too large for the files API The changed-files endpoint returns at most 3,000 entries, so on a larger PR a generated docs path could sit outside the returned set and the guard would report a pass without having listed it. Read changed_files from the PR object first and refuse to certify anything above the cap, with a message pointing at manual review. Refs #2873 Assisted-by: PI (rits/deepseek-ai/DeepSeek-V4.1-Flash-1017) Signed-off-by: Meni Yakove <myakove@gmail.com> * docs(contributing): verify the live page matches the build, not just HTTP 200 Pages keeps serving the last successful deployment when a new one fails, so a 200 on quickstart.html can describe the previous page. Document comparing the served page with a local build of the merged commit, alongside the workflow run lookup, and say why a status code alone is not a freshness check. Refs #2873\n\nAssisted-by: PI (rits/deepseek-ai/DeepSeek-V4.1-Flash-1017) Signed-off-by: Meni Yakove <myakove@gmail.com> --------- Signed-off-by: Meni Yakove <myakove@gmail.com>
1 parent 24c632f commit 02216db

40 files changed

Lines changed: 212 additions & 33283 deletions

‎.github/workflows/docs-guard.yml‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Docs Guard
2+
3+
# pull_request_target, NOT pull_request: with `pull_request` the workflow definition is taken from
4+
# the PR under review, so a PR could keep this job's name and replace the check with `exit 0` in the
5+
# same change that adds generated docs. `pull_request_target` always runs the copy on the base
6+
# branch, so the check cannot be rewritten by the change it is checking.
7+
#
8+
# Nothing from the PR is checked out or executed: the changed paths are read from the REST API and
9+
# filtered in jq. That keeps PR code (and a repository token in .git/config) out of reach, and it
10+
# sidesteps git's path quoting — an API path arrives as a JSON string, so a non-ASCII or
11+
# newline-containing name cannot dodge the patterns below.
12+
#
13+
# Consequence: because the base branch has no copy of this file yet, the check does not run on the
14+
# PR that introduces it; it applies to every PR opened after it lands.
15+
on: pull_request_target
16+
17+
permissions:
18+
pull-requests: read
19+
20+
jobs:
21+
no-generated-docs:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Reject generated docs in the PR
25+
env:
26+
GH_TOKEN: ${{ github.token }}
27+
GH_REPO: ${{ github.repository }}
28+
PR_NUMBER: ${{ github.event.pull_request.number }}
29+
run: |
30+
set -euo pipefail
31+
offenders="$(mktemp)"
32+
trap 'rm -f "$offenders"' EXIT
33+
34+
# The files endpoint stops at 3,000 entries, so on a bigger PR a generated path could sit
35+
# outside the returned set and an "all clean" reading would certify what was never listed.
36+
# Fail closed: such a PR is reviewed by a maintainer, not silently passed.
37+
changed_files="$(gh api "repos/${GH_REPO}/pulls/${PR_NUMBER}" --jq '.changed_files')"
38+
if [ "${changed_files:-0}" -gt 3000 ]; then
39+
echo "::error::This PR changes ${changed_files} files, above the 3,000-file API limit — the docs guard cannot list them all. Split the PR, or ask a maintainer to check the docs paths by hand."
40+
exit 1
41+
fi
42+
43+
# Only added/modified/renamed/copied files are a violation: a DELETION is the migration
44+
# itself (removing the committed output) and must pass, or the PR that fixes the rule can
45+
# never satisfy it. A rename or copy is checked on BOTH sides, so
46+
# docs/foo.md -> docs/index.html is caught too. A type change (file -> symlink) arrives as
47+
# `modified`, which is included.
48+
#
49+
# Inverted allowlist: docs/**/*.md and docs/nav.json are the sources; everything else under
50+
# docs/ is what .github/workflows/docs.yml builds. Each offender is emitted with @json so a
51+
# path containing a newline stays on one line instead of splitting into two non-matching
52+
# ones.
53+
if ! gh api --paginate -H "Accept: application/vnd.github+json" \
54+
"repos/${GH_REPO}/pulls/${PR_NUMBER}/files?per_page=100" \
55+
--jq '
56+
.[]
57+
| select(.status != "removed")
58+
| ((.previous_filename // empty), .filename)
59+
| select(startswith("docs/"))
60+
| select(. != "docs/nav.json")
61+
| select(endswith(".md") | not)
62+
| @json
63+
' > "$offenders"; then
64+
# A listing that never ran must not be read as "nothing found".
65+
echo "::error::could not list the pull request changed files — refusing to report a pass."
66+
exit 1
67+
fi
68+
69+
if [ -s "$offenders" ]; then
70+
echo "::error::Generated docs must not be committed — the site is built on main from the docs sources."
71+
while IFS= read -r line; do echo " $line"; done < "$offenders"
72+
echo "Everything under docs/ other than docs/**/*.md and docs/nav.json is build output of"
73+
echo ".github/workflows/docs.yml — edit the markdown source instead."
74+
exit 1
75+
fi
76+
echo "No generated docs in the diff."

‎.github/workflows/docs.yml‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Docs
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
# Any docs change, not just .md: the migration that removes the committed output touches
8+
# only generated paths, and it must still deploy. The workflow file is listed because it
9+
# carries the tagline, so editing it changes the built site.
10+
- "docs/**"
11+
- ".github/workflows/docs.yml"
12+
# The first deploy after Pages is switched to build_type=workflow has no push to ride on.
13+
workflow_dispatch:
14+
15+
concurrency:
16+
group: docs
17+
cancel-in-progress: true
18+
19+
permissions:
20+
contents: read
21+
22+
jobs:
23+
build:
24+
# workflow_dispatch accepts any ref, so without this guard `gh workflow run docs.yml --ref
25+
# some-branch` would publish that branch's docs/ to the live Pages site. Deploying is main-only;
26+
# a manual run is still how the first deploy after the Pages switch is triggered.
27+
if: github.ref == 'refs/heads/main'
28+
runs-on: ubuntu-latest
29+
# Building needs nothing but the sources: publish rights live on the deploy job alone, so
30+
# whatever the build step runs can never reach Pages.
31+
permissions:
32+
contents: read
33+
steps:
34+
- uses: actions/checkout@v4
35+
with:
36+
# The build runs a third-party generator; leaving the token in .git/config would hand it
37+
# to that process for the rest of the job.
38+
persist-credentials: false
39+
- uses: astral-sh/setup-uv@v6
40+
- name: Build site from docs/*.md
41+
# Pinned, because this job's output is what `deploy` publishes: `@latest` would let a new
42+
# upstream release change the live site with no commit here. Bump deliberately (and bump
43+
# CONTRIBUTING.md's command with it) after reviewing the release.
44+
# --repo-url is explicit on purpose: pi-docsite otherwise derives it from `origin`, and a
45+
# build from a fork rewrites every repository link.
46+
run: >-
47+
uvx pi-docsite@4.18.0 --docs-dir docs
48+
--repo-url https://github.com/RedHatQE/openshift-python-wrapper
49+
--tagline "Manage OpenShift and Kubernetes resources with clean, Pythonic code instead of raw API calls"
50+
- uses: actions/upload-pages-artifact@v3
51+
with:
52+
path: docs
53+
54+
deploy:
55+
needs: build
56+
if: github.ref == 'refs/heads/main'
57+
runs-on: ubuntu-latest
58+
# The only job that publishes.
59+
permissions:
60+
pages: write
61+
id-token: write
62+
environment:
63+
name: github-pages
64+
url: ${{ steps.deployment.outputs.page_url }}
65+
steps:
66+
- id: deployment
67+
uses: actions/deploy-pages@v4

‎.gitignore‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,14 @@ class_generator/schema/__resources-mappings.json
146146

147147
# graft's local graph cache — regenerable, not committed (run `graft build`).
148148
/graft/
149+
150+
# Docs build output: generated by pi-docsite in .github/workflows/docs.yml and published by Pages.
151+
# Only docs/*.md and docs/nav.json are tracked — never commit anything below.
152+
# .nojekyll is the legacy branch-build marker; artifact deploys skip Jekyll, so it must not come
153+
# back either (src: .github/workflows/docs-guard.yml rejects it).
154+
docs/*.html
155+
docs/.nojekyll
156+
docs/assets/
157+
docs/llms.txt
158+
docs/llms-full.txt
159+
docs/search-index.json

‎.pr_agent.toml‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,3 @@ push_commands = ["/agentic_review"]
1010
[review_agent]
1111
comments_location_policy = "both"
1212
inline_comments_severity_threshold = 1
13-
14-
[ignore]
15-
glob = [
16-
"docs/*.html",
17-
"docs/search-index.json",
18-
"docs/llms.txt",
19-
"docs/llms-full.txt",
20-
"docs/assets/*.js",
21-
"docs/assets/style.css",
22-
]

‎AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Code between markers is auto-generated — do NOT modify manually. Use `class-ge
7575

7676
- ✅ Always: use `uv` for Python ops, run `prek install` before first commit, add typing
7777
- ⚠️ Ask first: adding new dependencies, modifying base `Resource` class, changing CI
78-
- 🚫 Never: use `python`/`pip` directly, edit generated code between markers, edit generated files in `docs/` (regenerate with pi-docsite instead)
78+
- 🚫 Never: use `python`/`pip` directly, edit generated code between markers, commit generated files under `docs/` (never run pi-docsite in a PR — edit the `.md` and let the Action build it)
7979

8080
## Environment
8181

‎CONTRIBUTING.md‎

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,34 +37,79 @@ prek install
3737

3838
## Documentation
3939

40-
The site under `docs/` is generated by [pi-docsite](https://github.com/myk-org/pi-config/tree/main/packages/pi-docsite).
41-
Edit the Markdown sources, never the generated files:
40+
The site under `docs/` is generated by [pi-docsite](https://github.com/myk-org/pi-config/tree/main/packages/pi-docsite)
41+
and published by `.github/workflows/docs.yml` on every push to `main` that touches `docs/`
42+
(https://redhatqe.github.io/openshift-python-wrapper/).
43+
44+
`main` tracks only the sources:
4245

4346
- sources: `docs/*.md` and the sidebar order in `docs/nav.json`
44-
- generated (do not edit): `docs/*.html`, `docs/search-index.json`, `docs/llms.txt`, `docs/llms-full.txt`, `docs/assets/`
4547

46-
Rebuild the site with one command:
48+
**Never run pi-docsite in a pull request.** Its output is not tracked — the Action builds it on
49+
`main`. `.github/workflows/docs-guard.yml` rejects any PR that adds, modifies, copies or renames a
50+
path under `docs/` other than `**/*.md` and `nav.json` (deletions are allowed).
51+
52+
To build locally for debugging — the output is gitignored, so it never shows up in `git status`:
4753

4854
```bash
49-
uvx pi-docsite --docs-dir docs \
55+
uvx pi-docsite@4.18.0 --docs-dir docs \
5056
--project-name openshift-python-wrapper \
5157
--repo-url https://github.com/RedHatQE/openshift-python-wrapper \
5258
--tagline "Manage OpenShift and Kubernetes resources with clean, Pythonic code instead of raw API calls"
5359
```
5460

55-
`--repo-url` is required in practice: pi-docsite otherwise derives it from the local
56-
`origin`, so building from a fork rewrites every repository link and produces a diff
57-
with no source changes. The tagline is the description shown in the sidebar and in
58-
each page's metadata.
61+
The version is pinned to the one `.github/workflows/docs.yml` publishes with, so a local build
62+
matches the site; bump both together after reviewing a release.
63+
64+
`--repo-url` matters: pi-docsite otherwise derives it from the local `origin`, so building from a
65+
fork rewrites every repository link. The tagline is the description shown in the sidebar and in
66+
each page's metadata; the workflow passes both for the same reason.
67+
68+
The build is deterministic (two runs without source changes are byte-identical), but that is now
69+
the workflow's property, not something a contributor has to prove.
5970

60-
The output is deterministic: running it twice without source changes produces no diff.
71+
Links between pages use the built `<slug>.html` form, because that is what the published site
72+
serves.
73+
74+
### Publishing prerequisites
75+
76+
Pages must be configured for **Actions** (one-time repository setting, not per-PR) — this repo is:
77+
78+
```bash
79+
gh api repos/RedHatQE/openshift-python-wrapper/pages --jq '{build_type, status}'
80+
# {"build_type":"workflow","status":"built"}
81+
```
82+
83+
With `build_type: legacy` the site is served straight from the committed `docs/` on `main`, and
84+
removing that output would take the site down. With `build_type: workflow` the deployed artifact is
85+
the only thing Pages serves, and Pages keeps serving the **last successful deployment** until the
86+
next one replaces it — so a merge that stops tracking the output never leaves a missing page; the
87+
push that merge produces builds and deploys the replacement. Check the live site, not the artifact —
88+
but a status code proves only that *something* is live, not that it is **current**: when a deploy
89+
fails, Pages keeps serving the last successful one, so a `200` can describe the previous page. Build
90+
locally from the merged commit (command above) and compare the served page with it:
91+
92+
```bash
93+
curl -s -o /tmp/live-quickstart.html https://redhatqe.github.io/openshift-python-wrapper/quickstart.html
94+
cmp docs/quickstart.html /tmp/live-quickstart.html && echo "live quickstart.html matches this commit"
95+
gh run list --branch main --workflow docs.yml --limit 1 # the run this check belongs to
96+
```
97+
98+
The first deploy after switching to `build_type: workflow` needs no manual run here: the workflow
99+
does not exist on `main` until the change merges, and that merge push (`docs/**` in the path filter)
100+
is what triggers the build and deploy. `gh workflow run docs.yml` (`workflow_dispatch`) is only for a
101+
re-deploy with no new commit.
61102

62103
Adding a page: create `docs/<slug>.md` and add `<slug>` to `docs/nav.json`. A `.md`
63104
missing from `nav.json` is still built, placed under a fallback group, and reported.
64105

65106
Deleting a page: remove the `.md` **and** its slug from `docs/nav.json`. A slug with no
66-
`.md` behind it is a build error, so the stale entry has to go first — the leftover
67-
`<slug>.html` is then removed by the rebuild.
107+
`.md` behind it is a build error, so the stale entry has to go first.
108+
109+
Branches opened before the generated files were untracked will hit delete/modify conflicts on
110+
exactly those paths. Resolve them by **deleting** (`git rm docs/foo.html docs/search-index.json …`)
111+
and keeping the `.md` edit from the branch. **Never resolve by regenerating** — the regenerated
112+
output reintroduces the conflict and is what the guard now rejects.
68113

69114
## Adding a new module (resource)
70115

‎docs/.nojekyll‎

Whitespace-only changes.

‎docs/assets/callouts.js‎

Lines changed: 0 additions & 26 deletions
This file was deleted.

‎docs/assets/codelabels.js‎

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)