Tests - Nightly Run #1
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
name: Tests - Nightly Run | |
on: | |
schedule: | |
- cron: "0 3 * * *" # 3 AM UTC nightly | |
workflow_dispatch: | |
env: | |
PYTHON_VERSION: "3.11" | |
jobs: | |
# --------------------------------------------------------- | |
# 1) Gather all notebooks (except skip-list) | |
# --------------------------------------------------------- | |
gather_all_notebooks: | |
runs-on: ubuntu-latest | |
outputs: | |
notebooks: ${{ steps.get_nbs.outputs.notebooks }} | |
has_notebooks: ${{ steps.get_nbs.outputs.has_notebooks }} | |
steps: | |
- uses: actions/checkout@v3 | |
- id: get_nbs | |
run: | | |
# 1) Find all available notebooks | |
NBS=$(find python-recipes -name '*.ipynb') | |
# 2) Load notebooks to ignore | |
IGNORE_LIST=() | |
while IFS= read -r skip_nb || [ -n "$skip_nb" ]; do | |
# Skip empty lines or comment lines | |
[[ -z "$skip_nb" || "$skip_nb" =~ ^# ]] && continue | |
IGNORE_LIST+=("$skip_nb") | |
done < .github/ignore-notebooks.txt | |
# 3) Filter out notebooks that match anything in IGNORE_LIST | |
FILTERED_NBS=() | |
for nb in $NBS; do | |
skip=false | |
for ignore_nb in "${IGNORE_LIST[@]}"; do | |
if [[ "$nb" == *"$ignore_nb"* ]]; then | |
skip=true | |
break | |
fi | |
done | |
if [ "$skip" = false ]; then | |
FILTERED_NBS+=("$nb") | |
fi | |
done | |
# 4) Stuff into a single-line JSON array | |
NB_JSON=$(printf '%s\n' "${FILTERED_NBS[@]}" \ | |
| jq -R . \ | |
| jq -s -c .) | |
if [ -z "$NB_JSON" ] || [ "$NB_JSON" = "[]" ]; then | |
NB_JSON="[]" | |
fi | |
echo "All valid notebooks: $NB_JSON" | |
# 5) Check if there's anything in FILTERED_NBS | |
if [ "${#FILTERED_NBS[@]}" -gt 0 ]; then | |
echo "has_notebooks=true" >> $GITHUB_OUTPUT | |
else | |
echo "has_notebooks=false" >> $GITHUB_OUTPUT | |
fi | |
echo "notebooks=$NB_JSON" >> $GITHUB_OUTPUT | |
# --------------------------------------------------------- | |
# 2) Test all notebooks in parallel | |
# --------------------------------------------------------- | |
test_all_notebooks: | |
if: ${{ needs.gather_all_notebooks.outputs.has_notebooks == 'true' }} | |
needs: gather_all_notebooks | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
notebook: ${{ fromJson(needs.gather_all_notebooks.outputs.notebooks) }} | |
services: | |
redis: | |
image: redis/redis-stack-server:latest | |
ports: | |
- 6379:6379 | |
steps: | |
- uses: actions/checkout@v3 | |
# Setup Python | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ env.PYTHON_VERSION }} | |
- name: Create and activate venv | |
run: | | |
python -m venv venv | |
source venv/bin/activate | |
pip install --upgrade pip setuptools wheel | |
pip install pytest nbval | |
- name: Test notebook | |
env: | |
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | |
COHERE_API_KEY: ${{ secrets.COHERE_API_KEY }} | |
run: | | |
echo "Testing notebook: ${{ matrix.notebook }}" | |
source venv/bin/activate | |
pytest --nbval-lax --disable-warnings "${{ matrix.notebook }}" |