|
1 | | -name: Test Suite |
| 1 | +name: Tests - PR/Push |
2 | 2 |
|
3 | 3 | on: |
4 | | - pull_request: |
5 | | - branches: |
6 | | - - main |
7 | 4 | push: |
8 | | - branches: |
9 | | - - main |
10 | | - schedule: |
11 | | - - cron: '0 0 * * 1' # Runs every Monday |
| 5 | + branches: [ main ] |
| 6 | + pull_request: |
| 7 | + branches: [ main ] |
| 8 | + |
| 9 | +env: |
| 10 | + PYTHON_VERSION: "3.11" |
12 | 11 |
|
13 | 12 | jobs: |
14 | | - test: |
15 | | - name: Python ${{ matrix.python-version }} - ${{ matrix.connection }} [redis-stack ${{matrix.redis-stack-version}}] |
| 13 | + # --------------------------------------------------------- |
| 14 | + # 1) Gather the changed notebooks to produce a matrix list |
| 15 | + # --------------------------------------------------------- |
| 16 | + gather_notebooks: |
16 | 17 | runs-on: ubuntu-latest |
| 18 | + outputs: |
| 19 | + notebooks: ${{ steps.get_nbs.outputs.notebooks }} |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v2 |
| 22 | + |
| 23 | + - id: get_nbs |
| 24 | + run: | |
| 25 | + # Compare this commit/PR to 'main' and list changed .ipynb files |
| 26 | + git fetch --depth=1 origin main |
| 27 | + CHANGED_NOTEBOOKS=$(git diff --name-only origin/main | grep '\.ipynb$' || true) |
| 28 | + |
| 29 | + # 1) Read ignore patterns from .github/ignore-notebooks.txt |
| 30 | + IGNORE_LIST=() |
| 31 | + while IFS= read -r skip_nb || [ -n "$skip_nb" ]; do |
| 32 | + # Skip empty lines or comment lines |
| 33 | + [[ -z "$skip_nb" || "$skip_nb" =~ ^# ]] && continue |
| 34 | + IGNORE_LIST+=("$skip_nb") |
| 35 | + done < .github/ignore-notebooks.txt |
| 36 | + |
| 37 | + # 2) Filter out notebooks in CHANGED_NOTEBOOKS that match ignore patterns |
| 38 | + FILTERED_NBS=() |
| 39 | + for nb in $CHANGED_NOTEBOOKS; do |
| 40 | + skip=false |
| 41 | + |
| 42 | + # Check if in ignore list |
| 43 | + for ignore_nb in "${IGNORE_LIST[@]}"; do |
| 44 | + # Partial match: |
| 45 | + if [[ "$nb" == *"$ignore_nb"* ]]; then |
| 46 | + skip=true |
| 47 | + break |
| 48 | + fi |
| 49 | + done |
| 50 | + |
| 51 | + if [ "$skip" = false ]; then |
| 52 | + FILTERED_NBS+=("$nb") |
| 53 | + fi |
| 54 | + done |
| 55 | + |
| 56 | + # 3) Build a single-line JSON array |
| 57 | + NB_JSON=$(printf '%s\n' "${FILTERED_NBS[@]}" \ |
| 58 | + | jq -R . \ |
| 59 | + | jq -s -c .) |
| 60 | + |
| 61 | + # 4) Fallback to an empty array if there's nothing left |
| 62 | + if [ -z "$NB_JSON" ] || [ "$NB_JSON" = "[]" ]; then |
| 63 | + NB_JSON="[]" |
| 64 | + fi |
| 65 | + |
| 66 | + echo "All valid notebooks: $NB_JSON" |
| 67 | + |
| 68 | + # 5) Write to $GITHUB_OUTPUT (modern approach instead of ::set-output) |
| 69 | + echo "notebooks=$NB_JSON" >> $GITHUB_OUTPUT |
17 | 70 |
|
| 71 | + # --------------------------------------------------------- |
| 72 | + # 2) Test each changed notebook in parallel |
| 73 | + # --------------------------------------------------------- |
| 74 | + test_notebooks: |
| 75 | + needs: gather_notebooks |
| 76 | + runs-on: ubuntu-latest |
18 | 77 | strategy: |
19 | 78 | fail-fast: false |
20 | 79 | matrix: |
21 | | - python-version: [3.11] |
22 | | - connection: ['plain'] |
23 | | - redis-stack-version: ['latest'] |
| 80 | + notebook: ${{ fromJson(needs.gather_notebooks.outputs.notebooks) }} |
24 | 81 |
|
25 | 82 | services: |
26 | 83 | redis: |
27 | | - image: redis/redis-stack-server:${{matrix.redis-stack-version}} |
| 84 | + image: redis/redis-stack-server:latest |
28 | 85 | ports: |
29 | 86 | - 6379:6379 |
30 | 87 |
|
31 | 88 | steps: |
32 | | - - uses: actions/checkout@v2 |
33 | | - - name: Set up Python ${{ matrix.python-version }} |
34 | | - uses: actions/setup-python@v4 |
35 | | - with: |
36 | | - python-version: ${{ matrix.python-version }} |
37 | | - cache: 'pip' |
38 | | - |
39 | | - - name: Install dependencies |
40 | | - run: | |
41 | | - pip install --no-cache-dir -r requirements.txt |
42 | | -
|
43 | | - - name: Set Redis version |
44 | | - run: | |
45 | | - echo "REDIS_VERSION=${{ matrix.redis-stack-version }}" >> $GITHUB_ENV |
46 | | -
|
47 | | - - name: Run notebooks |
48 | | - if: matrix.connection == 'plain' && matrix.redis-stack-version == 'latest' |
49 | | - env: |
50 | | - OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} |
51 | | - LLAMA_CLOUD_API_KEY: ${{ secrets.LLAMA_CLOUD_API_KEY }} |
52 | | - GCP_REGION: ${{ secrets.GCP_REGION }} |
53 | | - GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }} |
54 | | - run: | |
55 | | - pytest --verbose --nbval-lax python-recipes/RAG/ python-recipes/vector-search python-recipes/redis-intro python-recipes/recommendation-systems python-recipes/agents python-recipes/computer-vision --ignore python-recipes/agents/01_crewai_langgraph_redis.ipynb --ignore python-recipes/RAG/05_nvidia_ai_rag_redis.ipynb --ignore python-recipes/semantic-cache/doc2cache_llama3_1.ipynb |
| 89 | + - uses: actions/checkout@v2 |
| 90 | + |
| 91 | + # Setup Python |
| 92 | + - uses: actions/setup-python@v4 |
| 93 | + with: |
| 94 | + python-version: ${{ env.PYTHON_VERSION }} |
| 95 | + |
| 96 | + - name: Create and activate venv |
| 97 | + run: | |
| 98 | + python -m venv venv |
| 99 | + source venv/bin/activate |
| 100 | + pip install --upgrade pip setuptools wheel |
| 101 | + pip install pytest nbval |
| 102 | +
|
| 103 | + - name: Test notebook |
| 104 | + env: |
| 105 | + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} |
| 106 | + COHERE_API_KEY: ${{ secrets.COHERE_API_KEY }} |
| 107 | + run: | |
| 108 | + echo "Testing notebook: ${{ matrix.notebook }}" |
| 109 | + source venv/bin/activate |
| 110 | + pytest --nbval-lax --disable-warnings "${{ matrix.notebook }}" |
0 commit comments