Skip to content

Commit 175d2b6

Browse files
committed
Build docs in GitHub for review
Signed-off-by: Mike McKiernan <[email protected]>
1 parent 485bfd2 commit 175d2b6

File tree

15 files changed

+1413
-180
lines changed

15 files changed

+1413
-180
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: docs-build-pr
2+
3+
on:
4+
pull_request:
5+
branches: [develop]
6+
types: [opened, synchronize]
7+
8+
env:
9+
GH_TOKEN: ${{ github.token }}
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
build-docs:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
- name: Set up Docker Buildx
22+
uses: docker/setup-buildx-action@v3
23+
- name: Build image
24+
uses: docker/build-push-action@v6
25+
with:
26+
context: docs
27+
file: docs/Dockerfile
28+
load: true
29+
tags: pr-image:${{ github.sha }}
30+
- name: Build docs
31+
run: |
32+
docker run -v $(pwd):/work -w /work pr-image:${{ github.sha }} sphinx-build -b html docs _build/docs
33+
- name: Delete unnecessary files
34+
run: |
35+
sudo find _build -name .doctrees -prune -exec rm -rf {} \;
36+
sudo find _build -name .buildinfo -exec rm {} \;
37+
- name: Upload HTML
38+
uses: actions/upload-artifact@v4
39+
with:
40+
name: html-build-artifact
41+
path: _build/docs
42+
if-no-files-found: error
43+
retention-days: 1
44+
- name: Store PR information
45+
run: |
46+
mkdir ./pr
47+
echo ${{ github.event.number }} > ./pr/pr.txt
48+
echo ${{ github.event.pull_request.merged }} > ./pr/merged.txt
49+
echo ${{ github.event.action }} > ./pr/action.txt
50+
- name: Upload PR information
51+
uses: actions/upload-artifact@v4
52+
with:
53+
name: pr
54+
path: pr/

