/ .github / workflows / docs-website-test-docs-snippets.yml
docs-website-test-docs-snippets.yml
 1  name: Test Python snippets in docs
 2  
 3  on:
 4    schedule:
 5      - cron: '17 3 * * *'  # daily at 03:17 UTC
 6    workflow_dispatch:
 7      inputs:
 8        haystack_version:
 9          description: 'Haystack version to test against (e.g., 2.16.1, main)'
10          required: false
11          default: 'main'
12          type: string
13  
14  env:
15    HATCH_VERSION: "1.16.5"
16    PYTHON_VERSION: "3.11"
17  
18  jobs:
19    test-docs-snippets:
20      runs-on: ubuntu-latest
21      timeout-minutes: 30
22      env:
23        AZURE_OPENAI_ENDPOINT: ${{ secrets.AZURE_OPENAI_ENDPOINT }}
24        AZURE_OPENAI_AD_TOKEN: ${{ secrets.AZURE_OPENAI_AD_TOKEN }}
25        AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }}
26        CORE_AZURE_CS_ENDPOINT: ${{ secrets.CORE_AZURE_CS_ENDPOINT }}
27        HF_API_TOKEN: ${{ secrets.HUGGINGFACE_API_KEY }}
28        OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
29        SERPERDEV_API_KEY: ${{ secrets.SERPERDEV_API_KEY }}
30  
31      steps:
32        - name: Checkout
33          uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
34  
35        - name: Setup Python
36          uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
37          with:
38            python-version: '3.11'
39  
40        - name: Install Hatch
41          run: pip install hatch==${{ env.HATCH_VERSION }}
42  
43        - name: Generate API reference for Docusaurus
44          run: hatch run docs
45  
46        - name: Install base dependencies
47          run: |
48            python -m pip install --upgrade pip
49            pip install requests toml
50  
51        - name: Run snippet tests (verbose)
52          shell: bash
53          run: |
54            hatch -e test env run -- python docs-website/scripts/test_python_snippets.py --verbose tmp_api_reference/
55  
56    notify-slack-on-failure:
57      if: failure() && github.ref_name == 'main'
58      needs:
59        - test-docs-snippets
60      runs-on: ubuntu-slim
61      steps:
62        - uses: deepset-ai/notify-slack-action@3cda73b77a148f16f703274198e7771340cf862b # v1
63          with:
64            slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL_NOTIFICATIONS }}