-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuildDocs.sh
executable file
·159 lines (117 loc) · 5.01 KB
/
buildDocs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/bin/bash
set -x
################################################################################
# File: buildDocs.sh
# Purpose: Script that builds our documentation using sphinx and updates GitHub
# Pages. This script is executed by:
# .github/workflows/docs_pages_workflow.yml
#
################################################################################
###################
# INSTALL DEPENDS #
###################
apt-get update
apt-get -y install git git-lfs rsync python3-stemmer python3-git python3-pip \
python3-virtualenv python3-setuptools zlib1g zlib1g-dev libjpeg-dev \
python3-pandas python3-matplotlib python3-seaborn
python3 -m pip install --upgrade docutils==0.16 reportlab==3.6.8
python3 -m pip install --upgrade rinohtype Pygments myst_parser sphinx_tabs \
sphinx_rtd_theme sphinx rst2pdf sphinx-autoapi \
sphinx_gallery
git lfs install
#####################
# DECLARE VARIABLES #
#####################
pwd
ls -lah
export SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct)
# make a new temp dir which will be our GitHub Pages docroot
docroot=`mktemp -d`
export REPO_NAME="${GITHUB_REPOSITORY##*/}"
##############
# BUILD DOCS #
##############
# first, cleanup any old builds' static assets
make -C docs clean
# get a list of branches, excluding 'HEAD' and 'gh-pages'
versions="`git for-each-ref '--format=%(refname:lstrip=-1)' refs/remotes/origin/ | grep -viE '^(HEAD|gh-pages)$'`"
for current_version in ${versions}; do
# make the current language available to conf.py
export current_version
git checkout ${current_version}
echo "INFO: Building sites for ${current_version}"
# skip this branch if it doesn't have our docs dir & sphinx config
if [ ! -e 'docs/conf.py' ]; then
echo -e "\tINFO: Couldn't find 'docs/conf.py' (skipped)"
continue
fi
languages="en `find docs/locales/ -mindepth 1 -maxdepth 1 -type d -exec basename '{}' \;`"
for current_language in ${languages}; do
# make the current language available to conf.py
export current_language
##########
# BUILDS #
##########
echo "INFO: Building for ${current_language}"
# HTML #
sphinx-build -b html docs/ docs/_build/html/${current_language}/${current_version} -D language="${current_language}"
# PDF #
sphinx-build -b rinoh docs/ docs/_build/rinoh -D language="${current_language}"
mkdir -p "${docroot}/${current_language}/${current_version}"
cp "docs/_build/rinoh/target.pdf" "${docroot}/${current_language}/${current_version}/helloWorld-docs_${current_language}_${current_version}.pdf"
# EPUB #
sphinx-build -b epub docs/ docs/_build/epub -D language="${current_language}"
mkdir -p "${docroot}/${current_language}/${current_version}"
cp "docs/_build/epub/target.epub" "${docroot}/${current_language}/${current_version}/helloWorld-docs_${current_language}_${current_version}.epub"
# copy the static assets produced by the above build into our docroot
rsync -av "docs/_build/html/" "${docroot}/"
done
done
# return to master branch
git checkout main
#######################
# Update GitHub Pages #
#######################
git config --global user.name "${GITHUB_ACTOR}"
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
pushd "${docroot}"
# don't bother maintaining history; just generate fresh
git init
git remote add deploy "https://token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
git checkout -b gh-pages
# add .nojekyll to the root so that github won't 404 on content added to dirs
# that start with an underscore (_), such as our "_content" dir..
touch .nojekyll
# add redirect from the docroot to our default docs language/version
cat > index.html <<EOF
<!DOCTYPE html>
<html>
<head>
<title>NiChart Docs</title>
<meta http-equiv = "refresh" content="0; url='/${REPO_NAME}/en/main/'" />
</head>
<body>
<p>Please wait while you're redirected to our <a href="/${REPO_NAME}/en/main/">documentation</a>.</p>
</body>
</html>
EOF
# Add README
cat > README.md <<EOF
# GitHub Pages Cache
Nothing to see here. The contents of this branch are essentially a cache that's not intended to be viewed on github.com.
If you're looking to update our documentation, check the 'docs/' dir.
If you are looking for documentation, please see:
* https://cbica.github.io/NiChart/
EOF
# copy the resulting html pages built from sphinx above to our new git repo
git add .
# commit all the new files
msg="Updating Docs for commit ${GITHUB_SHA} made on `date -d"@${SOURCE_DATE_EPOCH}" --iso-8601=seconds` from ${GITHUB_REF} by ${GITHUB_ACTOR}"
git commit -am "${msg}"
# convert LFS objects to binary files
git lfs migrate export --yes --include "*.png,*.gif,*.svg" --include-ref HEAD
# overwrite the contents of the gh-pages branch on our github.com repo
git push deploy gh-pages --force
popd # return to main repo sandbox root
# exit cleanly
exit 0