Skip to content

Commit a0bfa16

Browse files
committed
Sync feature/detections-api-integration with trustyai-explainability/NeMo-Guardrails:develop
2 parents b027e02 + 48a7021 commit a0bfa16

File tree

704 files changed

+40608
-19732
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

704 files changed

+40608
-19732
lines changed

.devcontainer/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/python-3/.devcontainer/base.Dockerfile
22

3-
# [Choice] Python version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.10, 3.9, 3.8, 3.7, 3.6, 3-bullseye, 3.10-bullseye, 3.9-bullseye, 3.8-bullseye, 3.7-bullseye, 3.6-bullseye, 3-buster, 3.10-buster, 3.9-buster, 3.8-buster, 3.7-buster, 3.6-buster
3+
# [Choice] Python version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.13, 3.12, 3.11, 3.10, 3-bullseye, 3.13-bullseye, 3.12-bullseye, 3.11-bullseye, 3.10-bullseye, 3-buster, 3.13-buster, 3.12-buster, 3.11-buster, 3.10-buster
44
ARG VARIANT="3.10-bullseye"
55
FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT}
66

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"dockerfile": "Dockerfile",
77
"context": "..",
88
"args": {
9-
// Update 'VARIANT' to pick a Python version: 3, 3.10, 3.9, 3.8, 3.7, 3.6
9+
// Update 'VARIANT' to pick a Python version: 3, 3.13, 3.12, 3.11, 3.10
1010
// Append -bullseye or -buster to pin to an OS version.
1111
// Use -bullseye variants on local on arm64/Apple Silicon.
1212
"VARIANT": "3.10-bullseye",

.github/workflows/_test.yml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ on:
2323
required: false
2424
default: false
2525
type: boolean
26+
with-coverage:
27+
description: "Whether to run tests with coverage reporting"
28+
required: false
29+
default: false
30+
type: boolean
2631

2732
defaults:
2833
run:
@@ -89,8 +94,23 @@ jobs:
8994
poetry install --with dev
9095
fi
9196
92-
- name: Run pre-commit hooks
93-
run: poetry run make pre_commit
97+
- name: Run pytest with coverage
98+
if: inputs.with-coverage
99+
run: poetry run pytest --cov=nemoguardrails tests/ --cov-report=xml:coverage.xml -v
94100

95-
- name: Run pytest
101+
- name: Run pytest without coverage
102+
if: inputs.with-coverage == false
96103
run: poetry run pytest -v
104+
105+
- name: Upload coverage to Codecov
106+
if: inputs.with-coverage
107+
uses: codecov/codecov-action@v5
108+
with:
109+
directory: ./coverage/reports/
110+
env_vars: PYTHON
111+
fail_ci_if_error: true
112+
files: ./coverage.xml
113+
flags: python
114+
name: codecov-umbrella
115+
token: ${{ secrets.CODECOV_TOKEN }}
116+
verbose: true

.github/workflows/docs-build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ jobs:
7474
path: pr/
7575

7676
store-html:
77-
if: github.event_name == 'push' && github.repository_owner == 'NVIDIA'
77+
if: github.event_name == 'push' && github.repository_owner == 'NVIDIA-NeMo'
7878
needs: [build-docs]
7979
runs-on: ubuntu-latest
8080
steps:

.github/workflows/full-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
strategy:
2020
matrix:
2121
os: [Windows, macOS] # exclude Ubuntu as it is available in pr-tests
22-
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
22+
python-version: ["3.10", "3.11", "3.12", "3.13"]
2323
include:
2424
- os: Windows
2525
image: windows-2022

.github/workflows/latest-deps-tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ jobs:
99
latest-deps-tests-matrix:
1010
strategy:
1111
matrix:
12-
os: [Ubuntu]
13-
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
12+
os: [Ubuntu, macOS, Windows]
13+
python-version: ["3.10", "3.11", "3.12", "3.13"]
1414
include:
1515
- os: Ubuntu
1616
image: ubuntu-latest
1717
- os: macOS
18-
image: macos-15
18+
image: macos-latest
1919
- os: Windows
2020
image: windows-latest
2121
fail-fast: false

.github/workflows/lint.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Lint
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
- develop
9+
workflow_dispatch:
10+
11+
env:
12+
POETRY_VERSION: 1.8.2
13+
PYTHON_VERSION: "3.11"
14+
15+
jobs:
16+
lint:
17+
name: Lint Code
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: ${{ env.PYTHON_VERSION }}
26+
27+
- name: Get full Python version
28+
id: full-python-version
29+
run: echo "version=$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")" >> $GITHUB_OUTPUT
30+
31+
- name: Bootstrap poetry
32+
run: |
33+
curl -sSL https://install.python-poetry.org | POETRY_VERSION=${{ env.POETRY_VERSION }} python -
34+
echo "$HOME/.local/bin" >> $GITHUB_PATH
35+
36+
- name: Configure poetry
37+
run: poetry config virtualenvs.in-project true
38+
39+
- name: Set up cache
40+
uses: actions/cache@v4
41+
id: cache
42+
with:
43+
path: .venv
44+
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}
45+
46+
- name: Ensure cache is healthy
47+
if: steps.cache.outputs.cache-hit == 'true'
48+
run: timeout 10s poetry run pip --version || rm -rf .venv
49+
50+
- name: Install dependencies
51+
run: poetry install --with dev
52+
53+
- name: Run pre-commit hooks
54+
run: poetry run make pre_commit
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Skip PR Tests
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "**/*.md"
7+
- ".github/**"
8+
9+
jobs:
10+
pr-tests-summary:
11+
name: PR Tests Summary
12+
runs-on: ubuntu-latest
13+
steps:
14+
- run: echo "Tests skipped (no code changes)"

