Overhaul to github actions workflows #177
Workflow file for this run
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 - 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 }} | |
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) | |
# 1) Read ignore patterns from a file named notebooks-ignore.txt | |
IGNORE_LIST=() | |
while IFS= read -r skip_nb; do | |
IGNORE_LIST+=("$skip_nb") | |
done < .github/ignore-notebooks.txt | |
# 2) Filter out notebooks in CHANGED_NOTEBOOKS that match ignore patterns | |
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 | |
# 3) Build a single-line JSON array | |
NB_JSON=$(printf '%s\n' "${FILTERED_NBS[@]}" \ | |
| jq -R . \ | |
| jq -s -c .) | |
# 4) Fallback to an empty array if there's nothing left | |
if [ -z "$NB_JSON" ] || [ "$NB_JSON" = "[]" ]; then | |
NB_JSON="[]" | |
fi | |
echo "All valid notebooks: $NB_JSON" | |
# 5) Write to $GITHUB_OUTPUT (modern approach instead of ::set-output) | |
echo "notebooks=$NB_JSON" >> $GITHUB_OUTPUT | |
# --------------------------------------------------------- | |
# 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: ${{ 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 }}" |