Skip to content

Commit 48a7021

Browse files
authored
Merge pull request #16 from m-misiura/sync-upstream-to-midstream
Sync midstream to upstream
2 parents c393c5d + ffbc968 commit 48a7021

File tree

415 files changed

+10497
-15671
lines changed

Some content is hidden

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

415 files changed

+10497
-15671
lines changed

.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/latest-deps-tests.yml

Lines changed: 2 additions & 2 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]
12+
os: [Ubuntu, macOS, Windows]
1313
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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ name: PR Tests
22

33
on:
44
pull_request:
5-
# we don't ignore markdkowns to run pre-commits
65
paths-ignore:
6+
- "**/*.md"
77
- ".github/**"
88

99
jobs:
@@ -15,12 +15,16 @@ jobs:
1515
include:
1616
- os: Ubuntu
1717
image: ubuntu-latest
18+
- python-version: "3.11"
19+
with-coverage: true
1820
fail-fast: false
1921
uses: ./.github/workflows/_test.yml
22+
secrets: inherit
2023
with:
2124
os: ${{ matrix.os }}
2225
image: ${{ matrix.image }}
2326
python-version: ${{ matrix.python-version }}
27+
with-coverage: ${{ matrix.with-coverage || false }}
2428
pr-tests-summary:
2529
name: PR Tests Summary
2630
needs: pr-tests-matrix

.github/workflows/publish-pypi-approval.yml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,35 @@ jobs:
1818
id-token: write
1919

2020
steps:
21-
- name: Checkout repository for tag detection
22-
uses: actions/checkout@v4
23-
with:
24-
fetch-depth: 0
25-
26-
- name: Detect version tag and extract info
21+
- name: Detect version tag from workflow event
2722
id: version
2823
run: |
29-
COMMIT_SHA="${{ github.event.workflow_run.head_sha }}"
24+
HEAD_BRANCH="${{ github.event.workflow_run.head_branch }}"
25+
26+
echo "Workflow triggered by: $HEAD_BRANCH"
3027
31-
TAG_NAME=$(git tag --points-at "$COMMIT_SHA" | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+' | head -1)
28+
if [[ "$HEAD_BRANCH" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
29+
TAG_NAME="$HEAD_BRANCH"
30+
VERSION="${TAG_NAME#v}"
3231
33-
if [ -z "$TAG_NAME" ]; then
34-
echo "❌ No version tag found at commit $COMMIT_SHA"
35-
echo "Available tags at this commit:"
36-
git tag --points-at "$COMMIT_SHA" || echo " (none)"
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)"
3742
exit 1
3843
fi
3944
40-
VERSION="${TAG_NAME#v}"
41-
echo "version=${VERSION}" >> $GITHUB_OUTPUT
42-
echo "tag=${TAG_NAME}" >> $GITHUB_OUTPUT
43-
echo "artifact_name=${TAG_NAME}-build" >> $GITHUB_OUTPUT
44-
echo "✅ Detected version tag: $TAG_NAME"
45-
4645
- name: Checkout repository
4746
uses: actions/checkout@v4
4847
with:
4948
ref: ${{ steps.version.outputs.tag }}
49+
fetch-depth: 0
5050

5151
- name: Validate version matches tag
5252
run: |

.github/workflows/test-coverage-report.yml

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

.github/workflows/test-docker.yml

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,48 @@ name: Test Docker Image
33
# TODO: set docker auth
44
on:
55
workflow_dispatch:
6-
# on:
7-
# push:
8-
# tags:
9-
# - "v*"
10-
11-
env:
12-
IMAGE: nemoguardrails
13-
TEST_TAG: ${{ env.IMAGE }}:test
14-
LATEST_TAG: ${{ env.IMAGE }}:latest
6+
schedule:
7+
- cron: "0 0 * * 0"
8+
push:
9+
tags:
10+
- "v*"
11+
pull_request:
12+
paths:
13+
- "Dockerfile"
14+
- "pyproject.toml"
15+
- "poetry.lock"
16+
- ".github/workflows/test-docker.yml"
1517

1618
jobs:
1719
docker:
1820
runs-on: ubuntu-latest
21+
env:
22+
IMAGE: nemoguardrails
1923
steps:
2024
#
2125
# Checkout the code
2226
- name: Checkout
2327
uses: actions/checkout@v4
2428

25-
# Extract the tag version and set Docker tags
26-
- name: Get git tag and set Docker tags
29+
# Get runner architecture
30+
- name: Get runner architecture
31+
id: runner-arch
32+
run: echo "arch=$(uname -m)" >> $GITHUB_OUTPUT
33+
34+
- name: Set Docker tags
2735
run: |
28-
VERSION=${GITHUB_REF#refs/tags/v}
29-
echo "VERSION=$VERSION" >> $GITHUB_ENV
30-
echo "VERSION_TAG=${{ env.IMAGE }}:$VERSION" >> $GITHUB_ENV
36+
ARCH=${{ steps.runner-arch.outputs.arch }}
37+
echo "TEST_TAG=${{ env.IMAGE }}:${{ github.sha }}-$ARCH" >> $GITHUB_ENV
3138
32-
# Build the Docker image
33-
- name: Build the Docker image
34-
run: docker build . --file Dockerfile --tag ${{ env.TEST_TAG }} --tag ${{ env.VERSION_TAG }}
39+
- name: Set up Docker Buildx
40+
uses: docker/setup-buildx-action@v3
41+
- name: Build image
42+
uses: docker/build-push-action@v6
43+
with:
44+
context: .
45+
file: Dockerfile
46+
load: true
47+
tags: ${{ env.TEST_TAG }}
3548

3649
# Start the container in detached mode
3750
- name: Start container

.pre-commit-config.yaml

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@ repos:
55
- id: check-yaml
66
- id: end-of-file-fixer
77
- id: trailing-whitespace
8-
- repo: https://github.com/pycqa/isort
9-
rev: 5.12.0
8+
9+
- repo: https://github.com/astral-sh/ruff-pre-commit
10+
# Ruff version.
11+
rev: v0.14.6
1012
hooks:
11-
- id: isort
12-
args: [ "--profile", "black" ]
13-
name: isort (python)
14-
- repo: https://github.com/psf/black
15-
rev: 23.3.0
16-
hooks:
17-
- id: black
13+
# Run the linter.
14+
- id: ruff
15+
args: [--fix]
16+
# Run the formatter.
17+
- id: ruff-format
18+
1819
- repo: https://github.com/Lucas-C/pre-commit-hooks
1920
rev: v1.4.2
2021
hooks:
@@ -32,9 +33,3 @@ repos:
3233
language: system
3334
types: [python]
3435
pass_filenames: false
35-
# Deactivating this for now.
36-
# - repo: https://github.com/pycqa/pylint
37-
# rev: v2.17.0
38-
# hooks:
39-
# - id: pylint
40-
# language_version: python3.10

0 commit comments

Comments
 (0)