Overhaul to github actions workflows #166
Workflow file for this run
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: Notebooks - PR/Push | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| # --------------------------------------------------------- | |
| # 1) Gather the changed notebooks to produce a matrix list | |
| # --------------------------------------------------------- | |
| gather_notebooks: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| notebooks: ${{ steps.get_nbs.outputs.notebooks }} | |
| steps: | |
| - uses: actions/checkout@v2 | |
| - id: get_nbs | |
| run: | | |
| # Compare this commit/PR to 'main' and list changed .ipynb files | |
| git fetch --depth=1 origin main | |
| CHANGED_NOTEBOOKS=$(git diff --name-only origin/main | grep '\.ipynb$' || true) | |
| # Optional: skip list or skip tag | |
| IGNORE_LIST=("experimental_notebook.ipynb") | |
| FILTERED_NBS=() | |
| for nb in $CHANGED_NOTEBOOKS; do | |
| skip=false | |
| # Check if in ignore list | |
| 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 | |
| # Convert filtered list into JSON array so it can be passed to matrix | |
| NB_JSON=$(printf '%s\n' "${FILTERED_NBS[@]}" | jq -R . | jq -s .) | |
| echo "Changed notebooks: $NB_JSON" | |
| echo "::set-output name=notebooks::$NB_JSON" | |
| # --------------------------------------------------------- | |
| # 2) Test each changed notebook in parallel | |
| # --------------------------------------------------------- | |
| test_notebooks: | |
| needs: gather_notebooks | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| notebook: ${{ fromJson(needs.gather_notebooks.outputs.notebooks) }} | |
| services: | |
| redis: | |
| image: redis/redis-stack-server:latest | |
| ports: | |
| - 6379:6379 | |
| steps: | |
| - uses: actions/checkout@v2 | |
| # Setup Python | |
| - uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.11' | |
| # # Use caching to speed up repeated installs of test dependencies | |
| # - name: Cache pip | |
| # uses: actions/cache@v3 | |
| # with: | |
| # path: ~/.cache/pip | |
| # key: ${{ runner.os }}-pip-${{ hashFiles('requirements-test.txt') }} | |
| # restore-keys: ${{ runner.os }}-pip- | |
| - 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 }} | |
| LLAMA_CLOUD_API_KEY: ${{ secrets.LLAMA_CLOUD_API_KEY }} | |
| GCP_REGION: ${{ secrets.GCP_REGION }} | |
| GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }} | |
| run: | | |
| echo "Testing notebook: ${{ matrix.notebook }}" | |
| source venv/bin/activate | |
| pytest --nbval-lax --disable-warnings "${{ matrix.notebook }}" |