.github/workflows/docs-build.yaml

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
name: docs-build
2+
3+
on:
4+
push:
5+
branches: [develop]
6+
tags:
7+
- docs-v*
8+
- v*
9+
workflow_dispatch:
10+
11+
env:
12+
REGISTRY: ghcr.io
13+
IMAGE_NAME: ${{ github.repository }}-docs
14+
TAG: 0.1.0
15+
GH_TOKEN: ${{ github.token }}
16+
17+
concurrency:
18+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
19+
cancel-in-progress: true
20+
21+
jobs:
22+
dockerfile-changed:
23+
runs-on: ubuntu-latest
24+
permissions:
25+
contents: read
26+
packages: read
27+
outputs:
28+
changed: ${{ steps.change.outputs.changed }}
29+
image: ${{ steps.change.outputs.image }}
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v4
33+
- name: Log in to Container Registry
34+
uses: docker/login-action@v3
35+
with:
36+
registry: ${{ env.REGISTRY }}
37+
username: ${{ github.actor }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
39+
- name: Detect change
40+
id: change
41+
shell: bash
42+
run: |
43+
export COMMIT_SHORT_SHA="${GITHUB_SHA:0:8}"
44+
if ! docker manifest inspect "${REGISTRY}/${IMAGE_NAME,,}:${TAG}" 2>&1 > /dev/null ; then
45+
echo "image not found...${REGISTRY}/${IMAGE_NAME,,}:${TAG}"
46+
export NEEDS_IMAGE=true
47+
fi
48+
def_branch=$(gh api "repos/${GITHUB_REPOSITORY}" -q '.default_branch')
49+
git fetch origin "${def_branch}"
50+
files=$(git diff --name-only "${GITHUB_SHA}" FETCH_HEAD | tr '\n' ' ')
51+
echo "${files}"
52+
if echo "${files}" | grep -q "docs/poetry.lock/\|docs/Dockerfile"; then export NEEDS_IMAGE=true ; fi
53+
if [[ "${NEEDS_IMAGE}" ]]; then
54+
echo "changed=true" >> "$GITHUB_OUTPUT"
55+
if [[ "${{ github.event_name }}" == 'pull_request' ]]; then
56+
echo "image=${REGISTRY}/${IMAGE_NAME,,}:${COMMIT_SHORT_SHA}" >> "$GITHUB_OUTPUT"
57+
else
58+
echo "image=${REGISTRY}/${IMAGE_NAME,,}:${TAG}" >> "$GITHUB_OUTPUT"
59+
fi
60+
else
61+
echo "changed=false" >> "$GITHUB_OUTPUT"
62+
echo "image=${REGISTRY}/${IMAGE_NAME,,}:${TAG}" >> "$GITHUB_OUTPUT"
63+
fi
64+
65+
build-and-push-image:
66+
needs: dockerfile-changed
67+
if: needs.dockerfile-changed.outputs.changed == 'true'
68+
runs-on: ubuntu-latest
69+
permissions:
70+
contents: read
71+
packages: write
72+
steps:
73+
- name: Checkout
74+
uses: actions/checkout@v4
75+
- name: Set up Docker Buildx
76+
uses: docker/setup-buildx-action@v3
77+
- name: Log in to Container Registry
78+
uses: docker/login-action@v3
79+
with:
80+
registry: ${{ env.REGISTRY }}
81+
username: ${{ github.actor }}
82+
password: ${{ secrets.GITHUB_TOKEN }}
83+
- name: Build and push
84+
uses: docker/build-push-action@v6
85+
with:
86+
context: docs
87+
file: docker/Dockerfile
88+
push: true
89+
tags: ${{ needs.dockerfile-changed.outputs.image }}
90+
91+
build-docs:
92+
needs: [dockerfile-changed, build-and-push-image]
93+
container:
94+
image: ${{ needs.dockerfile-changed.outputs.image }}
95+
if: ${{ always() }}
96+
runs-on: ubuntu-latest
97+
steps:
98+
- name: Checkout
99+
uses: actions/checkout@v4
100+
- name: Build docs
101+
run: |
102+
sphinx-build -b html docs _build/docs
103+
- name: Delete unnecessary files
104+
run: |
105+
find _build -name .doctrees -prune -exec rm -rf {} \;
106+
find _build -name .buildinfo -exec rm {} \;
107+
- name: Upload HTML
108+
uses: actions/upload-artifact@v4
109+
with:
110+
name: html-build-artifact
111+
path: _build/docs
112+
if-no-files-found: error
113+
retention-days: 1
114+
- name: Store PR information
115+
if: github.event_name == 'pull_request'
116+
run: |
117+
mkdir ./pr
118+
echo ${{ github.event.number }} > ./pr/pr.txt
119+
echo ${{ github.event.pull_request.merged }} > ./pr/merged.txt
120+
echo ${{ github.event.action }} > ./pr/action.txt
121+
- name: Upload PR information
122+
if: ${{ github.event_name == 'pull_request' }}
123+
uses: actions/upload-artifact@v4
124+
with:
125+
name: pr
126+
path: pr/
127+
128+
store-html:
129+
needs: [build-docs]
130+
runs-on: ubuntu-latest
131+
steps:
132+
- uses: actions/checkout@v4
133+
with:
134+
ref: "gh-pages"
135+
- name: Initialize Git configuration
136+
run: |
137+
git config user.name docs-build
138+
git config user.email [email protected]
139+
- name: Download artifacts
140+
uses: actions/download-artifact@v4
141+
with:
142+
name: html-build-artifact
143+
- name: Copy HTML directories
144+
run: |
145+
ls -asl
146+
for i in `ls -d *`
147+
do
148+
echo "Git adding ${i}"
149+
git add "${i}"
150+
done
151+
- name: Check or create dot-no-jekyll file
152+
run: |
153+
if [ -f ".nojekyll" ]; then
154+
echo "The dot-no-jekyll file already exists."
155+
exit 0
156+
fi
157+
touch .nojekyll
158+
git add .nojekyll
159+
- name: Check or create redirect page
160+
env:
161+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
162+
run: |
163+
resp=$(grep 'http-equiv="refresh"' index.html 2>/dev/null) || true
164+
if [ -n "${resp}" ]; then
165+
echo "The redirect file already exists."
166+
exit 0
167+
fi
168+
# If any of these commands fail, fail the build.
169+
def_branch=$(gh api "repos/${GITHUB_REPOSITORY}" --jq ".default_branch")
170+
html_url=$(gh api "repos/${GITHUB_REPOSITORY}/pages" --jq ".html_url")
171+
# Beware ugly quotation mark avoidance in the foll lines.
172+
echo '<!DOCTYPE html>' > index.html
173+
echo '<html>' >> index.html
174+
echo ' <head>' >> index.html
175+
echo ' <title>Redirect to documentation</title>' >> index.html
176+
echo ' <meta charset="utf-8">' >> index.html
177+
echo ' <meta http=equiv="refresh" content="3; URL='${html_url}${def_branch}'/index.html">' >> index.html
178+
echo ' <link rel="canonical" href="'${html_url}${def_branch}'/index.html">' >> index.html
179+
echo ' <script language="javascript">' >> index.html
180+
echo ' function redirect() {' >> index.html
181+
echo ' window.location.assign("'${html_url}${def_branch}'/index.html")' >> index.html
182+
echo ' }' >> index.html
183+
echo ' </script>' >> index.html
184+
echo ' </head>' >> index.html
185+
echo ' <body onload="redirect()">' >> index.html
186+
echo ' <p>Please follow the link to the <a href="'${html_url}${def_branch}'/index.html">' >> index.html
187+
echo ${def_branch}'</a> branch documentation.</p>' >> index.html
188+
echo ' </body>' >> index.html
189+
echo '</html>' >> index.html
190+
git add index.html
191+
- name: Commit changes to the GitHub Pages branch
192+
run: |
193+
git status
194+
if git commit -m 'Pushing changes to GitHub Pages.'; then
195+
git push -f
196+
else
197+
echo "Nothing changed."
198+
fi
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: docs-preview-pr
2+
3+
on:
4+
workflow_run:
5+
workflows: [ docs-build-pr ]
6+
types: [ completed ]
7+
branches-ignore: [ main ]
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
11+
cancel-in-progress: true
12+
13+
env:
14+
WF_ID: ${{ github.event.workflow_run.id }}
15+
16+
jobs:
17+
preview:
18+
uses: nvidia-merlin/.github/.github/workflows/docs-preview-pr-common.yaml@main
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: docs-remove-stale-reviews
2+
3+
on:
4+
schedule:
5+
# 42 minutes after 0:00 UTC on Sundays
6+
- cron: "42 0 * * 0"
7+
workflow_dispatch:
8+
9+
jobs:
10+
remove:
11+
uses: nvidia-merlin/.github/.github/workflows/docs-remove-stale-reviews-common.yaml@main

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
1515
✨✨✨
1616

17-
📌 **The official NeMo Guardrails documentation has moved to [docs.nvidia.com/nemo-guardrails](https://docs.nvidia.com/nemo-guardrails).**
17+
📌 **The official NeMo Guardrails documentation has moved to [docs.nvidia.com/nemo/guardrails](https://docs.nvidia.com/nemo/guardrails).**
1818

1919
✨✨✨
2020

@@ -40,6 +40,8 @@ For more detailed instructions, see the [Installation Guide](https://docs.nvidia
4040

4141
## Overview
4242

43+
<!-- start-documentation-reuse -->
44+
4345
NeMo Guardrails enables developers building LLM-based applications to easily add **programmable guardrails** between the application code and the LLM.
4446

4547
<div align="center">
@@ -54,6 +56,8 @@ Key benefits of adding *programmable guardrails* include:
5456

5557
- **Controllable dialog**: you can steer the LLM to follow pre-defined conversational paths, allowing you to design the interaction following conversation design best practices and enforce standard operating procedures (e.g., authentication, support).
5658

59+
<!-- end-documentation-reuse -->
60+
5761
### Protecting against LLM Vulnerabilities
5862

5963
NeMo Guardrails provides several mechanisms for protecting an LLM-powered chat application against common LLM vulnerabilities, such as jailbreaks and prompt injections. Below is a sample overview of the protection offered by different guardrails configuration for the example [ABC Bot](./examples/bots/abc) included in this repository. For more details, please refer to the [LLM Vulnerability Scanning](https://docs.nvidia.com/nemo/guardrails/evaluation/llm-vulnerability-scanning.html) page.

docs/Dockerfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
FROM python:3.10
16+
17+
ARG UID=1000
18+
19+
ENV POETRY_VERSION=1.8.2
20+
ENV POETRY_HOME=/opt/poetry
21+
ENV PATH="${PATH}:${POETRY_HOME}/bin"
22+
23+
RUN apt-get update && DEBIAN_FRONTEND=noninteractive \
24+
&& apt-get install --no-install-recommends -y \
25+
curl \
26+
python3-pip \
27+
jq \
28+
lsb-release
29+
30+
RUN curl -sSL https://install.python-poetry.org | POETRY_VERSION="${POETRY_VERSION}" POETRY_HOME="${POETRY_HOME}" python -
31+
32+
RUN useradd -u "${UID}" -ms /bin/bash nvs
33+
RUN --mount=type=bind,target=/work poetry config virtualenvs.create false && poetry install -C /work --with docs --no-interaction --no-ansi

0 commit comments

Comments
 (0)