Skip to content

Commit 333d81b

Browse files
committed
CI make stable and dev version doc
1 parent 50dd208 commit 333d81b

File tree

4 files changed

+178
-64
lines changed

4 files changed

+178
-64
lines changed

build_tools/circle/build_doc.sh

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#!/usr/bin/env bash
2+
set -x
3+
set -e
4+
5+
# Decide what kind of documentation build to run, and run it.
6+
#
7+
# If the last commit message has a "[doc skip]" marker, do not build
8+
# the doc. On the contrary if a "[doc build]" marker is found, build the doc
9+
# instead of relying on the subsequent rules.
10+
#
11+
# We always build the documentation for jobs that are not related to a specific
12+
# PR (e.g. a merge to master or a maintenance branch).
13+
#
14+
# If this is a PR, do a full build if there are some files in this PR that are
15+
# under the "doc/" or "examples/" folders, otherwise perform a quick build.
16+
#
17+
# If the inspection of the current commit fails for any reason, the default
18+
# behavior is to quick build the documentation.
19+
20+
get_build_type() {
21+
if [ -z "$CIRCLE_SHA1" ]
22+
then
23+
echo SKIP: undefined CIRCLE_SHA1
24+
return
25+
fi
26+
commit_msg=$(git log --format=%B -n 1 $CIRCLE_SHA1)
27+
if [ -z "$commit_msg" ]
28+
then
29+
echo QUICK BUILD: failed to inspect commit $CIRCLE_SHA1
30+
return
31+
fi
32+
if [[ "$commit_msg" =~ \[doc\ skip\] ]]
33+
then
34+
echo SKIP: [doc skip] marker found
35+
return
36+
fi
37+
if [[ "$commit_msg" =~ \[doc\ quick\] ]]
38+
then
39+
echo QUICK: [doc quick] marker found
40+
return
41+
fi
42+
if [[ "$commit_msg" =~ \[doc\ build\] ]]
43+
then
44+
echo BUILD: [doc build] marker found
45+
return
46+
fi
47+
if [ -z "$CI_PULL_REQUEST" ]
48+
then
49+
echo BUILD: not a pull request
50+
return
51+
fi
52+
git_range="origin/master...$CIRCLE_SHA1"
53+
git fetch origin master >&2 || (echo QUICK BUILD: failed to get changed filenames for $git_range; return)
54+
filenames=$(git diff --name-only $git_range)
55+
if [ -z "$filenames" ]
56+
then
57+
echo QUICK BUILD: no changed filenames for $git_range
58+
return
59+
fi
60+
if echo "$filenames" | grep -q -e ^examples/
61+
then
62+
echo BUILD: detected examples/ filename modified in $git_range: $(echo "$filenames" | grep -e ^examples/ | head -n1)
63+
return
64+
fi
65+
echo QUICK BUILD: no examples/ filename modified in $git_range:
66+
echo "$filenames"
67+
}
68+
69+
build_type=$(get_build_type)
70+
if [[ "$build_type" =~ ^SKIP ]]
71+
then
72+
exit 0
73+
fi
74+
75+
MAKE_TARGET=html
76+
77+
# deactivate circleci virtualenv and setup a miniconda env instead
78+
if [[ `type -t deactivate` ]]; then
79+
deactivate
80+
fi
81+
82+
# Install dependencies with miniconda
83+
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh \
84+
-O miniconda.sh
85+
chmod +x miniconda.sh && ./miniconda.sh -b -p $MINICONDA_PATH
86+
export PATH="$MINICONDA_PATH/bin:$PATH"
87+
conda update --yes --quiet conda
88+
89+
# Configure the conda environment and put it in the path using the
90+
# provided versions
91+
conda create -n $CONDA_ENV_NAME --yes --quiet python=3
92+
source activate $CONDA_ENV_NAME
93+
94+
conda install --yes pip numpy scipy scikit-learn pillow matplotlib sphinx \
95+
sphinx_rtd_theme numpydoc
96+
pip install sphinx-gallery
97+
98+
# Build and install imbalanced-learn in dev mode
99+
cd "$HOME/$CIRCLE_PROJECT_REPONAME"
100+
ls -l
101+
python setup.py develop
102+
103+
# The pipefail is requested to propagate exit code
104+
set -o pipefail && cd doc && make $MAKE_TARGET 2>&1 | tee ~/log.txt
105+
106+
cd -
107+
set +o pipefail
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
# Add `master` branch to the update list.
4+
# Otherwise CircleCI will give us a cached one.
5+
FETCH_REFS="+master:master"
6+
7+
# Update PR refs for testing.
8+
if [[ -n "${CIRCLE_PR_NUMBER}" ]]
9+
then
10+
FETCH_REFS="${FETCH_REFS} +refs/pull/${CIRCLE_PR_NUMBER}/head:pr/${CIRCLE_PR_NUMBER}/head"
11+
FETCH_REFS="${FETCH_REFS} +refs/pull/${CIRCLE_PR_NUMBER}/merge:pr/${CIRCLE_PR_NUMBER}/merge"
12+
fi
13+
14+
# Retrieve the refs.
15+
git fetch -u origin ${FETCH_REFS}
16+
17+
# Checkout the PR merge ref.
18+
if [[ -n "${CIRCLE_PR_NUMBER}" ]]
19+
then
20+
git checkout -qf "pr/${CIRCLE_PR_NUMBER}/merge" || (
21+
echo Could not fetch merge commit. >&2
22+
echo There may be conflicts in merging PR \#${CIRCLE_PR_NUMBER} with master. >&2;
23+
exit 1)
24+
fi
25+
26+
# Check for merge conflicts.
27+
if [[ -n "${CIRCLE_PR_NUMBER}" ]]
28+
then
29+
git branch --merged | grep master > /dev/null
30+
git branch --merged | grep "pr/${CIRCLE_PR_NUMBER}/head" > /dev/null
31+
fi

