Agno Tool Integrations notebook fix (#1167) #138
This file contains hidden or 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: Add Notebook Examples to Docs | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - 'examples/**' | |
| - 'docs/v2/examples/**' | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| add-notebook-examples-to-docs: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.x' | |
| - name: Install dependencies | |
| run: pip install jupyter nbconvert | |
| - name: Detect and process notebooks | |
| id: process | |
| run: | | |
| # Determine comparison range | |
| case "${{ github.event_name }}" in | |
| "push") | |
| BASE_SHA="${{ github.event.before }}" | |
| [[ "$BASE_SHA" == "0000000000000000000000000000000000000000" ]] && BASE_SHA="$(git hash-object -t tree /dev/null)" | |
| HEAD_SHA="${{ github.event.after }}" | |
| ;; | |
| "pull_request") | |
| BASE_SHA="${{ github.event.pull_request.base.sha }}" | |
| HEAD_SHA="${{ github.event.pull_request.head.sha }}" | |
| ;; | |
| "workflow_dispatch") | |
| git fetch origin "${{ github.event.repository.default_branch }}" --depth=50 | |
| BASE_SHA="origin/${{ github.event.repository.default_branch }}" | |
| HEAD_SHA="HEAD" | |
| ;; | |
| *) | |
| exit 1 | |
| ;; | |
| esac | |
| # Get changed files and filter in one pass | |
| CHANGED_FILES=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA") | |
| # Use arrays for better performance | |
| declare -A notebooks_set | |
| # Process notebooks directly from changed files | |
| while IFS= read -r file; do | |
| if [[ "$file" =~ ^examples/.*\.ipynb$ ]]; then | |
| notebooks_set["$file"]=1 | |
| elif [[ "$file" =~ ^docs/v2/examples/.*\.mdx$ ]] && [[ -f "$file" ]]; then | |
| # Extract source notebook from MDX file | |
| source_notebook=$(grep -oP '(?<=SOURCE_FILE: )[^ ]+' "$file" 2>/dev/null || true) | |
| if [[ -n "$source_notebook" && -f "$source_notebook" ]]; then | |
| notebooks_set["$source_notebook"]=1 | |
| fi | |
| fi | |
| done <<< "$CHANGED_FILES" | |
| # Exit if no notebooks found | |
| [[ ${#notebooks_set[@]} -eq 0 ]] && exit 0 | |
| # Process each notebook and track results | |
| failed_count=0 | |
| processed_notebooks="" | |
| for notebook in "${!notebooks_set[@]}"; do | |
| if python examples/generate_documentation.py "$notebook"; then | |
| processed_notebooks="$processed_notebooks$notebook"$'\n' | |
| else | |
| ((failed_count++)) | |
| fi | |
| done | |
| [[ $failed_count -gt 0 ]] && exit 1 | |
| # Get modified files for PR description | |
| modified_files=$(git status --porcelain | grep -E '^\s*[AM]' | awk '{print $2}' | sort) | |
| # Save outputs for PR | |
| echo "processed_notebooks<<EOF" >> $GITHUB_OUTPUT | |
| echo "$processed_notebooks" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| echo "modified_files<<EOF" >> $GITHUB_OUTPUT | |
| echo "$modified_files" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: Create Pull Request | |
| uses: peter-evans/create-pull-request@v7 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| committer: github-actions[bot] <github-actions[bot]@users.noreply.github.com> | |
| author: github-actions[bot] <github-actions[bot]@users.noreply.github.com> | |
| commit-message: "docs: update examples from notebooks" | |
| title: "docs: update examples from notebooks" | |
| body: | | |
| Updates documentation examples from their source notebooks. | |
| **Triggered by:** @${{ github.actor }} | |
| **Event:** ${{ github.event_name }} | |
| ${{ steps.process.outputs.processed_notebooks && format(' | |
| ## Processed Notebooks | |
| ``` | |
| {0} | |
| ```', steps.process.outputs.processed_notebooks) || '' }} | |
| ${{ steps.process.outputs.modified_files && format(' | |
| ## Modified Files | |
| ``` | |
| {0} | |
| ```', steps.process.outputs.modified_files) || '' }} | |
| branch: update-examples-docs | |
| delete-branch: true | |
| assignees: the-praxs,bboynton97,areibman | |
| reviewers: the-praxs,bboynton97,areibman |