|
| 1 | + |
| 2 | +# OpenAI Guardrails Python — Docs Hosting Setup (MkDocs → GitHub Pages) |
| 3 | + |
| 4 | +Target site: **https://openai.github.io/openai-guardrails-python/** |
| 5 | +Repository: **https://github.com/openai/openai-guardrails-python** |
| 6 | + |
| 7 | +This guide is copy‑pasteable by an AI coding IDE to create files and apply changes automatically. |
| 8 | + |
| 9 | +--- |
| 10 | + |
| 11 | +## Overview |
| 12 | + |
| 13 | +- Build with **MkDocs** (Material theme recommended). |
| 14 | +- Deploy with **GitHub Pages** using **GitHub Actions**. |
| 15 | +- Automatic deployment on push to `main` (after tests succeed). |
| 16 | +- Optional: PR preview URLs for docs changes. |
| 17 | + |
| 18 | +--- |
| 19 | + |
| 20 | +## 0) Prerequisites |
| 21 | + |
| 22 | +- Python 3.10+ available in CI (we’ll use 3.11). |
| 23 | +- MkDocs and any plugins installed in CI (local `make serve-docs` can continue to use your existing dev env). |
| 24 | +- The repository contains your docs in a `docs/` folder (create if missing). |
| 25 | + |
| 26 | +--- |
| 27 | + |
| 28 | +## 1) Project layout (expected) |
| 29 | + |
| 30 | +``` |
| 31 | +openai-guardrails-python/ |
| 32 | +├─ docs/ # Markdown docs live here |
| 33 | +│ └─ index.md |
| 34 | +├─ mkdocs.yml # MkDocs configuration (see below) |
| 35 | +└─ .github/ |
| 36 | + └─ workflows/ |
| 37 | + ├─ docs.yml # Deploy workflow |
| 38 | + └─ docs-preview.yml # (optional) PR preview workflow |
| 39 | +``` |
| 40 | + |
| 41 | +If `docs/` or `.github/workflows/` folders are missing, create them. |
| 42 | + |
| 43 | +--- |
| 44 | + |
| 45 | +## 2) MkDocs configuration |
| 46 | + |
| 47 | +Create or update **`mkdocs.yml`** in the repo root with the following minimal content (merge with your existing file if you have one): |
| 48 | + |
| 49 | +```yaml |
| 50 | +site_name: OpenAI Guardrails Python |
| 51 | +site_url: https://openai.github.io/openai-guardrails-python/ |
| 52 | +repo_url: https://github.com/openai/openai-guardrails-python |
| 53 | +repo_name: openai/openai-guardrails-python |
| 54 | + |
| 55 | +theme: |
| 56 | + name: material |
| 57 | + features: |
| 58 | + - navigation.instant |
| 59 | + - navigation.tracking |
| 60 | + - content.code.copy |
| 61 | + |
| 62 | +nav: |
| 63 | + - Home: index.md |
| 64 | + |
| 65 | +markdown_extensions: |
| 66 | + - admonition |
| 67 | + - codehilite |
| 68 | + - toc: |
| 69 | + permalink: true |
| 70 | +``` |
| 71 | +
|
| 72 | +> **Note:** If you use extra MkDocs plugins locally (e.g., `mkdocstrings[python]`, `mkdocs-section-index`, `mkdocs-literate-nav`), add them here and in the CI install step below. |
| 73 | + |
| 74 | +--- |
| 75 | + |
| 76 | +## 3) Docs index |
| 77 | + |
| 78 | +Create **`docs/index.md`** if missing: |
| 79 | + |
| 80 | +```markdown |
| 81 | +# OpenAI Guardrails Python |
| 82 | +
|
| 83 | +Welcome to the docs for **openai-guardrails-python**. |
| 84 | +``` |
| 85 | + |
| 86 | +(Replace with your actual content.) |
| 87 | + |
| 88 | +--- |
| 89 | + |
| 90 | +## 4) GitHub Pages settings |
| 91 | + |
| 92 | +In the GitHub repo: |
| 93 | + |
| 94 | +1. Go to **Settings → Pages**. |
| 95 | +2. Set **Source** to **GitHub Actions** (not a branch). |
| 96 | +3. No custom domain is required since we publish under `openai.github.io/openai-guardrails-python/`. |
| 97 | + |
| 98 | +--- |
| 99 | + |
| 100 | +## 5) CI: Deploy docs to GitHub Pages |
| 101 | + |
| 102 | +Create **`.github/workflows/docs.yml`** with the following content: |
| 103 | + |
| 104 | +```yaml |
| 105 | +name: Deploy docs |
| 106 | +
|
| 107 | +on: |
| 108 | + # Deploy after the main test workflow finishes successfully |
| 109 | + workflow_run: |
| 110 | + workflows: ["Tests"] # <-- set to your repo's test workflow name |
| 111 | + branches: [ main ] |
| 112 | + types: [ completed ] |
| 113 | +
|
| 114 | +permissions: |
| 115 | + contents: read |
| 116 | + pages: write |
| 117 | + id-token: write |
| 118 | +
|
| 119 | +concurrency: |
| 120 | + group: "pages" |
| 121 | + cancel-in-progress: false |
| 122 | +
|
| 123 | +jobs: |
| 124 | + deploy_docs: |
| 125 | + if: ${{ github.event.workflow_run.conclusion == 'success' }} |
| 126 | + runs-on: ubuntu-latest |
| 127 | + steps: |
| 128 | + - name: Checkout |
| 129 | + uses: actions/checkout@v4 |
| 130 | +
|
| 131 | + - name: Set up Python |
| 132 | + uses: actions/setup-python@v5 |
| 133 | + with: |
| 134 | + python-version: "3.11" |
| 135 | + cache: "pip" |
| 136 | +
|
| 137 | + - name: Install MkDocs and plugins |
| 138 | + run: | |
| 139 | + pip install --upgrade pip |
| 140 | + pip install mkdocs mkdocs-material |
| 141 | + # Add any plugins you use: |
| 142 | + # pip install mkdocstrings[python] mkdocs-section-index mkdocs-literate-nav |
| 143 | +
|
| 144 | + - name: Build site |
| 145 | + run: mkdocs build --strict --site-dir site |
| 146 | +
|
| 147 | + - name: Configure Pages |
| 148 | + uses: actions/configure-pages@v5 |
| 149 | +
|
| 150 | + - name: Upload artifact |
| 151 | + uses: actions/upload-pages-artifact@v3 |
| 152 | + with: |
| 153 | + path: site |
| 154 | +
|
| 155 | + - name: Deploy to GitHub Pages |
| 156 | + id: deployment |
| 157 | + uses: actions/deploy-pages@v4 |
| 158 | +``` |
| 159 | + |
| 160 | +**Alternative trigger:** If you prefer a simpler “deploy on push to `main`” flow, replace the `on:` block with: |
| 161 | +```yaml |
| 162 | +on: |
| 163 | + push: |
| 164 | + branches: [ main ] |
| 165 | + workflow_dispatch: |
| 166 | +``` |
| 167 | + |
| 168 | +--- |
| 169 | + |
| 170 | +## 6) Local development |
| 171 | + |
| 172 | +You can keep using your existing `make serve-docs`. A direct command is: |
| 173 | + |
| 174 | +```bash |
| 175 | +pip install mkdocs mkdocs-material |
| 176 | +mkdocs serve |
| 177 | +``` |
| 178 | + |
| 179 | +Open `http://127.0.0.1:8000` to preview. |
| 180 | + |
| 181 | +--- |
| 182 | + |
| 183 | +## 7) Verification checklist |
| 184 | + |
| 185 | +- Push to `main` → The **Deploy docs** workflow runs and publishes the site. |
| 186 | +- Visit **https://openai.github.io/openai-guardrails-python/** and confirm: |
| 187 | + - Styles load correctly (no 404s for assets). |
| 188 | + - Internal links and nav work. |
| 189 | + - Canonical URLs include `/openai-guardrails-python/` (set via `site_url`). |
| 190 | +- In **Settings → Pages**, you should see the latest successful deployment linked. |
| 191 | + |
| 192 | +--- |
| 193 | + |
| 194 | +## 8) Troubleshooting |
| 195 | + |
| 196 | +- **404s on CSS/JS or broken links under `/openai-guardrails-python/`** |
| 197 | + Ensure `site_url` is set to `https://openai.github.io/openai-guardrails-python/` in `mkdocs.yml`. |
| 198 | + |
| 199 | +- **Workflow never triggers** |
| 200 | + If using `workflow_run`, confirm the referenced workflow name (e.g., `"Tests"`) matches your CI workflow’s `name:` exactly, or switch to a simple `push` trigger. |
| 201 | + |
| 202 | +- **MkDocs plugin missing in CI** |
| 203 | + Add the plugin to both `pip install ...` in the workflow and to `mkdocs.yml`. |
| 204 | + |
| 205 | +- **Custom domain not needed** |
| 206 | + We’re publishing under the project path on `openai.github.io`—no `CNAME` file is required. |
| 207 | + |
| 208 | +--- |
| 209 | + |
| 210 | +## 9) Summary |
| 211 | + |
| 212 | +- Keep docs in `docs/` and configure `mkdocs.yml` with the correct `site_url`. |
| 213 | +- Use `docs.yml` to automatically build and deploy on each push (or after tests pass). |
| 214 | + |
| 215 | +Once merged to `main`, the site will publish to: |
| 216 | +**https://openai.github.io/openai-guardrails-python/** |
0 commit comments