Skip to content

Commit 8003101

Browse files
committed
add docs CI
ghstack-source-id: 8f2df50bd58b93818ea75ced4a6bf9b5c4f26fcb Pull Request resolved: #232 mend
1 parent c149784 commit 8003101

File tree

5 files changed

+243
-2
lines changed

5 files changed

+243
-2
lines changed

Diff for: .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+
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
69+
git push

Diff for: .github/workflows/docs.yaml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# This workflow builds the multipy docs and deploys them to gh-pages.
2+
# It is very heavily inspired by torchrec's script to deploy to gh-pages.
3+
name: Generate documentation
4+
on:
5+
push:
6+
branches:
7+
- main
8+
# pull_request:
9+
jobs:
10+
build_docs_job:
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
matrix:
14+
include:
15+
- os: linux.2xlarge
16+
python-version: 3.8
17+
steps:
18+
- name: Check ldd --version
19+
run: ldd --version
20+
- name: Checkout
21+
uses: actions/checkout@v2
22+
- name: Setup SSH (Click me for login details)
23+
uses: ./.github/actions/setup-ssh
24+
with:
25+
github-secret: ${{ secrets.GITHUB_TOKEN }}
26+
# Update references
27+
- name: Update pip
28+
run: |
29+
sudo yum update -y
30+
sudo yum -y install git python3-pip doxygen
31+
sudo pip3 install --upgrade pip
32+
- name: Setup conda
33+
run: |
34+
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh
35+
bash ~/miniconda.sh -b -p $HOME/miniconda
36+
- name: setup Path
37+
run: |
38+
echo "/home/ec2-user/miniconda/bin" >> $GITHUB_PATH
39+
echo "CONDA=/home/ec2-user/miniconda" >> $GITHUB_PATH
40+
- name: create conda env
41+
run: |
42+
conda create --name build_binary python=${{ matrix.python-version }}
43+
conda info
44+
- name: check python version no Conda
45+
run: |
46+
python --version
47+
- name: check python version
48+
run: |
49+
conda run -n build_binary python --version
50+
- name: Build the docset
51+
run: |
52+
conda run -n build_binary python -m pip install -r docs/requirements.txt
53+
cd docs
54+
conda run -n build_binary make html
55+
cd ..
56+
- name: Get output time
57+
run: echo "The time was ${{ steps.build.outputs.time }}"
58+
- name: Deploy
59+
uses: JamesIves/github-pages-deploy-action@releases/v3
60+
with:
61+
ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62+
BRANCH: gh-pages # The branch the action should deploy to.
63+
FOLDER: docs/build/html # The folder the action should deploy.

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

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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+
multipy_ver="0.1.0dev0"
61+
62+
echo "Building multipy-$multipy_ver docs..."
63+
docs_dir=$repo_root/docs
64+
build_dir=$docs_dir/build
65+
cd "$docs_dir" || exit
66+
python3 -m pip install setuptools
67+
python3 -m pip install -r requirements.txt
68+
make clean html
69+
echo "Doc build complete"
70+
71+
tmp_dir=/tmp/multipy_docs_tmp
72+
rm -rf "${tmp_dir:?}"
73+
74+
echo "Checking out gh-pages branch..."
75+
gh_pages_dir="$tmp_dir/multipy_gh_pages"
76+
git clone -b gh-pages --single-branch "$repo_origin" $gh_pages_dir
77+
78+
echo "Copying doc pages for $multipy_ver into $gh_pages_dir..."
79+
rm -rf "${gh_pages_dir:?}/${multipy_ver:?}"
80+
cp -R "$build_dir/$multipy_ver/html" "$gh_pages_dir/$multipy_ver"
81+
82+
cd $gh_pages_dir || exit
83+
84+
for redirect in "${redirects[@]}"; do
85+
echo "Creating redirect symlinks for: $redirect -> $multipy_ver..."
86+
rm -rf "${gh_pages_dir:?}/${redirect:?}"
87+
ln -s "$multipy_ver" "$redirect"
88+
done
89+
90+
"$docs_dir"/versions_html.py
91+
92+
git add .
93+
git commit --quiet -m "[doc_push][$release_tag] built from $commit_id ($branch). Redirects: ${redirects[*]} -> $multipy_ver."
94+
95+
if [ $dry_run -eq 1 ]; then
96+
echo "*** --dry-run mode, skipping push to gh-pages branch. To publish run: cd ${gh_pages_dir} && git push"
97+
exit
98+
fi
99+
100+
git push

Diff for: docs/requirements.txt

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
sphinx==5.0.1
2-
-e git+http://github.com/pytorch/pytorch_sphinx_theme.git#egg=pytorch_sphinx_theme
1+
sphinx
2+
# PyTorch Theme
3+
-e git+https://github.com/pytorch/pytorch_sphinx_theme.git#egg=pytorch_sphinx_theme
34
sphinx-gallery<=0.7.0
45
sphinxcontrib.katex
56
matplotlib
67
papermill
78
jinja2<=3.0.3
9+
breathe
810
exhale
11+
ipython_genutils
12+
ipykernel

0 commit comments

Comments
 (0)