Skip to content

Commit 1c34620

Browse files
committed
run each notebook as its own independent check
use hunggingface cli via poetry upload artifacts after setup source the venv only copy in nltk-data from tmp only upload necessary data as artifacts
1 parent 917e41d commit 1c34620

File tree

2 files changed

+53
-50
lines changed

2 files changed

+53
-50
lines changed

.github/workflows/examples_check.yml

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,50 +6,71 @@ on:
66
workflow_dispatch: # This enables manual triggering
77

88
jobs:
9-
execute_notebooks:
9+
setup:
1010
runs-on: ubuntu-latest
11-
1211
env:
1312
COHERE_API_KEY: ${{ secrets.COHERE_API_KEY }}
1413
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
1514
HUGGINGFACE_API_KEY: ${{ secrets.HUGGINGFACE_API_KEY }}
16-
17-
1815
steps:
1916
- name: Checkout repository
20-
uses: actions/checkout@v2
21-
17+
uses: actions/checkout@v2
2218
- name: Set up Python
2319
uses: actions/setup-python@v2
24-
with:
20+
with:
2521
python-version: 3.11.x
26-
2722
- name: Poetry cache
2823
uses: actions/cache@v3
2924
with:
3025
path: ~/.cache/pypoetry
3126
key: poetry-cache-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ env.POETRY_VERSION }}
32-
3327
- name: Install Poetry
3428
uses: snok/install-poetry@v1
3529
with:
36-
virtualenvs-create: true
37-
virtualenvs-in-project: true
38-
installer-parallel: true
39-
30+
virtualenvs-create: true
31+
virtualenvs-in-project: true
32+
installer-parallel: true
4033
- name: Install dependencies
4134
run: |
4235
make full;
4336
poetry add openai==0.28.1 jupyter nbconvert cohere;
44-
# pip install openai==0.28.1 jupyter nbconvert;
45-
# pip install .;
46-
4737
- name: Check for pypdfium2
4838
run: poetry run pip show pypdfium2
49-
5039
- name: Huggingface Hub Login
51-
run: huggingface-cli login --token $HUGGINGFACE_API_KEY
40+
run: poetry run huggingface-cli login --token $HUGGINGFACE_API_KEY
41+
- name: download nltk data
42+
run: |
43+
mkdir /tmp/nltk_data;
44+
poetry run python -m nltk.downloader -d /tmp/nltk_data punkt;
45+
- name: Upload artifacts
46+
uses: actions/upload-artifact@v3
47+
with:
48+
path: |
49+
/tmp/nltk_data
50+
./.venv
51+
./guardrails
52+
~/.cache/pypoetry
53+
54+
execute_notebooks:
55+
runs-on: ubuntu-latest
56+
needs: setup
57+
strategy:
58+
matrix:
59+
notebook: [ "*.ipynb" ]
60+
env:
61+
COHERE_API_KEY: ${{ secrets.COHERE_API_KEY }}
62+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
63+
HUGGINGFACE_API_KEY: ${{ secrets.HUGGINGFACE_API_KEY }}
64+
NLTK_DATA: /tmp/nltk_data
65+
5266

67+
steps:
68+
- name: Download artifacts
69+
uses: actions/download-artifact@v3
70+
with:
71+
name: setup-artifacts
72+
- name: Use venv
73+
run: source .venv/bin/activate
5374
- name: Execute notebooks and check for errors
54-
run: ./.github/workflows/scripts/run_notebooks.sh
75+
run: bash ./.github/workflows/scripts/run_notebooks.sh ${{ matrix.notebook }}
5576

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,20 @@
11
#!/bin/bash
2-
3-
mkdir /tmp/nltk_data;
4-
poetry run python -m nltk.downloader -d /tmp/nltk_data punkt;
52
export NLTK_DATA=/tmp/nltk_data;
63

74
cd docs/examples
85

9-
# Function to process a notebook
10-
process_notebook() {
11-
notebook="$1"
12-
invalid_notebooks=("valid_chess_moves.ipynb" "llamaindex-output-parsing.ipynb" "competitors_check.ipynb")
13-
if [[ ! " ${invalid_notebooks[@]} " =~ " ${notebook} " ]]; then
14-
echo "Processing $notebook..."
15-
poetry run jupyter nbconvert --to notebook --execute "$notebook"
16-
if [ $? -ne 0 ]; then
17-
echo "Error found in $notebook"
18-
echo "Error in $notebook. See logs for details." >> errors.txt
19-
fi
20-
fi
21-
}
22-
23-
export -f process_notebook # Export the function for parallel execution
24-
25-
# Create a file to collect errors
26-
> errors.txt
6+
# Get the notebook name from the matrix variable
7+
notebook="$1"
278

28-
# Run in parallel
29-
ls *.ipynb | parallel process_notebook
9+
# Check if the notebook should be processed
10+
invalid_notebooks=("valid_chess_moves.ipynb" "llamaindex-output-parsing.ipynb" "competitors_check.ipynb")
11+
if [[ ! " ${invalid_notebooks[@]} " =~ " ${notebook} " ]]; then
12+
echo "Processing $notebook..."
13+
poetry run jupyter nbconvert --to notebook --execute "$notebook"
14+
if [ $? -ne 0 ]; then
15+
echo "Error found in $notebook"
16+
echo "Error in $notebook. See logs for details." >> errors.txt
17+
fi
18+
fi
3019

31-
# Check if there were any errors
32-
if [ -s errors.txt ]; then
33-
echo "Some notebooks had errors"
34-
cat errors.txt
35-
exit 1
36-
else
37-
echo "All notebooks ran successfully."
38-
fi
20+
exit 0

0 commit comments

Comments
 (0)