Add Context Engineering Course with Redis University Class Agent #447
This file contains hidden or 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 - PR/Push | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| env: | |
| PYTHON_VERSION: "3.11" | |
| jobs: | |
| # --------------------------------------------------------- | |
| # 1) Gather the changed notebooks to produce a matrix list | |
| # --------------------------------------------------------- | |
| gather_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 | |
| - name: Gather notebooks | |
| id: get_nbs | |
| run: | | |
| # 1) Compare this commit/PR to 'main' and list changed notebooks | |
| git fetch --depth=1 origin main | |
| CHANGED_NOTEBOOKS=$(git diff --name-only origin/main | grep '\.ipynb$' || true) | |
| # 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 ignored notebooks | |
| FILTERED_NBS=() | |
| for nb in $CHANGED_NOTEBOOKS; do | |
| skip=false | |
| # Check if in ignore list | |
| for ignore_nb in "${IGNORE_LIST[@]}"; do | |
| # Partial match: | |
| 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 each changed notebook in parallel | |
| # --------------------------------------------------------- | |
| test_notebooks: | |
| if: ${{ needs.gather_notebooks.outputs.has_notebooks == 'true' }} | |
| needs: gather_notebooks | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| notebook: ${{ fromJson(needs.gather_notebooks.outputs.notebooks) }} | |
| services: | |
| redis: | |
| image: redis:8.2 | |
| ports: | |
| - 6379:6379 | |
| options: >- | |
| --health-cmd "redis-cli ping" | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| steps: | |
| - uses: actions/checkout@v3 | |
| # Setup Python | |
| - uses: actions/setup-python@v4 | |
| with: | |
| python-version: ${{ env.PYTHON_VERSION }} | |
| # Start Agent Memory Server | |
| - name: Start Agent Memory Server | |
| env: | |
| OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | |
| run: | | |
| # Start the Agent Memory Server | |
| docker run -d \ | |
| --name agent-memory-server \ | |
| --network host \ | |
| -e REDIS_URL=redis://localhost:6379 \ | |
| -e OPENAI_API_KEY=$OPENAI_API_KEY \ | |
| -e LOG_LEVEL=INFO \ | |
| ghcr.io/redis/agent-memory-server:latest | |
| # Wait for memory server to be ready | |
| echo "Waiting for Agent Memory Server to be ready..." | |
| for i in {1..30}; do | |
| if curl -f http://localhost:8000/health 2>/dev/null; then | |
| echo "✅ Agent Memory Server is ready!" | |
| break | |
| fi | |
| echo "Waiting... ($i/30)" | |
| sleep 2 | |
| done | |
| # Show status but don't fail if server isn't ready | |
| if curl -f http://localhost:8000/health 2>/dev/null; then | |
| echo "✅ Agent Memory Server is healthy" | |
| else | |
| echo "⚠️ WARNING: Agent Memory Server may not be ready" | |
| echo "Docker logs:" | |
| docker logs agent-memory-server || true | |
| fi | |
| - name: Create and activate venv | |
| run: | | |
| python -m venv venv | |
| source venv/bin/activate | |
| pip install --upgrade pip setuptools wheel | |
| pip install pytest nbval | |
| # Install the redis-context-course package and its dependencies | |
| cd python-recipes/context-engineering/reference-agent | |
| pip install -e . | |
| - name: Test notebook | |
| env: | |
| OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | |
| COHERE_API_KEY: ${{ secrets.COHERE_API_KEY }} | |
| AGENT_MEMORY_URL: http://localhost:8000 | |
| REDIS_URL: redis://localhost:6379 | |
| run: | | |
| echo "Testing notebook: ${{ matrix.notebook }}" | |
| source venv/bin/activate | |
| pytest --nbval-lax --disable-warnings "${{ matrix.notebook }}" | |
| - name: Show Agent Memory Server logs on failure | |
| if: failure() | |
| run: | | |
| docker logs agent-memory-server |