Skip to content

Commit 7544a02

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

File tree

15 files changed

+1412
-180
lines changed

15 files changed

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