build_tools/circle/push_doc.sh

Lines changed: 22 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,36 @@
11
#!/bin/bash
2-
# This script is meant to be called in the "deploy" step defined in
2+
# This script is meant to be called in the "deploy" step defined in
33
# circle.yml. See https://circleci.com/docs/ for more details.
44
# The behavior of the script is controlled by environment variable defined
55
# in the circle.yml in the top level folder of the project.
66

7-
MSG="Pushing the docs for revision for branch: $CIRCLE_BRANCH, commit $CIRCLE_SHA1"
7+
if [ "$CIRCLE_BRANCH" = "master" ]
8+
then
9+
dir=dev
10+
else
11+
# Strip off .X
12+
dir="${CIRCLE_BRANCH::-2}"
13+
fi
814

9-
cd $HOME
10-
# Copy the build docs to a temporary folder
11-
rm -rf tmp
12-
mkdir tmp
13-
cp -R $HOME/$DOC_REPO/doc/_build/html/* ./tmp/
15+
MSG="Pushing the docs to $dir/ for branch: $CIRCLE_BRANCH, commit $CIRCLE_SHA1"
1416

15-
# Clone the docs repo if it isnt already there
17+
cd $HOME
1618
if [ ! -d $DOC_REPO ];
17-
then git clone "git@github.com:$USERNAME/"$DOC_REPO".git";
19+
then git clone --depth 1 --no-checkout "git@github.com:"$ORGANIZATION"/"$DOC_REPO".git";
1820
fi
19-
2021
cd $DOC_REPO
21-
git branch gh-pages
22-
git checkout -f gh-pages
22+
git config core.sparseCheckout true
23+
echo $dir > .git/info/sparse-checkout
24+
git checkout gh-pages
2325
git reset --hard origin/gh-pages
24-
git clean -dfx
25-
26-
for name in $(ls -A $HOME/$DOC_REPO); do
27-
case $name in
28-
.nojekyll) # So that github does not build this as a Jekyll website.
29-
;;
30-
circle.yml) # Config so that build gh-pages branch.
31-
;;
32-
*)
33-
git rm -rf $name
34-
;;
35-
esac
36-
done
37-
38-
# Copy the new build docs
39-
mkdir $DOC_URL
40-
cp -R $HOME/tmp/* ./$DOC_URL/
41-
26+
git rm -rf $dir/ && rm -rf $dir/
27+
cp -R $HOME/imbalanced-learn/doc/_build/html $dir
28+
touch $dir/.nojekyll
4229
git config --global user.email $EMAIL
4330
git config --global user.name $USERNAME
44-
git add -f ./$DOC_URL/
45-
git commit -m "$MSG"
46-
git push -f origin gh-pages
47-
if [ $? -ne 0 ]; then
48-
echo "Pushing docs failed"
49-
echo
50-
exit 1
51-
fi
31+
git config --global push.default matching
32+
git add -f $dir/
33+
git commit -m "$MSG" $dir
34+
git push
5235

53-
echo $MSG
36+
echo $MSG

circle.yml

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
checkout:
2+
post:
3+
- ./build_tools/circle/checkout_merge_commit.sh
4+
15
machine:
26
environment:
37
# The github organization or username of the repository which hosts the
@@ -13,43 +17,32 @@ machine:
1317
# The email is to be used for commits in the Github Page
1418
EMAIL: "g.lemaitre58@gmail.com"
1519

16-
dependencies:
20+
MINICONDA_PATH: $HOME/miniconda
21+
CONDA_ENV_NAME: testenv
1722

18-
# Various dependencies
19-
pre:
20-
- sudo -E apt-get -yq remove texlive-binaries --purge
21-
- sudo apt-get update
22-
- sudo apt-get install libatlas-dev libatlas3gf-base
23-
- sudo apt-get install build-essential python-dev python-setuptools
24-
# install numpy first as it is a compile time dependency for other packages
25-
- pip install --upgrade numpy
26-
- pip install --upgrade scipy matplotlib setuptools nose coverage pillow
27-
- pip install --upgrade scikit-learn numpydoc
28-
- pip install --upgrade sphinx-gallery sphinx_rtd_theme sphinx==1.5.6
29-
# Installing required packages for `make -C doc check command` to work.
30-
- sudo -E apt-get -yq update
31-
- sudo -E apt-get -yq --no-install-suggests --no-install-recommends --force-yes install dvipng texlive-latex-base texlive-latex-extra
32-
33-
# The --user is needed to let sphinx see the source and the binaries
34-
# The pipefail is requested to propagate exit code
23+
dependencies:
24+
# Check whether the doc build is required, install build dependencies and
25+
# run sphinx to build the doc.
3526
override:
36-
- python setup.py clean
37-
- python setup.py develop
38-
- set -o pipefail && cd doc && make html 2>&1 | tee ~/log.txt
27+
- ./build_tools/circle/build_doc.sh:
28+
timeout: 3600 # seconds
29+
3930
test:
4031
# Grep error on the documentation
4132
override:
4233
- cat ~/log.txt && if grep -q "Traceback (most recent call last):" ~/log.txt; then false; else true; fi
34+
4335
deployment:
44-
push:
45-
branch: master
46-
commands:
47-
- bash build_tools/circle/push_doc.sh
36+
push:
37+
branch: /^master$|^[0-9]+\.[0-9]+\.X$/
38+
commands:
39+
- bash build_tools/circle/push_doc.sh
4840
general:
4941
# Open the doc to the API
5042
artifacts:
5143
- "doc/_build/html"
5244
- "~/log.txt"
45+
5346
# Restric the build to the branch master only
5447
branches:
5548
ignore:

0 commit comments

Comments
 (0)