ENH: update models JSON [llm] #1381
Workflow file for this run
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: Auto run gen_docs.py and commit changes to PR | |
| on: | |
| pull_request_target: | |
| types: [opened, synchronize, ready_for_review] | |
| paths: | |
| - 'xinference/model/llm/llm_family.json' | |
| - 'xinference/model/embedding/model_spec.json' | |
| - 'xinference/model/rerank/model_spec.json' | |
| - 'xinference/model/image/model_spec.json' | |
| - 'xinference/model/audio/model_spec.json' | |
| - 'xinference/model/video/model_spec.json' | |
| permissions: | |
| contents: write | |
| pull-requests: read | |
| jobs: | |
| run-gen-docs-and-commit: | |
| if: github.event.pull_request.draft == false && startsWith(github.event.pull_request.head.ref, 'chore/models-sync/') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Validate PR metadata | |
| env: | |
| HEAD_REF: ${{ github.event.pull_request.head.ref }} | |
| HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }} | |
| run: | | |
| set -euo pipefail | |
| if ! printf '%s' "$HEAD_REF" | grep -Eq '^chore/models-sync/[A-Za-z0-9._/-]+$'; then | |
| echo "Unsafe branch name: $HEAD_REF" | |
| exit 1 | |
| fi | |
| if ! printf '%s' "$HEAD_REPO" | grep -Eq '^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$'; then | |
| echo "Unsafe repository name: $HEAD_REPO" | |
| exit 1 | |
| fi | |
| - name: Checkout base branch (trusted code) | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.pull_request.base.sha }} | |
| repository: ${{ github.repository }} | |
| path: base | |
| fetch-depth: 0 | |
| - name: Checkout PR head (data only) | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.pull_request.head.sha }} | |
| repository: ${{ github.event.pull_request.head.repo.full_name }} | |
| path: pr | |
| fetch-depth: 0 | |
| - name: Decide whether to run gen_docs for latest commit | |
| id: decide | |
| working-directory: pr | |
| run: | | |
| set -e | |
| MSG="$(git log -1 --pretty=%B || echo "")" | |
| echo "Latest commit message: $MSG" | |
| if echo "$MSG" | grep -Eiq '\[(skip ci|ci skip)\]'; then | |
| echo "Skip token found in commit message; will not run." | |
| echo "run=false" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| echo "run=true" >> $GITHUB_OUTPUT | |
| - name: Validate changed files | |
| if: steps.decide.outputs.run == 'true' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| PR_FILES_URL: ${{ github.event.pull_request.url }}/files | |
| run: | | |
| set -euo pipefail | |
| python base/.github/scripts/validate_gen_docs_pr.py changed-files | |
| - name: Set up Python | |
| if: steps.decide.outputs.run == 'true' | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.10' | |
| - name: Install gen_docs dependencies | |
| if: steps.decide.outputs.run == 'true' | |
| run: | | |
| python -m pip install --upgrade pip | |
| python -m pip install jinja2 | |
| python -m pip install "./base[doc]" | |
| - name: Prepare sanitized gen_docs workspace | |
| if: steps.decide.outputs.run == 'true' | |
| run: | | |
| set -euo pipefail | |
| rm -rf gen-docs-work | |
| cp -a base gen-docs-work | |
| for file in \ | |
| xinference/model/llm/llm_family.json \ | |
| xinference/model/embedding/model_spec.json \ | |
| xinference/model/rerank/model_spec.json \ | |
| xinference/model/image/model_spec.json \ | |
| xinference/model/audio/model_spec.json \ | |
| xinference/model/video/model_spec.json | |
| do | |
| if [ -e "pr/$file" ]; then | |
| if [ -L "pr/$file" ]; then | |
| echo "Refusing symlinked PR data file: $file" | |
| exit 1 | |
| fi | |
| cp "pr/$file" "gen-docs-work/$file" | |
| fi | |
| done | |
| - name: Validate model names | |
| if: steps.decide.outputs.run == 'true' | |
| run: | | |
| set -euo pipefail | |
| python base/.github/scripts/validate_gen_docs_pr.py model-names gen-docs-work | |
| - name: Run gen_docs.py from sanitized workspace | |
| if: steps.decide.outputs.run == 'true' | |
| working-directory: gen-docs-work/doc/source | |
| run: | | |
| set -euo pipefail | |
| python gen_docs.py | |
| - name: Copy generated docs back to PR checkout | |
| if: steps.decide.outputs.run == 'true' | |
| run: | | |
| set -euo pipefail | |
| for path in \ | |
| doc/source/models/builtin \ | |
| doc/source/getting_started/installation.rst \ | |
| doc/source/user_guide/backends.rst \ | |
| doc/source/user_guide/metrics.rst | |
| do | |
| if [ -e "gen-docs-work/$path" ]; then | |
| mkdir -p "pr/$(dirname "$path")" | |
| rm -rf "pr/$path" | |
| cp -a "gen-docs-work/$path" "pr/$path" | |
| fi | |
| done | |
| - name: Stage and validate generated changes | |
| if: steps.decide.outputs.run == 'true' | |
| working-directory: pr | |
| run: | | |
| set -euo pipefail | |
| echo "[Debug] Before staging:" && git status --porcelain | |
| echo "[Debug] check-ignore for generated file:" | |
| git check-ignore -v doc/source/_generated/auto_generated.txt || echo "Not ignored" | |
| git add -A -- \ | |
| doc/source/models/builtin \ | |
| doc/source/getting_started/installation.rst \ | |
| doc/source/user_guide/backends.rst \ | |
| doc/source/user_guide/metrics.rst | |
| echo "[Debug] After staging:" && git status --porcelain | |
| echo "[Debug] Staged diff:" && git diff --cached --name-status || true | |
| unexpected="$(git diff --cached --name-only | grep -Ev '^(doc/source/models/builtin/|doc/source/getting_started/installation\.rst$|doc/source/user_guide/backends\.rst$|doc/source/user_guide/metrics\.rst$)' || true)" | |
| if [ -n "$unexpected" ]; then | |
| echo "Unexpected generated changes:" | |
| printf '%s\n' "$unexpected" | |
| exit 1 | |
| fi | |
| unsafe_generated_names="$(git diff --cached --name-only -- doc/source/models/builtin | grep -Ev '^doc/source/models/builtin/(llm|embedding|rerank|image|audio|video)/([A-Za-z0-9._-]+|index)\.rst$' || true)" | |
| if [ -n "$unsafe_generated_names" ]; then | |
| echo "Unsafe generated documentation paths:" | |
| printf '%s\n' "$unsafe_generated_names" | |
| exit 1 | |
| fi | |
| if ! git diff --cached --quiet; then | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git commit -m "chore(docs): auto-run gen_docs.py [skip ci]" | |
| else | |
| echo "No changes to commit." | |
| fi | |
| - name: Push to same-repo PR | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| HEAD_REF: ${{ github.event.pull_request.head.ref }} | |
| if: steps.decide.outputs.run == 'true' && github.event.pull_request.head.repo.full_name == github.repository | |
| working-directory: pr | |
| run: | | |
| if ! printf '%s' "$HEAD_REF" | grep -Eq '^chore/models-sync/[A-Za-z0-9._/-]+$'; then | |
| echo "Unsafe branch name: $HEAD_REF" | |
| exit 1 | |
| fi | |
| echo "Pushing changes to same-repo PR..." | |
| git push origin "HEAD:${HEAD_REF}" || echo "No changes to push." | |
| - name: Skip fork PR push | |
| env: | |
| HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }} | |
| if: steps.decide.outputs.run == 'true' && github.event.pull_request.head.repo.full_name != github.repository | |
| run: | | |
| echo "Skipping automatic docs push to fork PR: $HEAD_REPO" | |
| echo "Please ask a maintainer to run gen_docs.py manually or open a same-repository chore/models-sync branch." |