-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: add GHA to execute how-to notebooks (#1694)
- Loading branch information
Showing
11 changed files
with
404 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: Run notebooks | ||
|
||
on: | ||
workflow_call: | ||
schedule: | ||
- cron: '0 13 * * *' | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
lib-version: | ||
- "development" | ||
- "latest" | ||
|
||
name: "test (langgraph: ${{ matrix.lib-version }})" | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python + Poetry | ||
uses: "./.github/actions/poetry_setup" | ||
with: | ||
python-version: 3.11 | ||
poetry-version: 1.7.1 | ||
cache-key: test-langgraph-notebooks | ||
|
||
- name: Install dependencies | ||
run: | | ||
poetry install --with test | ||
poetry run pip install jupyter | ||
- name: Start services | ||
run: make start-services | ||
|
||
- name: Prepare notebooks | ||
if: ${{ matrix.lib-version == 'development' }} | ||
run: poetry run python docs/_scripts/prepare_notebooks_for_ci.py | ||
|
||
- name: Run notebooks | ||
env: | ||
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | ||
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} | ||
TAVILY_API_KEY: ${{ secrets.TAVILY_API_KEY }} | ||
LANGSMITH_API_KEY: ${{ secrets.LANGSMITH_API_KEY }} | ||
run: | | ||
for file in $(find docs/docs/how-tos -name "*.ipynb") | ||
do | ||
echo "Executing $file" | ||
PIP_PRE=1 poetry run jupyter execute "$file" | ||
done | ||
- name: Stop services | ||
run: make stop-services |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"""Preprocess notebooks for CI. Currently removes pip install cells.""" | ||
|
||
import os | ||
import json | ||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
NOTEBOOK_DIRS = ("docs/docs/how-tos",) | ||
|
||
def remove_install_cells(notebook_path: str) -> None: | ||
with open(notebook_path, "r") as file: | ||
notebook = json.load(file) | ||
|
||
indices_to_delete = [] | ||
for index, cell in enumerate(notebook["cells"]): | ||
if cell["cell_type"] == "code": | ||
if any("pip install" in line for line in cell["source"]): | ||
indices_to_delete.append(index) | ||
|
||
for index in reversed(indices_to_delete): | ||
notebook["cells"].pop(index) | ||
|
||
with open(notebook_path, "w") as file: | ||
json.dump(notebook, file, indent=2) | ||
|
||
|
||
def process_notebooks() -> None: | ||
for directory in NOTEBOOK_DIRS: | ||
for root, _, files in os.walk(directory): | ||
for file in files: | ||
if not file.endswith(".ipynb"): | ||
continue | ||
|
||
notebook_path = os.path.join(root, file) | ||
try: | ||
remove_install_cells(notebook_path) | ||
logger.info(f"Processed: {notebook_path}") | ||
except Exception as e: | ||
logger.error(f"Error processing {notebook_path}: {e}") | ||
|
||
|
||
if __name__ == "__main__": | ||
process_notebooks() | ||
logger.info("All notebooks processed successfully.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: notebook-tests | ||
services: | ||
mongo: | ||
image: mongo:latest | ||
ports: | ||
- "27017:27017" | ||
redis: | ||
image: redis:latest | ||
ports: | ||
- "6379:6379" | ||
postgres: | ||
image: postgres:16 | ||
ports: | ||
- "5442:5432" | ||
environment: | ||
POSTGRES_DB: postgres | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: postgres | ||
healthcheck: | ||
test: pg_isready -U postgres | ||
start_period: 10s | ||
timeout: 1s | ||
retries: 5 | ||
interval: 60s | ||
start_interval: 1s |
Oops, something went wrong.