Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 91c6d0e

Browse files
authored
CI Speed-up doc builds (#34936)
1 parent 7eec52f commit 91c6d0e

2 files changed

Lines changed: 23 additions & 25 deletions

File tree

build_tools/circle/build_doc.sh

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,9 @@ set -x
2020
# defines the get_dep and show_installed_libraries functions
2121
source build_tools/shared.sh
2222

23-
if [ -n "$GITHUB_ACTION" ]
23+
if [[ -n "$CI_PULL_REQUEST" && -z "$CI_TARGET_BRANCH" ]]
2424
then
25-
# Map the variables from Github Action to CircleCI
26-
CIRCLE_SHA1=$(git log -1 --pretty=format:%H)
27-
28-
CIRCLE_JOB=$GITHUB_JOB
29-
30-
if [ "$GITHUB_EVENT_NAME" == "pull_request" ]
31-
then
32-
CIRCLE_BRANCH=$GITHUB_HEAD_REF
33-
CI_PULL_REQUEST=true
34-
CI_TARGET_BRANCH=$GITHUB_BASE_REF
35-
else
36-
CIRCLE_BRANCH=$GITHUB_REF_NAME
37-
fi
38-
fi
39-
40-
if [[ -n "$CI_PULL_REQUEST" && -z "$CI_TARGET_BRANCH" ]]
41-
then
42-
# Get the target branch name when using CircleCI
25+
# CircleCI does not expose the PR base branch as an environment variable.
4326
CI_TARGET_BRANCH=$(curl -s "https://api.github.com/repos/scikit-learn/scikit-learn/pulls/$CIRCLE_PR_NUMBER" | jq -r .base.ref)
4427
fi
4528

@@ -140,7 +123,15 @@ then
140123
exit 0
141124
fi
142125

143-
if [[ "$CIRCLE_BRANCH" =~ ^main$|^[0-9]+\.[0-9]+\.X$ && -z "$CI_PULL_REQUEST" ]]
126+
# ZIP, image optimization and version listing are only useful for the
127+
# documentation that is deployed to the website (the "doc" CircleCI job).
128+
deploy_docs=false
129+
if [[ "$CIRCLE_BRANCH" =~ ^main$|^[0-9]+\.[0-9]+\.X$ && -z "$CI_PULL_REQUEST" && "$CIRCLE_JOB" == "doc" ]]
130+
then
131+
deploy_docs=true
132+
fi
133+
134+
if [[ "$deploy_docs" == "true" ]]
144135
then
145136
# ZIP linked into HTML
146137
make_args=dist
@@ -157,10 +148,15 @@ else
157148
fi
158149

159150
# Installing required system packages to support the rendering of math
160-
# notation in the HTML documentation and to optimize the image files
151+
# notation in the HTML documentation. zip and optipng are only needed when
152+
# building the downloadable documentation archive for the website.
153+
apt_packages="dvipng gsfonts ccache"
154+
if [[ "$make_args" == "dist" ]]
155+
then
156+
apt_packages="$apt_packages zip optipng"
157+
fi
161158
sudo -E apt-get -yq update --allow-releaseinfo-change
162-
sudo -E apt-get -yq --no-install-suggests --no-install-recommends \
163-
install dvipng gsfonts ccache zip optipng
159+
sudo -E apt-get -yq --no-install-suggests --no-install-recommends install $apt_packages
164160

165161
# deactivate circleci virtualenv and setup a conda env instead
166162
if [[ `type -t deactivate` ]]; then
@@ -203,7 +199,7 @@ then
203199
towncrier build --yes
204200
fi
205201

206-
if [[ "$CIRCLE_BRANCH" =~ ^main$ && -z "$CI_PULL_REQUEST" ]]
202+
if [[ "$CIRCLE_BRANCH" == "main" && "$deploy_docs" == "true" ]]
207203
then
208204
# List available documentation versions if on main
209205
python build_tools/circle/list_versions.py --json doc/js/versions.json --rst doc/versions.rst

doc/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ ziphtml:
9292
make html; \
9393
fi
9494
# Optimize the images to reduce the size of the ZIP
95-
optipng $(BUILDDIR)/html/stable/_images/*.png
95+
# Use 3 cores to match the CircleCI `doc` resource class (medium+).
96+
find $(BUILDDIR)/html/stable/_images -name '*.png' -print0 \
97+
| xargs -0 -n 1 -P 3 optipng
9698
# Exclude the output directory to avoid infinity recursion
9799
cd $(BUILDDIR)/html/stable; \
98100
zip -q -x _downloads \

0 commit comments

Comments
 (0)