Skip to content

Commit 416771e

Browse files
authored
2.x: Automatically publish the generated JavaDocs from CI (#5996)
* Experiment: auto publish JavaDocs * Fix script error, add logging * Have all package-list staged * Fix another scripting error * Fix copy paths * Real pushback on snapshot builds. * Pull requests should not trigger snapshot pushbacks * Rename push.sh to push_javadoc.sh
1 parent 90203b6 commit 416771e

File tree

2 files changed

+121
-0
lines changed

2 files changed

+121
-0
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ script: gradle/buildViaTravis.sh
2020
# Code coverage
2121
after_success:
2222
- bash <(curl -s https://codecov.io/bash)
23+
- bash gradle/push_javadoc.sh
2324

2425
# cache between builds
2526
cache:

gradle/push_javadoc.sh

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#!/bin/bash
2+
# ----------------------------------------------------------
3+
# Automatically push back the generated JavaDocs to gh-pages
4+
# ----------------------------------------------------------
5+
# based on https://gist.github.com/willprice/e07efd73fb7f13f917ea
6+
7+
# specify the common address for the repository
8+
targetRepo=github.com/ReactiveX/RxJava.git
9+
# =======================================================================
10+
11+
# only for main pushes, for now
12+
if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
13+
echo -e "Pull request detected, skipping JavaDocs pushback."
14+
exit 0
15+
fi
16+
17+
# get the current build tag if any
18+
buildTag="$TRAVIS_TAG"
19+
echo -e "Travis tag: '$buildTag'"
20+
21+
if [ "$buildTag" == "" ]; then
22+
buildTag="snapshot"
23+
else
24+
buildTag="${buildTag:1}"
25+
fi
26+
27+
echo -e "JavaDocs pushback for tag: $buildTag"
28+
29+
# check if the token is actually there
30+
if [ "$GITHUB_TOKEN" == "" ]; then
31+
echo -e "No access to GitHub, skipping JavaDocs pushback."
32+
exit 0
33+
fi
34+
35+
# prepare the git information
36+
git config --global user.email "[email protected]"
37+
git config --global user.name "Travis CI"
38+
39+
# setup the remote
40+
echo -e "Adding the target repository to git"
41+
git remote add origin-pages https://${GITHUB_TOKEN}@${targetRepo} > /dev/null 2>&1
42+
43+
# stash changes due to chmod
44+
echo -e "Stashing any local non-ignored changes"
45+
git stash
46+
47+
# get the gh-pages
48+
echo -e "Update branches and checking out gh-pages"
49+
git fetch --all
50+
git branch -a
51+
git checkout -b gh-pages origin-pages/gh-pages
52+
53+
# releases should update 2 extra locations
54+
if [ "$buildTag" != "snapshot" ]; then
55+
# for releases, add a new directory with the new version
56+
# and carefully replace the others
57+
58+
# 1.) main javadoc
59+
# ----------------
60+
# remove the io subdir
61+
echo -e "Removing javadoc/io"
62+
rm -r javadoc/io
63+
64+
# remove the html files
65+
echo -e "Removing javadoc/*.html"
66+
rm javadoc/*.html
67+
68+
# copy the new doc
69+
echo -e "Copying to javadoc/"
70+
yes | cp -rf ./build/docs/javadoc/ .
71+
72+
# 2.) 2.x javadoc
73+
# remove the io subdir
74+
echo -e "Removing 2.x/javadoc/io"
75+
rm -r 2.x/javadoc/io
76+
77+
# remove the html files
78+
echo -e "Removing 2.x/javadoc/*.html"
79+
rm 2.x/javadoc/*.html
80+
81+
# copy the new doc
82+
echo -e "Copying to 2.x/javadoc/"
83+
yes | cp -rf ./build/docs/javadoc/ 2.x/
84+
fi
85+
86+
# 3.) create a version/snapshot specific copy of the docs
87+
# clear the existing tag
88+
echo -e "Removing to 2.x/javadoc/${buildTag}"
89+
rm -r 2.x/javadoc/${buildTag}
90+
91+
# copy the new doc
92+
echo -e "Copying to 2.x/javadoc/${buildTag}"
93+
yes | cp -rf ./build/docs/javadoc/ 2.x/javadoc/${buildTag}/
94+
95+
96+
# stage all changed and new files
97+
echo -e "Staging new files"
98+
git add *.html
99+
git add *.css
100+
git add *.js
101+
git add *package-list*
102+
103+
# remove tracked but deleted files
104+
echo -e "Removing deleted files"
105+
git add -u
106+
107+
# commit all
108+
echo -e "commit Travis build: $TRAVIS_BUILD_NUMBER for $buildTag"
109+
git commit --message "Travis build: $TRAVIS_BUILD_NUMBER for $buildTag"
110+
111+
# debug file list
112+
#find -name "*.html"
113+
114+
# push it
115+
echo -e "Pushing back changes."
116+
git push --quiet --set-upstream origin-pages gh-pages
117+
118+
119+
# we are done
120+
echo -e "JavaDocs pushback complete."

0 commit comments

Comments
 (0)