Skip to content

docs(fern): migrate remaining examples to unified CLI #8282

docs(fern): migrate remaining examples to unified CLI

docs(fern): migrate remaining examples to unified CLI #8282

Workflow file for this run

# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Unit tests
on:
pull_request:
types: [opened, synchronize, reopened, labeled, unlabeled]
workflow_call:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
# Number of parallel shards for the full server suite. Keep in sync with the matrix below.
NUM_SHARDS: "8"
# Pin uv: 0.11.20 has a resolver regression that silently drops pinned deps from
# `uv pip install -r requirements.txt`. 0.11.19 is the latest known-good version.
UV_INSTALL_URL: "https://astral.sh/uv/0.11.19/install.sh"
jobs:
detect:
name: Detect changes
runs-on: ubuntu-latest
outputs:
run_full: ${{ steps.changes.outputs.run_full }}
run_servers: ${{ steps.changes.outputs.run_servers }}
server_all_changed_files: ${{ steps.changed-files.outputs.server_all_changed_files }}
steps:
- name: Checkout repository
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
submodules: 'recursive'
- name: Detect changed files
id: changed-files
uses: step-security/changed-files@3dbe17c78367e7d60f00d78ae6781a35be47b4a1 # v45.0.1
with:
# 'files' input enables global other_changed_files_count for uncategorized files
files: |
**.md
fern/**
LICENSE
resources_servers/**
responses_api_agents/**
responses_api_models/**
benchmarks/**
files_yaml: |
doc:
- '**.md'
- fern/**
- LICENSE
- benchmarks/**
server:
- resources_servers/**
- responses_api_agents/**
- responses_api_models/**
- name: Classify changes
id: changes
run: |
# workflow_call or non-PR context: run everything
if [[ "${{ github.event_name }}" != "pull_request" ]]; then
echo "run_full=true" >> $GITHUB_OUTPUT
echo "run_servers=false" >> $GITHUB_OUTPUT
echo "No PR context - running full suite"
exit 0
fi
DOC_CHANGED="${{ steps.changed-files.outputs.doc_any_changed }}"
SERVER_CHANGED="${{ steps.changed-files.outputs.server_any_changed }}"
OTHER_COUNT="${{ steps.changed-files.outputs.other_changed_files_count }}"
echo "============================================"
echo "File change categorization"
echo "============================================"
echo ""
echo "Categories:"
echo " doc (skip tests): **.md, fern/**, LICENSE, benchmarks/**"
echo " server (test changed): resources_servers/**, responses_api_agents/**, responses_api_models/**"
echo " other (full suite): everything else (core library, CI, scripts, etc.)"
echo " Priority: other > server > doc"
echo ""
echo "This PR:"
echo " doc changed: $DOC_CHANGED"
echo " server changed: $SERVER_CHANGED"
echo " other (uncategorized): ${OTHER_COUNT:-0} file(s)"
if [[ "${OTHER_COUNT:-0}" -gt 0 ]]; then
echo " other files: ${{ steps.changed-files.outputs.other_changed_files }}"
fi
echo ""
# Files outside doc/server categories (CI, core library, config, etc.) → full suite
if [[ "${OTHER_COUNT:-0}" -gt 0 ]]; then
echo "Decision: FULL TEST SUITE"
echo "Reason: ${OTHER_COUNT} file(s) outside doc/server categories"
echo "run_full=true" >> $GITHUB_OUTPUT
echo "run_servers=false" >> $GITHUB_OUTPUT
# Only server files changed (possibly with doc changes) → test changed servers
elif [[ "$SERVER_CHANGED" == "true" ]]; then
echo "Decision: SERVER TESTS ONLY"
echo "Reason: only server files changed (+ possibly docs)"
echo "run_full=false" >> $GITHUB_OUTPUT
echo "run_servers=true" >> $GITHUB_OUTPUT
# Only doc files changed → skip tests
else
echo "Decision: SKIP TESTS"
echo "Reason: only doc/benchmark files changed"
echo "run_full=false" >> $GITHUB_OUTPUT
echo "run_servers=false" >> $GITHUB_OUTPUT
fi
echo "============================================"
# Core library unit tests (run once on a full run) + the changed-servers path. The full
# server suite is sharded into the parallel `server-suite` matrix below.
test:
name: Test
needs: detect
if: needs.detect.outputs.run_full == 'true' || needs.detect.outputs.run_servers == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
submodules: 'recursive'
- name: Cache uv dependencies
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
with:
path: ~/.cache/uv
key: uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}
restore-keys: |
uv-${{ runner.os }}-
- name: Setup for test
run: |
sudo apt-get update
# Curl is required for setup_nvidia.sh to download uv
# ca-certificates is there to support curl and mitigate `curl: (77) error setting certificate file: /etc/ssl/certs/ca-certificates.crt`
sudo apt-get install -y --no-install-recommends git curl ca-certificates
# The flow below should be used and synced with any Docker or container related flows. There is no script here to keep it 100% explicit.
# This is how we test and this is how you should use/consume.
curl -LsSf "$UV_INSTALL_URL" | sh
uv venv --python 3.12
source .venv/bin/activate
uv sync --extra dev --extra sandbox
- name: Test
run: |
source .venv/bin/activate
# Full suite: core library unit tests run here once; all server tests run in the
# parallel `server-suite` matrix.
if [[ "${{ needs.detect.outputs.run_full }}" == "true" ]]; then
echo "Running core library unit tests without sandbox marker (server suite runs in the sharded matrix)"
PYTEST_ADDOPTS='-m "not sandbox" --cov-report= --cov-fail-under=0' ng_dev_test
echo "Running sandbox unit tests and appending them to the coverage report"
pytest --cov=. --cov-append --cov-report=term-missing --durations=10 -m sandbox
# Server-only: test only the changed servers (typically a small set, no sharding needed)
elif [[ "${{ needs.detect.outputs.run_servers }}" == "true" ]]; then
CHANGED_SERVERS=$(echo "${{ needs.detect.outputs.server_all_changed_files }}" | \
tr ' ' '\n' | cut -d'/' -f1-2 | sort -u)
echo "Testing changed servers:"
echo "$CHANGED_SERVERS" | sed 's/^/ - /'
EXIT_CODE=0
for server in $CHANGED_SERVERS; do
echo ""
echo "================================================"
echo "Testing: $server"
echo "================================================"
if ng_test +entrypoint=$server +delete_venvs_after_each_test=true +should_validate_data=true; then
echo "PASS: $server"
else
echo "FAIL: $server"
EXIT_CODE=1
fi
done
if [ $EXIT_CODE -ne 0 ]; then
echo "Some server tests failed"
exit 1
fi
fi
# Full server suite, split across NUM_SHARDS parallel runners. Only runs on a full run.
server-suite:
name: Server suite (shard ${{ matrix.shard }})
needs: detect
if: needs.detect.outputs.run_full == 'true'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
shard: [0, 1, 2, 3, 4, 5, 6, 7]
steps:
- name: Checkout repository
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
submodules: 'recursive'
- name: Cache uv dependencies
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
with:
path: ~/.cache/uv
key: uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}
restore-keys: |
uv-${{ runner.os }}-
- name: Setup for test
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends git curl ca-certificates
curl -LsSf "$UV_INSTALL_URL" | sh
uv venv --python 3.12
source .venv/bin/activate
uv sync --extra dev
- name: Server tests (shard ${{ matrix.shard }}/${{ env.NUM_SHARDS }})
run: |
source .venv/bin/activate
ng_test_all \
+fail_on_total_and_test_mismatch=true \
+delete_venvs_after_each_test=true \
+num_shards=${{ env.NUM_SHARDS }} \
+shard_index=${{ matrix.shard }}
# Single aggregated gate for the sharded server suite — make this a required check
# (in addition to "Test") instead of the individual shard jobs. `always()` so it also
# produces a green result when the full suite isn't required for this change.
server-suite-result:
name: Server suite
needs: [detect, server-suite]
if: always()
runs-on: ubuntu-latest
steps:
- name: Aggregate shard results
run: |
if [[ "${{ needs.detect.outputs.run_full }}" != "true" ]]; then
echo "Full server suite not required for this change; nothing to aggregate."
exit 0
fi
if [[ "${{ needs.server-suite.result }}" == "success" ]]; then
echo "All server-suite shards passed."
exit 0
fi
echo "One or more server-suite shards failed (result: ${{ needs.server-suite.result }})."
exit 1