Skip to content

Commit

Permalink
add nbtest job to the GitHub Actions CI
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Jan 31, 2024
1 parent fb3ea3a commit 5ac3f48
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 6 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: notebook-tests
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
tests:
runs-on: ubuntu-latest
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.12.0
env:
discovery.type: single-node
xpack.security.enabled: false
xpack.security.http.ssl.enabled: false
xpack.license.self_generated.type: trial
ports:
- 9200:9200
steps:
- uses: actions/checkout@v4
- run: sleep 30
- run: MOCK_ES=1 FORCE_COLOR=1 make test
13 changes: 8 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@

test: nbtest notebooks

notebooks: search document-chunking model-upgrades langchain
notebooks: search document-chunking model-upgrades langchain hugging-face

search:
$(MAKE) -C notebooks/search
$(MAKE) -s --no-print-directory -C notebooks/search

document-chunking:
$(MAKE) -C notebooks/document-chunking
$(MAKE) -s --no-print-directory -C notebooks/document-chunking

model-upgrades:
$(MAKE) -C notebooks/model-upgrades
$(MAKE) -s --no-print-directory -C notebooks/model-upgrades

langchain:
$(MAKE) -C notebooks/langchain
$(MAKE) -s --no-print-directory -C notebooks/langchain

hugging-face:
$(MAKE) -s --no-print-directory -C notebooks/integrations/hugging-face

install: pre-commit nbtest

Expand Down
Empty file added bin/__init__.py
Empty file.
18 changes: 18 additions & 0 deletions bin/mocks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This module is provided to nbtest when running under GitHub Actions CI to
# mock the Elasticsearch client to always connect on localhost, regardless of
# arguments provided

import elasticsearch

orig_es_init = elasticsearch.Elasticsearch.__init__


def patched_es_init(self, *args, **kwargs):
if 'cloud_id' in kwargs:
assert kwargs['cloud_id'] == 'foo'
if 'api_key' in kwargs:
assert kwargs['api_key'] == 'bar'
return orig_es_init(self, 'http://localhost:9200')


elasticsearch.Elasticsearch.__init__ = patched_es_init
14 changes: 13 additions & 1 deletion bin/nbtest
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,17 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
if [[ ! -f $SCRIPT_DIR/../.venv/bin/nbtest ]]; then
make nbtest
fi

NBTEST="nbtest"
if [[ "$MOCK_ES" != "" ]]; then
export ELASTIC_CLOUD_ID=foo
export ELASTIC_API_KEY=bar
export PYTHONPATH=$SCRIPT_DIR
NBTEST="$NBTEST --mocks mocks"

# ensure elasticsearch is installed so that it can be mocked
$SCRIPT_DIR/../.venv/bin/pip install -q elasticsearch
fi

source $SCRIPT_DIR/../.venv/bin/activate
$SCRIPT_DIR/../.venv/bin/nbtest $*
$SCRIPT_DIR/../.venv/bin/$NBTEST $*
2 changes: 2 additions & 0 deletions notebooks/integrations/hugging-face/.nbtest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
masks:
- 'Score: [0-9]+\.[0-9][0-9]*'

0 comments on commit 5ac3f48

Please sign in to comment.