Skip to content

Commit f9040c0

Browse files
committed
use a script to populate notebook matrix
use notebook matrixed strategy in ci
1 parent 052149e commit f9040c0

File tree

4 files changed

+66
-42
lines changed

4 files changed

+66
-42
lines changed

.github/workflows/ci.yml

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -144,46 +144,46 @@ jobs:
144144
runs-on: ubuntu-latest
145145
if: ${{ always() && contains(join(needs.*.result, ','), 'success') }}
146146
needs: [Linting, Typing, Pytests]
147-
147+
strategy:
148+
matrix:
149+
# this line is automatically generated by the script in .github/workflows/scripts/update_notebook_matrix.sh
150+
notebook: ["bug_free_python_code.ipynb","check_for_pii.ipynb","competitors_check.ipynb","extracting_entities.ipynb","generate_structured_data.ipynb","generate_structured_data_cohere.ipynb","guardrails_with_chat_models.ipynb","input_validation.ipynb","llamaindex-output-parsing.ipynb","no_secrets_in_generated_text.ipynb","provenance.ipynb","recipe_generation.ipynb","regex_validation.ipynb","response_is_on_topic.ipynb","secrets_detection.ipynb","select_choice_based_on_action.ipynb","streaming.ipynb","syntax_error_free_sql.ipynb","text_summarization_quality.ipynb","toxic_language.ipynb","translation_to_specific_language.ipynb","translation_with_quality_check.ipynb","valid_chess_moves.ipynb","value_within_distribution.ipynb"]
148151
env:
149-
COHERE_API_KEY: ${{ secrets.COHERE_API_KEY }}
150-
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
151-
HUGGINGFACE_API_KEY: ${{ secrets.HUGGINGFACE_API_KEY }}
152-
152+
COHERE_API_KEY: ${{ secrets.COHERE_API_KEY }}
153+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
154+
HUGGINGFACE_API_KEY: ${{ secrets.HUGGINGFACE_API_KEY }}
155+
NLTK_DATA: /tmp/nltk_data
153156
steps:
154-
- name: Checkout repository
155-
uses: actions/checkout@v2
156-
157-
- name: Set up Python
158-
uses: actions/setup-python@v2
159-
with:
160-
python-version: 3.11.x
161-
162-
- name: Poetry cache
163-
uses: actions/cache@v3
164-
with:
165-
path: ~/.cache/pypoetry
166-
key: poetry-cache-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ env.POETRY_VERSION }}
167-
168-
- name: Install Poetry
169-
uses: snok/install-poetry@v1
170-
with:
171-
virtualenvs-create: true
172-
virtualenvs-in-project: true
173-
installer-parallel: true
174-
175-
- name: Install dependencies
176-
run: |
177-
make full;
178-
poetry add openai==0.28.1 jupyter nbconvert cohere;
179-
# pip install openai==0.28.1 jupyter nbconvert;
180-
# pip install .;
181-
182-
- name: Check for pypdfium2
183-
run: poetry run pip show pypdfium2
184-
185-
- name: Huggingface Hub Login
186-
run: poetry run huggingface-cli login --token $HUGGINGFACE_API_KEY
187-
188-
- name: Execute notebooks and check for errors
189-
run: ./.github/workflows/scripts/run_notebooks.sh
157+
- name: Checkout repository
158+
uses: actions/checkout@v2
159+
- name: Set up Python
160+
uses: actions/setup-python@v2
161+
with:
162+
python-version: 3.11.x
163+
- name: Poetry cache
164+
uses: actions/cache@v3
165+
with:
166+
path: ~/.cache/pypoetry
167+
key: poetry-cache-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ env.POETRY_VERSION }}
168+
- name: Install Poetry
169+
uses: snok/install-poetry@v1
170+
with:
171+
virtualenvs-create: true
172+
virtualenvs-in-project: true
173+
installer-parallel: true
174+
- name: Install dependencies
175+
run: |
176+
make full;
177+
poetry add openai==0.28.1 jupyter nbconvert cohere;
178+
- name: Check for pypdfium2
179+
run: poetry run pip show pypdfium2
180+
- name: Huggingface Hub Login
181+
run: poetry run huggingface-cli login --token $HUGGINGFACE_API_KEY
182+
- name: download nltk data
183+
run: |
184+
mkdir /tmp/nltk_data;
185+
poetry run python -m nltk.downloader -d /tmp/nltk_data punkt;
186+
- name: Use venv
187+
run: source .venv/bin/activate
188+
- name: Execute notebooks and check for errors
189+
run: bash ./.github/workflows/scripts/run_notebooks.sh ${{ matrix.notebook }}

.github/workflows/examples_check.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ jobs:
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
13-
notebook: [ "*.ipynb" ]
13+
# this line is automatically generated by the script in .github/workflows/scripts/update_notebook_matrix.sh
14+
notebook: ["bug_free_python_code.ipynb","check_for_pii.ipynb","competitors_check.ipynb","extracting_entities.ipynb","generate_structured_data.ipynb","generate_structured_data_cohere.ipynb","guardrails_with_chat_models.ipynb","input_validation.ipynb","llamaindex-output-parsing.ipynb","no_secrets_in_generated_text.ipynb","provenance.ipynb","recipe_generation.ipynb","regex_validation.ipynb","response_is_on_topic.ipynb","secrets_detection.ipynb","select_choice_based_on_action.ipynb","streaming.ipynb","syntax_error_free_sql.ipynb","text_summarization_quality.ipynb","toxic_language.ipynb","translation_to_specific_language.ipynb","translation_with_quality_check.ipynb","valid_chess_moves.ipynb","value_within_distribution.ipynb"]
1415
env:
1516
COHERE_API_KEY: ${{ secrets.COHERE_API_KEY }}
1617
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
# Array to store notebook names
3+
notebook_names="["
4+
5+
# Compile list of file names
6+
for file in $(ls docs/examples/*.ipynb); do
7+
# Add the full filename with extension
8+
filename=$(basename "$file")
9+
10+
notebook_names+="\"$filename\","
11+
done
12+
notebook_names="${notebook_names%,}]"
13+
14+
# echo $notebook_names
15+
16+
17+
# find line that begins with "notebook:" and replace it with notebook: $notebook_names
18+
sed "s/notebook: \[.*\]/notebook: $notebook_names/" .github/workflows/examples_check.yml > .github/workflows/examples_check.yml.tmp
19+
mv .github/workflows/examples_check.yml.tmp .github/workflows/examples_check.yml
20+
21+
sed "s/notebook: \[.*\]/notebook: $notebook_names/" .github/workflows/ci.yml > .github/workflows/ci.yml.tmp
22+
mv .github/workflows/ci.yml.tmp .github/workflows/ci.yml

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,4 @@ precommit:
7171
# pytest -x -q --no-summary
7272
pyright guardrails/
7373
make lint
74+
./github/workflows/scripts/update_notebook_matrix.sh

0 commit comments

Comments
 (0)