docs.yml 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. name: Docs
  2. on:
  3. pull_request:
  4. push:
  5. branches:
  6. - nightly
  7. - main
  8. - release/*
  9. tags:
  10. - v[0-9]+.[0-9]+.[0-9]
  11. - v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+
  12. workflow_dispatch:
  13. jobs:
  14. build:
  15. uses: pytorch/test-infra/.github/workflows/linux_job.yml@release/2.1
  16. with:
  17. repository: pytorch/vision
  18. upload-artifact: docs
  19. script: |
  20. set -euo pipefail
  21. export PYTHON_VERSION=3.8
  22. export GPU_ARCH_TYPE=cpu
  23. export GPU_ARCH_VERSION=''
  24. ./.github/scripts/setup-env.sh
  25. # Prepare conda
  26. CONDA_PATH=$(which conda)
  27. eval "$(${CONDA_PATH} shell.bash hook)"
  28. conda activate ci
  29. # FIXME: not sure why we need this. `ldd torchvision/video_reader.so` shows that it
  30. # already links against the one pulled from conda. However, at runtime it pulls from
  31. # /lib64
  32. # Should we maybe always do this in `./.github/scripts/setup-env.sh` so that we don't
  33. # have to pay attention in all other workflows?
  34. export LD_LIBRARY_PATH="${CONDA_PREFIX}/lib:${LD_LIBRARY_PATH}"
  35. cd docs
  36. echo '::group::Install doc requirements'
  37. pip install --progress-bar=off -r requirements.txt
  38. echo '::endgroup::'
  39. if [[ ${{ github.event_name }} == push && (${{ github.ref_type }} == tag || (${{ github.ref_type }} == branch && ${{ github.ref_name }} == release/*)) ]]; then
  40. echo '::group::Enable version string sanitization'
  41. # This environment variable just has to exist and must not be empty. The actual value is arbitrary.
  42. # See docs/source/conf.py for details
  43. export TORCHVISION_SANITIZE_VERSION_STR_IN_DOCS=1
  44. echo '::endgroup::'
  45. fi
  46. # The runner does not have sufficient memory to run with as many processes as there are
  47. # cores (`-j auto`). Thus, we limit to a single process (`-j 1`) here.
  48. sed -i -e 's/-j auto/-j 1/' Makefile
  49. make html
  50. # Below is an imperfect way for us to add "try on collab" links to all of our gallery examples.
  51. # sphinx-gallery will convert all gallery examples to .ipynb notebooks and stores them in
  52. # build/html/_downloads/<some_hash>/<example_name>.ipynb
  53. # We copy all those ipynb files in a more convenient folder so that we can more easily link to them.
  54. mkdir build/html/_generated_ipynb_notebooks
  55. for file in `find build/html/_downloads`; do
  56. if [[ $file == *.ipynb ]]; then
  57. cp $file build/html/_generated_ipynb_notebooks/
  58. fi
  59. done
  60. cp -r build/html "${RUNNER_ARTIFACT_DIR}"
  61. # On PRs we also want to upload the docs into our S3 bucket for preview.
  62. if [[ ${{ github.event_name == 'pull_request' }} ]]; then
  63. cp -r build/html/* "${RUNNER_DOCS_DIR}"
  64. fi
  65. upload:
  66. needs: build
  67. if: github.repository == 'pytorch/vision' && github.event_name == 'push' &&
  68. ((github.ref_type == 'branch' && github.ref_name == 'main') || github.ref_type == 'tag')
  69. permissions:
  70. contents: write
  71. uses: pytorch/test-infra/.github/workflows/linux_job.yml@release/2.1
  72. with:
  73. repository: pytorch/vision
  74. download-artifact: docs
  75. ref: gh-pages
  76. script: |
  77. set -euo pipefail
  78. REF_TYPE=${{ github.ref_type }}
  79. REF_NAME=${{ github.ref_name }}
  80. if [[ "${REF_TYPE}" == branch ]]; then
  81. TARGET_FOLDER="${REF_NAME}"
  82. elif [[ "${REF_TYPE}" == tag ]]; then
  83. case "${REF_NAME}" in
  84. *-rc*)
  85. echo "Aborting upload since this is an RC tag: ${REF_NAME}"
  86. exit 0
  87. ;;
  88. *)
  89. # Strip the leading "v" as well as the trailing patch version. For example:
  90. # 'v0.15.2' -> '0.15'
  91. TARGET_FOLDER=$(echo "${REF_NAME}" | sed 's/v\([0-9]\+\)\.\([0-9]\+\)\.[0-9]\+/\1.\2/')
  92. ;;
  93. esac
  94. fi
  95. echo "Target Folder: ${TARGET_FOLDER}"
  96. mkdir -p "${TARGET_FOLDER}"
  97. rm -rf "${TARGET_FOLDER}"/*
  98. mv "${RUNNER_ARTIFACT_DIR}"/html/* "${TARGET_FOLDER}"
  99. git add "${TARGET_FOLDER}" || true
  100. if [[ "${TARGET_FOLDER}" == main ]]; then
  101. mkdir -p _static
  102. rm -rf _static/*
  103. cp -r "${TARGET_FOLDER}"/_static/* _static
  104. git add _static || true
  105. fi
  106. git config user.name 'pytorchbot'
  107. git config user.email 'soumith+bot@pytorch.org'
  108. git config http.postBuffer 524288000
  109. git commit -m "auto-generating sphinx docs" || true
  110. git push