-
Notifications
You must be signed in to change notification settings - Fork 118
128 lines (109 loc) · 4.36 KB
/
run_tutorials.yml
File metadata and controls
128 lines (109 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
name: Run Tutorials
on:
workflow_dispatch: # Activate this workflow manually
schedule:
- cron: "0 0 * * *"
pull_request:
paths:
- "tutorials/*.ipynb"
jobs:
generate-matrix:
runs-on: ubuntu-slim
outputs:
matrix: ${{ steps.matrix.outputs.matrix }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: "3.11"
- id: generator
env:
GH_TOKEN: ${{ github.token }}
run: |
# Get tutorial notebooks
VERSION=$(gh api /repos/deepset-ai/haystack/releases | \
jq -r '[.[].tag_name | select(test("^v2.[0-9]+.[0-9]+$"))] | first')
NOTEBOOKS=$(python ./scripts/generate_matrix.py --haystack-version "$VERSION" --include-main)
echo "matrix={\"include\":$NOTEBOOKS}" >> "$GITHUB_OUTPUT"
- name: Get changed files
if: github.event_name == 'pull_request'
id: files
uses: tj-actions/changed-files@24d32ffd492484c1d75e0c0b894501ddb9d30d62 # v47.0.0
with:
matrix: true
files: tutorials/*.ipynb
- name: Filter to changed notebooks (pull request only)
id: matrix
shell: python
env:
EVENT_NAME: ${{ github.event_name }}
MATRIX: ${{ steps.generator.outputs.matrix }}
CHANGED_FILES: ${{ steps.files.outputs.all_changed_files }}
run: |
import os
import json
matrix = json.loads(os.environ["MATRIX"])
if os.environ["EVENT_NAME"] == "pull_request":
changed_files = json.loads(os.environ["CHANGED_FILES"])
new_matrix = {"include": []}
for item in matrix["include"]:
notebook = item["notebook"]
if f"tutorials/{notebook}.ipynb" in changed_files:
new_matrix["include"].append(item)
matrix = new_matrix
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
print(f"matrix={json.dumps(matrix)}", file=f)
run-tutorials:
needs: generate-matrix
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.generate-matrix.outputs.matrix) }}
env:
HAYSTACK_TELEMETRY_ENABLED: "False"
HF_API_TOKEN: ${{ secrets.HF_API_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
SERPERDEV_API_KEY: ${{ secrets.SERPERDEV_API_KEY }}
NOTION_API_KEY: ${{ secrets.NOTION_API_KEY }}
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup Python and uv
uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7.6.0
with:
python-version: "3.11"
- name: Install common dependencies
run: |
uv venv
if [ "${{ matrix.haystack_version }}" = "main" ]; then
uv pip install "haystack-ai @ git+https://github.com/deepset-ai/haystack.git@main"
else
VERSION="${{ matrix.haystack_version }}"
uv pip install "haystack-ai==${VERSION#v}"
fi
uv pip install nbconvert ipython
- name: Install tutorial dependencies
if: toJSON(matrix.dependencies) != '[]'
run: |
uv pip install "${{ join(matrix.dependencies, '" "')}}"
- name: Convert notebook to Python
run: |
. .venv/bin/activate
jupyter nbconvert --to python --RegexRemovePreprocessor.patterns '%%bash' ./tutorials/${{ matrix.notebook }}.ipynb
- name: Run the converted notebook
run: |
. .venv/bin/activate
NOTEBOOK="./tutorials/${{ matrix.notebook }}.py"
if [ "${{ matrix.notebook }}" = "47_Human_in_the_Loop_Agent" ]; then
# We add a prompt to confirm any user inputs in the HiTL notebook
yes y | python "$NOTEBOOK"
elif [ "${{ matrix.notebook }}" = "48_Conversational_RAG" ]; then
yes Q | python "$NOTEBOOK"
else
python "$NOTEBOOK"
fi
- name: Notify Slack on nightly failure
if: failure() && github.event_name != 'pull_request'
uses: deepset-ai/notify-slack-action@3cda73b77a148f16f703274198e7771340cf862b # v1
with:
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL_NOTIFICATIONS }}