|
| 1 | +# Build the API reference documentation for v0.3 branch. |
| 2 | +# |
| 3 | +# Manual trigger only. |
| 4 | +# |
| 5 | +# Built HTML pushed to langchain-ai/langchain-api-docs-html. |
| 6 | +# |
| 7 | +# Looks for langchain-ai org repos in packages.yml and checks them out. |
| 8 | +# Calls prep_api_docs_build.py. |
| 9 | + |
| 10 | +name: "📚 API Docs (v0.3)" |
| 11 | +run-name: "Build & Deploy API Reference (v0.3)" |
| 12 | + |
| 13 | +on: |
| 14 | + workflow_dispatch: |
| 15 | + |
| 16 | +env: |
| 17 | + PYTHON_VERSION: "3.11" |
| 18 | + |
| 19 | +jobs: |
| 20 | + build: |
| 21 | + if: github.repository == 'langchain-ai/langchain' || github.event_name != 'schedule' |
| 22 | + runs-on: ubuntu-latest |
| 23 | + permissions: |
| 24 | + contents: read |
| 25 | + steps: |
| 26 | + - uses: actions/checkout@v5 |
| 27 | + with: |
| 28 | + ref: v0.3 |
| 29 | + path: langchain |
| 30 | + |
| 31 | + - uses: actions/checkout@v5 |
| 32 | + with: |
| 33 | + repository: langchain-ai/langchain-api-docs-html |
| 34 | + path: langchain-api-docs-html |
| 35 | + token: ${{ secrets.TOKEN_GITHUB_API_DOCS_HTML }} |
| 36 | + |
| 37 | + - name: "📋 Extract Repository List with yq" |
| 38 | + id: get-unsorted-repos |
| 39 | + uses: mikefarah/yq@master |
| 40 | + with: |
| 41 | + cmd: | |
| 42 | + # Extract repos from packages.yml that are in the langchain-ai org |
| 43 | + # (excluding 'langchain' itself) |
| 44 | + yq ' |
| 45 | + .packages[] |
| 46 | + | select( |
| 47 | + ( |
| 48 | + (.repo | test("^langchain-ai/")) |
| 49 | + and |
| 50 | + (.repo != "langchain-ai/langchain") |
| 51 | + ) |
| 52 | + or |
| 53 | + (.include_in_api_ref // false) |
| 54 | + ) |
| 55 | + | .repo |
| 56 | + ' langchain/libs/packages.yml |
| 57 | +
|
| 58 | + - name: "📋 Parse YAML & Checkout Repositories" |
| 59 | + env: |
| 60 | + REPOS_UNSORTED: ${{ steps.get-unsorted-repos.outputs.result }} |
| 61 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 62 | + run: | |
| 63 | + # Get unique repositories |
| 64 | + REPOS=$(echo "$REPOS_UNSORTED" | sort -u) |
| 65 | + # Checkout each unique repository |
| 66 | + for repo in $REPOS; do |
| 67 | + # Validate repository format (allow any org with proper format) |
| 68 | + if [[ ! "$repo" =~ ^[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+$ ]]; then |
| 69 | + echo "Error: Invalid repository format: $repo" |
| 70 | + exit 1 |
| 71 | + fi |
| 72 | +
|
| 73 | + REPO_NAME=$(echo $repo | cut -d'/' -f2) |
| 74 | +
|
| 75 | + # Additional validation for repo name |
| 76 | + if [[ ! "$REPO_NAME" =~ ^[a-zA-Z0-9_.-]+$ ]]; then |
| 77 | + echo "Error: Invalid repository name: $REPO_NAME" |
| 78 | + exit 1 |
| 79 | + fi |
| 80 | + echo "Checking out $repo to $REPO_NAME" |
| 81 | + git clone --depth 1 https://github.com/$repo.git $REPO_NAME |
| 82 | + done |
| 83 | +
|
| 84 | + - name: "🐍 Setup Python ${{ env.PYTHON_VERSION }}" |
| 85 | + uses: actions/setup-python@v6 |
| 86 | + id: setup-python |
| 87 | + with: |
| 88 | + python-version: ${{ env.PYTHON_VERSION }} |
| 89 | + |
| 90 | + - name: "📦 Install Initial Python Dependencies using uv" |
| 91 | + working-directory: langchain |
| 92 | + run: | |
| 93 | + python -m pip install -U uv |
| 94 | + python -m uv pip install --upgrade --no-cache-dir pip setuptools pyyaml |
| 95 | +
|
| 96 | + - name: "📦 Organize Library Directories" |
| 97 | + # Places cloned partner packages into libs/partners structure |
| 98 | + run: python langchain/.github/scripts/prep_api_docs_build.py |
| 99 | + |
| 100 | + - name: "🧹 Clear Prior Build" |
| 101 | + run: |
| 102 | + # Remove artifacts from prior docs build |
| 103 | + rm -rf langchain-api-docs-html/api_reference_build/html |
| 104 | + |
| 105 | + - name: "📦 Install Documentation Dependencies using uv" |
| 106 | + working-directory: langchain |
| 107 | + run: | |
| 108 | + # Install all partner packages in editable mode with overrides |
| 109 | + python -m uv pip install $(ls ./libs/partners | xargs -I {} echo "./libs/partners/{}") --overrides ./docs/vercel_overrides.txt |
| 110 | +
|
| 111 | + # Install core langchain and other main packages |
| 112 | + python -m uv pip install libs/core libs/langchain libs/text-splitters libs/community libs/experimental libs/standard-tests |
| 113 | +
|
| 114 | + # Install Sphinx and related packages for building docs |
| 115 | + python -m uv pip install -r docs/api_reference/requirements.txt |
| 116 | +
|
| 117 | + - name: "🔧 Configure Git Settings" |
| 118 | + working-directory: langchain |
| 119 | + run: | |
| 120 | + git config --local user.email "[email protected]" |
| 121 | + git config --local user.name "Github Actions" |
| 122 | +
|
| 123 | + - name: "📚 Build API Documentation" |
| 124 | + working-directory: langchain |
| 125 | + run: | |
| 126 | + # Generate the API reference RST files |
| 127 | + python docs/api_reference/create_api_rst.py |
| 128 | +
|
| 129 | + # Build the HTML documentation using Sphinx |
| 130 | + # -T: show full traceback on exception |
| 131 | + # -E: don't use cached environment (force rebuild, ignore cached doctrees) |
| 132 | + # -b html: build HTML docs (vs PDS, etc.) |
| 133 | + # -d: path for the cached environment (parsed document trees / doctrees) |
| 134 | + # - Separate from output dir for faster incremental builds |
| 135 | + # -c: path to conf.py |
| 136 | + # -j auto: parallel build using all available CPU cores |
| 137 | + python -m sphinx -T -E -b html -d ../langchain-api-docs-html/_build/doctrees -c docs/api_reference docs/api_reference ../langchain-api-docs-html/api_reference_build/html -j auto |
| 138 | +
|
| 139 | + # Post-process the generated HTML |
| 140 | + python docs/api_reference/scripts/custom_formatter.py ../langchain-api-docs-html/api_reference_build/html |
| 141 | +
|
| 142 | + # Default index page is blank so we copy in the actual home page. |
| 143 | + cp ../langchain-api-docs-html/api_reference_build/html/{reference,index}.html |
| 144 | +
|
| 145 | + # Removes Sphinx's intermediate build artifacts after the build is complete. |
| 146 | + rm -rf ../langchain-api-docs-html/_build/ |
| 147 | +
|
| 148 | + # Commit and push changes to langchain-api-docs-html repo |
| 149 | + - uses: EndBug/add-and-commit@v9 |
| 150 | + with: |
| 151 | + cwd: langchain-api-docs-html |
| 152 | + message: "Update API docs build from v0.3 branch" |
0 commit comments