Skip to content

Commit 6ac5360

Browse files
PaliCfacebook-github-bot
authored andcommitted
add docs CI (#232)
Summary: Pull Request resolved: #232 The CI to update our docs. Currently, the way we do versioning is pretty janky as we hardcode versioning into `docs/doc_push.sh`. Regardless here is the preliminary website [https://pytorch.org/multipy/latest/](https://pytorch.org/multipy/latest/). Before release we should 1. Shrink down the readme so it is no longer redundant and references our docs. 2. Symlink pytorch.org/multipy -> pytorch.org/multipy/latest. 3. Add a more in depth what is this/overview page. 4. Add a path_enviroment tutorial + a more complete end to end one. Test Plan: Imported from OSS Reviewed By: d4l3k Differential Revision: D40745113 Pulled By: PaliC fbshipit-source-id: 2551c563b11c72408872c985e79e7c6ad3101d1e
1 parent 1fd7766 commit 6ac5360

File tree

3 files changed

+174
-1
lines changed

3 files changed

+174
-1
lines changed

.github/workflows/docs-build.yaml

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Docs Build
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
docbuild:
11+
runs-on: ubuntu-18.04
12+
steps:
13+
- name: Setup Python
14+
uses: actions/setup-python@v2
15+
with:
16+
python-version: 3.8
17+
architecture: x64
18+
- name: Checkout MultiPy
19+
uses: actions/checkout@v2
20+
- name: Install Dependencies
21+
run: |
22+
set -eux
23+
sudo apt-get install -y pandoc doxygen
24+
pip install -r docs/requirements.txt
25+
- name: Doc Test
26+
run: |
27+
cd docs
28+
make doctest
29+
- name: Linkcheck
30+
run: |
31+
cd docs
32+
make linkcheck
33+
- name: Doc Build
34+
run: |
35+
cd docs
36+
make html
37+
38+
docpush:
39+
runs-on: ubuntu-18.04
40+
needs: docbuild
41+
if: ${{ github.ref == 'refs/heads/main' }}
42+
steps:
43+
- name: Setup Python
44+
uses: actions/setup-python@v2
45+
with:
46+
python-version: 3.8
47+
architecture: x64
48+
- name: Checkout MultiPy
49+
uses: actions/checkout@v2
50+
- name: Set Identity
51+
run: |
52+
set -ex
53+
git config --global user.email "[email protected]"
54+
git config --global user.name "MultiPy CI Runner"
55+
- name: Install Dependencies
56+
run: |
57+
set -eux
58+
sudo apt-get install -y pandoc doxygen
59+
pip install -r docs/requirements.txt
60+
- name: Build
61+
run: |
62+
set -ex
63+
sudo bash docs/doc_push.sh --dry-run
64+
- name: Push
65+
run: |
66+
set -ex
67+
cd /tmp/multipy_docs_tmp/multipy_gh_pages
68+
sudo git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
69+
git push

docs/doc_push.sh

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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+
60+
# Not sure why this is on python 2, but if we are only
61+
# printing out variables, it should be fine. Let's change
62+
# it if we are doing something more complicated.
63+
multipy_ver=$(python -c "from multipy.version import __version__; print __version__")
64+
65+
echo "Building multipy-$multipy_ver docs..."
66+
docs_dir=$repo_root/docs
67+
build_dir=$docs_dir/build
68+
cd "$docs_dir" || exit
69+
python3 -m pip install setuptools
70+
python3 -m pip install -r requirements.txt
71+
make clean html
72+
echo "Doc build complete"
73+
74+
tmp_dir=/tmp/multipy_docs_tmp
75+
rm -rf "${tmp_dir:?}"
76+
77+
echo "Checking out gh-pages branch..."
78+
gh_pages_dir="$tmp_dir/multipy_gh_pages"
79+
git clone -b gh-pages --single-branch "$repo_origin" $gh_pages_dir
80+
81+
echo "Copying doc pages for $multipy_ver into $gh_pages_dir..."
82+
rm -rf "${gh_pages_dir:?}/${multipy_ver:?}"
83+
cp -R "$build_dir/html" "$gh_pages_dir/$multipy_ver"
84+
85+
cd $gh_pages_dir || exit
86+
87+
for redirect in "${redirects[@]}"; do
88+
echo "Creating redirect symlinks for: $redirect -> $multipy_ver..."
89+
rm -rf "${gh_pages_dir:?}/${redirect:?}"
90+
ln -s "$multipy_ver" "$redirect"
91+
done
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

docs/requirements.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
sphinx==5.0.1
1+
sphinx
22
sphinx-autobuild
33
-e git+http://github.com/pytorch/pytorch_sphinx_theme.git#egg=pytorch_sphinx_theme
44
sphinx-gallery<=0.7.0
55
sphinxcontrib.katex
66
matplotlib
77
papermill
88
jinja2<=3.0.3
9+
breathe
910
exhale
11+
ipython_genutils
12+
ipykernel

0 commit comments

Comments
 (0)