-
Notifications
You must be signed in to change notification settings - Fork 5
/
travis.linux.sh
205 lines (143 loc) · 4.28 KB
/
travis.linux.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
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/usr/bin/env bash
# -----------------------------------------------------------------------------
# Safety settings (see https://gist.github.com/ilg-ul/383869cbb01f61a51c4d).
if [[ ! -z ${DEBUG} ]]
then
set ${DEBUG} # Activate the expand mode if DEBUG is anything but empty.
else
DEBUG=""
fi
set -o errexit # Exit if command failed.
set -o pipefail # Exit if pipe failed.
set -o nounset # Exit if variable not set.
# Remove the initial space and instead use '\n'.
IFS=$'\n\t'
# -----------------------------------------------------------------------------
# https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables
# -----------------------------------------------------------------------------
export slug="${TRAVIS_BUILD_DIR}"
export site="${HOME}/out/${GITHUB_DEST_REPO}"
# -----------------------------------------------------------------------------
function do_run()
{
echo "\$ $@"
"$@"
}
# -----------------------------------------------------------------------------
# Not available:
# tree
# Errors in this function will break the build.
function do_before_install() {
echo "Before install, bring extra tools..."
cd "${HOME}"
do_run gem install html-proofer
do_run htmlproofer --version
return 0
}
# Errors in this function will break the build.
function do_before_script() {
echo "Before starting the test, clone the destination repo..."
cd "${HOME}"
do_run git config --global user.email "${GIT_COMMIT_USER_EMAIL}"
do_run git config --global user.name "${GIT_COMMIT_USER_NAME}"
# Clone the destination repo.
do_run git clone --branch=master https://github.com/${GITHUB_DEST_REPO}.git "${site}"
return 0
}
# Errors in this function will break the build.
function do_script() {
echo "The main test code; perform the Jekyll build..."
cd "${slug}"
# Be sure the 'vendor/' folder is excluded, otherwise a strage error occurs.
do_run bundle exec jekyll build --destination "${site}"
# Temporary test the Apple URL, to help diagnose htmlproofer.
# curl -L --url http://developer.apple.com/xcode/downloads/ --verbose
# Mainly to validate the internal & external links.
do_run bundle exec htmlproofer \
--url-ignore "https://developer.apple.com/xcode/downloads/,http://developer.apple.com/xcode/downloads/" \
"${site}"
# ---------------------------------------------------------------------------
# The deployment code is present here not in after_success,
# to break the build if not successful.
cd "${site}"
if [ "${TRAVIS_BRANCH}" != "master" ]
then
echo "Not on master branch, skip deploy."
return 0;
fi
if [ "${TRAVIS_PULL_REQUEST}" != "false" ]
then
echo "A pull request, skip deploy."
return 0;
fi
is_dirty=`git status --porcelain`
# Should detect new, modified, removed files.
if [ -z "${is_dirty}" ]
then
echo "No changes to the output on this push; skip deploy."
exit 0
fi
do_run git diff
do_run git add --all .
do_run git commit -m "Travis CI Deploy of ${TRAVIS_COMMIT}"
# git status
echo "Deploy to GitHub pages..."
# Must be quiet and have no output, to not reveal the key.
git push --force --quiet "https://${GITHUB_TOKEN}@github.com/${GITHUB_DEST_REPO}" master > /dev/null 2>&1
return 0
}
# Errors in the following function will not break the build.
function do_after_success() {
echo "Nothing to do after success..."
return 0
}
function do_after_failure() {
echo "Nothing to do after failure..."
return 0
}
function do_deploy() {
echo "Nothing to do to deploy..."
return 0
}
function do_after_script() {
echo "Nothing to do after script..."
return 0
}
# -----------------------------------------------------------------------------
if [ $# -ge 1 ]
then
action=$1
shift
case ${action} in
before_install)
do_before_install "$@"
;;
before_script)
do_before_script "$@"
;;
script)
do_script "$@"
;;
after_success)
do_after_success "$@"
;;
after_failure)
do_after_failure "$@"
;;
deploy)
do_deploy "$@"
;;
after_script)
do_after_script "$@"
;;
*)
echo "Unsupported command" "${action}" "$@"
exit 1
;;
esac
exit 0
else
echo "Missing command"
exit 1
fi
# -----------------------------------------------------------------------------