| 1 | if [ "$READTHEDOCS_VERSION_TYPE" != "external" ]; then |
| 2 | echo "Not a PR build (version type=$READTHEDOCS_VERSION_TYPE); skipping pre-run-check gate." |
| 3 | exit 0 |
| 4 | fi |
| 5 | |
| 6 | # Use a GitHub token if provided to raise the API rate limit (60 -> 5000 |
| 7 | # requests/hour). Set GITHUB_TOKEN in the Read the Docs environment variables. |
| 8 | CURL_AUTH=() |
| 9 | if [ -n "$GITHUB_TOKEN" ]; then |
| 10 | CURL_AUTH=(-H "Authorization: Bearer $GITHUB_TOKEN") |
| 11 | fi |
| 12 | |
| 13 | # The 'build-docs' label forces a docs build, bypassing the checks below. |
| 14 | echo "Checking for the 'build-docs' label on PR #${READTHEDOCS_VERSION_NAME}..." |
| 15 | LABELS=$(curl -sS "${CURL_AUTH[@]}" "https://api.github.com/repos/vllm-project/vllm/issues/${READTHEDOCS_VERSION_NAME}/labels" | python3 -c "import sys, json; print('\n'.join(l.get('name', '') for l in json.load(sys.stdin)))") |
| 16 | if printf '%s\n' "$LABELS" | grep -qx "build-docs"; then |
| 17 | echo "PR has the 'build-docs' label; forcing build." |
| 18 | exit 0 |
| 19 | fi |
| 20 | |
| 21 | echo "Checking for changes to docs-affecting files vs origin/main..." |
| 22 | DOCS_PATHS=( |
| 23 | docs/ # Actual docs content |
| 24 | examples/ # Examples are rendered in docs |
| 25 | # vllm/ # API & CLI reference (too broad, use 'build-docs' label) |
| 26 | requirements/test/cuda.txt # CLI reference (see docs/mkdocs/gen_files/generate_argparse.py) |
| 27 | mkdocs.yaml # Affects build process |
| 28 | .readthedocs.yaml # Affects build process |
| 29 | requirements/docs.txt # Affects build process |
| 30 | requirements/docs.in # Affects build process |
| 31 | ) |
| 32 | if git diff --quiet origin/main -- "${DOCS_PATHS[@]}"; then |
| 33 | echo "No docs-affecting files changed vs origin/main; cancelling build." |
| 34 | # See https://docs.readthedocs.com/platform/latest/guides/build/skip-build.html for info on exit code |
| 35 | exit 183 |
| 36 | fi |
| 37 | echo "Docs-affecting files changed; continuing pre-run-check." |
| 38 | echo "Checking pre-commit/pre-run-check status..." |
| 39 | MAX_WAIT=300 |
| 40 | INTERVAL=60 |
| 41 | ELAPSED=0 |
| 42 | while :; do |
| 43 | RAW=$(curl -sS "${CURL_AUTH[@]}" -w "\n%{http_code}" "https://api.github.com/repos/vllm-project/vllm/commits/${READTHEDOCS_GIT_COMMIT_HASH}/check-runs?check_name=pre-run-check&filter=latest") |
| 44 | HTTP_CODE=$(printf %s "$RAW" | tail -n1) |
| 45 | BODY=$(printf %s "$RAW" | sed '$d') |
| 46 | if [ "$HTTP_CODE" != "200" ]; then |
| 47 | echo "GitHub API returned HTTP $HTTP_CODE (likely rate-limited); skipping pre-commit/pre-run-check gate." |
| 48 | break |
| 49 | fi |
| 50 | STATUS=$(printf %s "$BODY" | python3 -c "import sys, json; r=json.load(sys.stdin).get(\"check_runs\",[]); print((r[0].get(\"status\") or \"\") if r else \"none\")") |
| 51 | CONCLUSION=$(printf %s "$BODY" | python3 -c "import sys, json; r=json.load(sys.stdin).get(\"check_runs\",[]); print((r[0].get(\"conclusion\") or \"\") if r else \"\")") |
| 52 | CHECK_URL=$(printf %s "$BODY" | python3 -c "import sys, json; r=json.load(sys.stdin).get(\"check_runs\",[]); print((r[0].get(\"html_url\") or \"\") if r else \"\")") |
| 53 | if [ "$STATUS" = "none" ]; then |
| 54 | echo "no pre-commit/pre-run-check found for this commit; skipping gate." |
| 55 | break |
| 56 | fi |
| 57 | if [ -n "$CONCLUSION" ]; then |
| 58 | echo "pre-commit/pre-run-check conclusion: $CONCLUSION" |
| 59 | if [ "$CONCLUSION" = "failure" ] || [ "$CONCLUSION" = "cancelled" ] || [ "$CONCLUSION" = "timed_out" ]; then |
| 60 | echo "pre-commit/pre-run-check did not pass; skipping docs build." |
| 61 | if [ -n "$CHECK_URL" ]; then |
| 62 | echo "pre-commit/pre-run-check failure reason: $CHECK_URL" |
| 63 | fi |
| 64 | exit 1 |
| 65 | fi |
| 66 | break |
| 67 | fi |
| 68 | if [ "$ELAPSED" -ge "$MAX_WAIT" ]; then |
| 69 | echo "pre-commit/pre-run-check status=$STATUS after ${MAX_WAIT}s; skipping gate." |
| 70 | break |
| 71 | fi |
| 72 | echo "pre-commit/pre-run-check status=$STATUS; waiting ${INTERVAL}s..." |
| 73 | sleep "$INTERVAL" |
| 74 | ELAPSED=$((ELAPSED + INTERVAL)) |
| 75 | done |