|
| 1 | +#!/bin/bash |
| 2 | +# Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | +# All rights reserved. |
| 4 | +# |
| 5 | +# This source code is licensed under the BSD-style license found in the |
| 6 | +# LICENSE file in the root directory of this source tree. |
| 7 | + |
| 8 | +# |
| 9 | +# Builds docs from the checkedout HEAD |
| 10 | +# and pushes the artifacts to gh-pages branch in github.com/pytorch/multipy |
| 11 | +# |
| 12 | +# 1. sphinx generated docs are copied to <repo-root>/<version> |
| 13 | +# 2. if a release tag is found on HEAD then redirects are copied to <repo-root>/latest |
| 14 | +# 3. if no release tag is found on HEAD then redirects are copied to <repo-root>/main |
| 15 | +# |
| 16 | +# gh-pages branch should look as follows: |
| 17 | +# <repo-root> |
| 18 | +# |- 0.1.0rc2 |
| 19 | +# |- 0.1.0rc3 |
| 20 | +# |- <versions...> |
| 21 | +# |- main (redirects to the most recent ver in trunk, including release) |
| 22 | +# |- latest (redirects to the most recent release) |
| 23 | +# If the most recent release is 0.1.0 and main is at 0.1.1rc1 then, |
| 24 | +# https://pytorch.org/multipy/main -> https://pytorch.org/multipy/0.1.1rc1 |
| 25 | +# https://pytorch.org/multipy/latest -> https://pytorch.org/multipy/0.1.0 |
| 26 | +# |
| 27 | +# Redirects are done via Jekyll redirect-from plugin. See: |
| 28 | +# sources/scripts/create_redirect_md.py |
| 29 | +# Makefile (redirect target) |
| 30 | +# (on gh-pages branch) _layouts/docs_redirect.html |
| 31 | + |
| 32 | +set -ex |
| 33 | + |
| 34 | +dry_run=0 |
| 35 | +for arg in "$@"; do |
| 36 | + shift |
| 37 | + case "$arg" in |
| 38 | + "--dry-run") dry_run=1 ;; |
| 39 | + "--help") echo "Usage $0 [--dry-run]"; exit 0 ;; |
| 40 | + esac |
| 41 | +done |
| 42 | + |
| 43 | +repo_origin="$(git remote get-url origin)" |
| 44 | +repo_root=$(git rev-parse --show-toplevel) |
| 45 | +branch=$(git rev-parse --abbrev-ref HEAD) |
| 46 | +commit_id=$(git rev-parse --short HEAD) |
| 47 | + |
| 48 | +if ! release_tag=$(git describe --tags --exact-match HEAD 2>/dev/null); then |
| 49 | + echo "No release tag found, building docs for main..." |
| 50 | + redirects=(main) |
| 51 | + release_tag="main" |
| 52 | +else |
| 53 | + echo "Release tag $release_tag found, building docs for release..." |
| 54 | + redirects=(latest main) |
| 55 | +fi |
| 56 | + |
| 57 | +echo "Installing multipy from $repo_root..." |
| 58 | +cd "$repo_root" || exit |
| 59 | +pip install -r dev-requirements.txt |
| 60 | +pip install -e . --install-option="--cmakeoff" |
| 61 | + |
| 62 | +multipy_ver=$(python -c "import multipy; print(multipy.__version__)") |
| 63 | + |
| 64 | +echo "Building multipy-$multipy_ver docs..." |
| 65 | +docs_dir=$repo_root/docs |
| 66 | +build_dir=$docs_dir/build |
| 67 | +cd "$docs_dir" || exit |
| 68 | +pip install -r requirements.txt |
| 69 | +make clean html |
| 70 | +echo "Doc build complete" |
| 71 | + |
| 72 | +tmp_dir=/tmp/multipy_docs_tmp |
| 73 | +rm -rf "${tmp_dir:?}" |
| 74 | + |
| 75 | +echo "Checking out gh-pages branch..." |
| 76 | +gh_pages_dir="$tmp_dir/multipy_gh_pages" |
| 77 | +git clone -b gh-pages --single-branch "$repo_origin" $gh_pages_dir |
| 78 | + |
| 79 | +echo "Copying doc pages for $multipy_ver into $gh_pages_dir..." |
| 80 | +rm -rf "${gh_pages_dir:?}/${multipy_ver:?}" |
| 81 | +cp -R "$build_dir/$multipy_ver/html" "$gh_pages_dir/$multipy_ver" |
| 82 | + |
| 83 | +cd $gh_pages_dir || exit |
| 84 | + |
| 85 | +for redirect in "${redirects[@]}"; do |
| 86 | + echo "Creating redirect symlinks for: $redirect -> $multipy_ver..." |
| 87 | + rm -rf "${gh_pages_dir:?}/${redirect:?}" |
| 88 | + ln -s "$multipy_ver" "$redirect" |
| 89 | +done |
| 90 | + |
| 91 | +"$docs_dir"/versions_html.py |
| 92 | + |
| 93 | +git add . |
| 94 | +git commit --quiet -m "[doc_push][$release_tag] built from $commit_id ($branch). Redirects: ${redirects[*]} -> $multipy_ver." |
| 95 | + |
| 96 | +if [ $dry_run -eq 1 ]; then |
| 97 | + echo "*** --dry-run mode, skipping push to gh-pages branch. To publish run: cd ${gh_pages_dir} && git push" |
| 98 | + exit |
| 99 | +fi |
| 100 | + |
| 101 | +git push |
0 commit comments