diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml deleted file mode 100644 index 22f2f496..00000000 --- a/.github/workflows/nightly.yml +++ /dev/null @@ -1,95 +0,0 @@ -name: Run Tutorials Nightly - -on: - workflow_dispatch: # Activate this workflow manually - schedule: - - cron: "0 0 * * *" - -jobs: - generate-matrix: - runs-on: ubuntu-latest - outputs: - matrix_v2: ${{ steps.generator.outputs.matrix_v2 }} - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - 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_v2={\"include\":$NOTEBOOKS}" >> "$GITHUB_OUTPUT" - - run-tutorials: - needs: generate-matrix - runs-on: ubuntu-latest - container: deepset/haystack:base-${{ matrix.haystack_version }} - - strategy: - max-parallel: 2 - fail-fast: false - matrix: ${{ fromJSON(needs.generate-matrix.outputs.matrix_v2) }} - - 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@v4 - - - name: Install common dependencies - run: | - apt-get update && apt-get install -y \ - build-essential \ - gcc \ - libsndfile1 \ - ffmpeg - - pip install nbconvert ipython - - - name: Install tutorial dependencies - if: toJSON(matrix.dependencies) != '[]' - run: | - pip install "${{ join(matrix.dependencies, '" "')}}" - - - name: Convert notebook to Python - run: | - jupyter nbconvert --to python --RegexRemovePreprocessor.patterns '%%bash' ./tutorials/${{ matrix.notebook }}.ipynb - - - name: Run the converted notebook - run: | - 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: Send Failure to Datadog - if: failure() - uses: masci/datadog@v1 - with: - api-key: ${{ secrets.CORE_DATADOG_API_KEY }} - api-url: https://api.datadoghq.eu - events: | - - title: "Tutorial ${{ matrix.notebook }} failed" - text: "Branch ${{ github.ref_name }} tests failed" - alert_type: "error" - source_type_name: "Github" - host: ${{ github.repository_owner }} - tags: - - "project:${{ github.repository }}" - - "name:${{ matrix.notebook }}" - - "url:https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" diff --git a/.github/workflows/run_tutorials.yml b/.github/workflows/run_tutorials.yml index 7fc46d6c..313b3c26 100644 --- a/.github/workflows/run_tutorials.yml +++ b/.github/workflows/run_tutorials.yml @@ -1,19 +1,22 @@ -name: Run Haystack Tutorials +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-latest + runs-on: ubuntu-slim outputs: - matrix: ${{ steps.filter.outputs.matrix }} + matrix: ${{ steps.matrix.outputs.matrix }} steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - - uses: actions/setup-python@v5 + - uses: actions/setup-python@v6 with: python-version: "3.11" @@ -28,16 +31,18 @@ jobs: echo "matrix={\"include\":$NOTEBOOKS}" >> "$GITHUB_OUTPUT" - name: Get changed files + if: github.event_name == 'pull_request' id: files - uses: tj-actions/changed-files@v46 + uses: tj-actions/changed-files@v47 with: matrix: true files: tutorials/*.ipynb - - name: Filter non changed notebooks - id: filter + - 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: | @@ -45,22 +50,22 @@ jobs: import json matrix = json.loads(os.environ["MATRIX"]) - changed_files = json.loads(os.environ["CHANGED_FILES"]) - new_matrix = {"include": []} - for item in matrix["include"]: - notebook = item["notebook"] - if f"tutorials/{notebook}.ipynb" not in changed_files: - continue - new_matrix["include"].append(item) - - new_matrix = json.dumps(new_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={new_matrix}", file=f) + print(f"matrix={json.dumps(matrix)}", file=f) run-tutorials: - runs-on: ubuntu-latest needs: generate-matrix - container: deepset/haystack:base-${{ matrix.haystack_version }} + runs-on: ubuntu-latest strategy: fail-fast: false @@ -75,29 +80,37 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v6 + + - name: Setup Python and uv + uses: astral-sh/setup-uv@v7 + with: + python-version: "3.11" - name: Install common dependencies run: | - apt-get update && apt-get install -y \ - build-essential \ - gcc \ - libsndfile1 \ - ffmpeg - - pip install nbconvert ipython + 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: | - pip install "${{ join(matrix.dependencies, '" "')}}" + 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 @@ -107,3 +120,9 @@ jobs: else python "$NOTEBOOK" fi + + - name: Notify Slack on nightly failure + if: failure() && github.event_name != 'pull_request' + uses: deepset-ai/notify-slack-action@v1 + with: + slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL_NOTIFICATIONS }} diff --git a/.github/workflows/verify_generation.yml b/.github/workflows/verify_generation.yml index c4a51c1e..a1ae337e 100644 --- a/.github/workflows/verify_generation.yml +++ b/.github/workflows/verify_generation.yml @@ -7,20 +7,24 @@ on: - "index.toml" jobs: - run-tutorials: - runs-on: ubuntu-latest + verify-markdown-generation: + runs-on: ubuntu-slim steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - - uses: actions/setup-python@v5 + - name: Setup Python and uv + uses: astral-sh/setup-uv@v7 with: - python-version: "3.10" + python-version: "3.11" - name: Install dependencies - run: pip install -r requirements.txt + run: | + uv venv + uv pip install -r requirements.txt - name: Generate all tutorials run: | + . .venv/bin/activate mkdir output python scripts/generate_markdowns.py --index index.toml --notebooks all --output ./output