.github/workflows/pr-tests.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
name: PR Tests
22

33
on:
4-
push:
5-
64
pull_request:
7-
# we don't ignore markdkowns to run pre-commits
85
paths-ignore:
6+
- "**/*.md"
97
- ".github/**"
108

119
jobs:
1210
pr-tests-matrix:
1311
strategy:
1412
matrix:
1513
os: [Ubuntu]
16-
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
14+
python-version: ["3.10", "3.11", "3.12", "3.13"]
1715
include:
1816
- os: Ubuntu
1917
image: ubuntu-latest
18+
- python-version: "3.11"
19+
with-coverage: true
2020
fail-fast: false
2121
uses: ./.github/workflows/_test.yml
22+
secrets: inherit
2223
with:
2324
os: ${{ matrix.os }}
2425
image: ${{ matrix.image }}
2526
python-version: ${{ matrix.python-version }}
27+
with-coverage: ${{ matrix.with-coverage || false }}
2628
pr-tests-summary:
2729
name: PR Tests Summary
2830
needs: pr-tests-matrix
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
name: Publish to PyPI (with Approval)
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Build and Test Distribution"]
6+
types:
7+
- completed
8+
9+
jobs:
10+
publish-pypi:
11+
if: github.event.workflow_run.conclusion == 'success'
12+
runs-on: ubuntu-latest
13+
environment:
14+
name: pypi-production
15+
url: https://pypi.org/project/nemoguardrails/
16+
permissions:
17+
contents: write
18+
id-token: write
19+
20+
steps:
21+
- name: Detect version tag from workflow event
22+
id: version
23+
run: |
24+
HEAD_BRANCH="${{ github.event.workflow_run.head_branch }}"
25+
26+
echo "Workflow triggered by: $HEAD_BRANCH"
27+
28+
if [[ "$HEAD_BRANCH" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
29+
TAG_NAME="$HEAD_BRANCH"
30+
VERSION="${TAG_NAME#v}"
31+
32+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
33+
echo "tag=${TAG_NAME}" >> $GITHUB_OUTPUT
34+
echo "artifact_name=${TAG_NAME}-build" >> $GITHUB_OUTPUT
35+
36+
echo "✅ Detected version tag: $TAG_NAME"
37+
echo " Version: $VERSION"
38+
echo " Artifact: ${TAG_NAME}-build"
39+
else
40+
echo "❌ Not triggered by a version tag: $HEAD_BRANCH"
41+
echo "This workflow should only run for version tags (vX.Y.Z)"
42+
exit 1
43+
fi
44+
45+
- name: Checkout repository
46+
uses: actions/checkout@v4
47+
with:
48+
ref: ${{ steps.version.outputs.tag }}
49+
fetch-depth: 0
50+
51+
- name: Validate version matches tag
52+
run: |
53+
VERSION_IN_FILE=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
54+
TAG_VERSION="${{ steps.version.outputs.version }}"
55+
if [ "$VERSION_IN_FILE" != "$TAG_VERSION" ]; then
56+
echo "❌ Version mismatch: pyproject.toml=$VERSION_IN_FILE, tag=$TAG_VERSION"
57+
exit 1
58+
fi
59+
echo "✅ Version validated: $VERSION_IN_FILE matches tag $TAG_VERSION"
60+
61+
- name: Download artifact
62+
uses: actions/download-artifact@v4
63+
with:
64+
name: ${{ steps.version.outputs.artifact_name }}
65+
path: dist
66+
github-token: ${{ secrets.GITHUB_TOKEN }}
67+
repository: ${{ github.repository }}
68+
run-id: ${{ github.event.workflow_run.id }}
69+
70+
- name: List files
71+
run: ls -la dist/
72+
73+
- name: Publish to PyPI
74+
uses: pypa/gh-action-pypi-publish@release/v1
75+
with:
76+
verbose: true
77+
packages-dir: dist/
78+
attestations: true
79+
80+
- name: Create GitHub Release
81+
env:
82+
GH_TOKEN: ${{ github.token }}
83+
run: |
84+
TAG_NAME="${{ steps.version.outputs.tag }}"
85+
86+
git config --global user.name "github-actions[bot]"
87+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
88+
89+
CHANGELOG_SECTION=$(awk -v version="${{ steps.version.outputs.version }}" '
90+
/^## \[/ {
91+
if (found) exit
92+
if ($0 ~ "\\[" version "\\]") {
93+
found=1
94+
next
95+
}
96+
}
97+
found && /^## \[/ { exit }
98+
found { print }
99+
' CHANGELOG.md || echo "No changelog entry found for this version.")
100+
101+
echo "$CHANGELOG_SECTION" > release_notes.md
102+
103+
if gh release view "$TAG_NAME" --repo ${{ github.repository }} >/dev/null 2>&1; then
104+
echo "ℹ️ Release $TAG_NAME already exists, skipping creation"
105+
else
106+
if gh release create "$TAG_NAME" \
107+
--draft \
108+
--title "$TAG_NAME" \
109+
--notes-file release_notes.md \
110+
--repo ${{ github.repository }}; then
111+
echo "✅ Release $TAG_NAME created successfully"
112+
else
113+
echo "❌ Failed to create release $TAG_NAME" >&2
114+
rm -f release_notes.md
115+
exit 1
116+
fi
117+
fi
118+
119+
rm -f release_notes.md

0 commit comments

Comments
 (0)