forked from plumed/plumed2
/
push
executable file
·187 lines (156 loc) · 5.05 KB
/
push
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#! /bin/bash
WHAT=$1
case "$WHAT" in
(doc) echo "Pushing documentation" ;;
(coverage) echo "Pushing coverage" ;;
(*) echo "ERROR!!"
exit 1
esac
set -e
set -x
GIT_OWNER=$( echo $TRAVIS_REPO_SLUG | sed "s/\/.*$//" )
GIT_REPO=$( echo $TRAVIS_REPO_SLUG | sed "s/^.*\///" )
if [ "$TRAVIS_PULL_REQUEST" != false ] ; then
echo "Building from a pull request, nothing to push"
exit 0
fi
if [ "$GIT_OWNER" = plumed ] ; then
if [[ "$TRAVIS_BRANCH" =~ ^v2\.[0-9]+$ ]] ; then
if test -f CHANGES/"$TRAVIS_BRANCH".md && grep -q plumednotmaintained CHANGES/"$TRAVIS_BRANCH".md ; then
branchtype=unsupported
else
branchtype=official
fi
elif [ "$TRAVIS_BRANCH" = master ] ; then
branchtype=master
else
branchtype=unofficial
fi
else
branchtype=unofficial
fi
hash=$( git log -1 --format="%h")
root="$PWD"
mkdir -p tmp/$$
cd tmp/$$
case "$WHAT" in
(doc)
# grab doc
mkdir user-doc
cp -R $root/user-doc/{html,manual.pdf} user-doc/
test -d $root/user-doc/regtests && cp -R $root/user-doc/regtests user-doc/ || true
mkdir developer-doc
cp -R $root/developer-doc/html developer-doc/
;;
(coverage)
cp -R $root/developer-doc/coverage .
cp -R $root/developer-doc/coverage-libs .
esac
# This file should be here, it is needed otherwise
# files beginning with _ are skipped
touch .nojekyll
case "$WHAT" in
(doc)
cat > index.html << EOF
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Page Auto Redirect</title>
<meta http-equiv="refresh" content ="0; user-doc/html/index.html">
</head>
<body>
This is an auto redirect page.
</body>
</html>
EOF
;;
(coverage)
cat > index.html << EOF
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body>
<title> Coverage scan </title>
<h1> Coverage scan </h1>
Here you can find coverage scan reports for PLUMED:
<ul>
<li><a href=coverage/index.html>Standard coverage (excluding libraries)</a></li>
<li><a href=coverage-libs/index.html>Coverage for third-party libraries</a></li>
</ul>
The first one is equivalent to the one you will find on <a href="https://codecov.io/gh/$GIT_OWNER/$GIT_REPO">CodeCov</a> (if enabled).
The second one only contains third-party libraries included in PLUMED.
</body>
</html>
EOF
;;
esac
if test -z "${GIT_BOT}"
then
export GIT_BOT=plumedbot
fi
if test -z "${GIT_BOT_EMAIL}"
then
export GIT_BOT_EMAIL=giovanni.bussi+plumedbot@gmail.com
fi
git init
git config user.email "${GIT_BOT_EMAIL}"
git config user.name "${GIT_BOT}"
git checkout -b gh-pages
# this is not to show the GIT_TOKEN on Travis log
set +x
git remote add doc https://${GIT_BOT}:$GIT_TOKEN@github.com/$GIT_OWNER/${WHAT}-${TRAVIS_BRANCH}.git
set -x
case "$WHAT" in
(doc)
cat > README.md << EOF
Precompiled manual for PLUMED ${TRAVIS_BRANCH}
-----------------------------
This repository hosts a precompiled manual for [PLUMED](http://www.plumed.org) ${TRAVIS_BRANCH},
git revision [$hash](https://github.com/${GIT_OWNER}/${GIT_REPO}/commit/$hash).
To browse the manual you should go [here](http://${GIT_OWNER}.github.io/${WHAT}-${TRAVIS_BRANCH}).
You can also download a full copy of the manual for offline access
at [this link](http://github.com/${GIT_OWNER}/${WHAT}-${TRAVIS_BRANCH}/archive/gh-pages.zip).
This manual has been compiled on [travis](http://travis-ci.org/${GIT_OWNER}/${GIT_REPO}) on $(date).
EOF
case "$branchtype" in
(official) echo "This is the manual for an official and supported PLUMED branch." >> README.md ;;
(unsupported) echo "This is the manual for an official but unsupported PLUMED branch. It will not appear on search engines." >> README.md ;;
(master) echo "This is the manual for the development PLUMED branch." >> README.md ;;
(unofficial) echo "This is the manual for an unofficial PLUMED branch. It will not appear on search engines." >> README.md ;;
esac
;;
(coverage)
cat > README.md << EOF
Coverage scan for PLUMED ${TRAVIS_BRANCH}
-----------------------------
This repository hosts the coverage scan for [PLUMED](http://www.plumed.org) ${TRAVIS_BRANCH},
git revision [$hash](https://github.com/${GIT_OWNER}/${GIT_REPO}/commit/$hash).
Coverage scan done on [travis](http://travis-ci.org/${GIT_OWNER}/${GIT_REPO}) on $(date).
To browse the scan you should go [here](http://${GIT_OWNER}.github.io/${WHAT}-${TRAVIS_BRANCH}).
You can also download a full copy of the scan for offline access
at [this link](http://github.com/${GIT_OWNER}/${WHAT}-${TRAVIS_BRANCH}/archive/gh-pages.zip).
EOF
esac
case "$branchtype" in
(unsupported|unofficial)
# this is to avoid a huge log file:
set +x
for file in $(find . -name "*.html") ; do
awk '{
if(done){print; next;}
print
if(match($0,".*<head>.*")){
print "<meta name=\"robots\" content=\"noindex\">"
done=1;
}
}END{
if(!done) print "error: head not present in " FILENAME > "/dev/stderr"
}' $file > $$
mv $$ $file
done
set -x
esac
git add --all .
# >/dev/null to avoid excessive noise on travis log
git commit -m "Update to ${GIT_OWNER}/${GIT_REPO}@$hash" >/dev/null
# -q and 2> is not to show the GIT_TOKEN on Travis log
git push -q -f doc gh-pages 2> /dev/null