Skip to content

Commit 5dd1671

Browse files
committed
add docs CI
ghstack-source-id: 71d2693b7a632c573e8d92cac0b2de70426589f5 Pull Request resolved: #232
1 parent 932450a commit 5dd1671

File tree

4 files changed

+178
-0
lines changed

4 files changed

+178
-0
lines changed

Diff for: .github/workflows/doc-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 ./docs/doc_push.sh --dry-run
64+
- name: Push
65+
run: |
66+
set -ex
67+
cd /tmp/multipy_docs_tmp/multipy_gh_pages
68+
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
69+
git push

Diff for: docs/Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ help:
1414

1515
.PHONY: help Makefile
1616

17+
clean:
18+
@echo "Deleting build directory"
19+
rm -rf "$(BUILDDIR)"
20+
rm -rf _doxygen/ api/
21+
1722
# Catch-all target: route all unknown targets to Sphinx using the new
1823
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
1924
%: Makefile

Diff for: 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+
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

Diff for: docs/requirements.txt

+3
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ sphinxcontrib.katex
55
matplotlib
66
papermill
77
jinja2<=3.0.3
8+
breathe
89
exhale
10+
ipython_genutils
11+
ipykernel

0 commit comments

Comments
 (0)