Skip to content

Commit 1f01e21

Browse files
committed
Add build script for Circle CI
1 parent ff2411e commit 1f01e21

File tree

3 files changed

+230
-22
lines changed

3 files changed

+230
-22
lines changed

circle.yml

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1+
2+
# Customize the test machine:
13
machine:
4+
5+
# Version of Node.js to use:
26
node:
37
version: 6
48

9+
10+
# Custom environment dependencies:
511
dependencies:
612
override:
7-
- 'nvm install 0.10 && nvm use 0.10 && npm update -g npm'
8-
- 'nvm install 0.12 && nvm use 0.12 && npm update -g npm'
9-
- 'nvm install 1 && nvm use 1 && npm update -g npm'
10-
- 'nvm install 2 && nvm use 2 && npm update -g npm'
11-
- 'nvm install 3 && nvm use 3 && npm update -g npm'
12-
- 'nvm install 4 && nvm use 4 && npm update -g npm'
13-
- 'nvm install 5 && nvm use 5 && npm update -g npm'
14-
- 'nvm install 6 && nvm use 6 && npm update -g npm'
1513
- 'nvm install node && nvm use node && npm update -g npm'
14+
- 'nvm install 6 && nvm use 6 && npm update -g npm'
15+
- 'nvm install 5 && nvm use 5 && npm update -g npm'
16+
- 'nvm install 4 && nvm use 4 && npm update -g npm'
17+
- 'nvm install 3 && nvm use 3 && npm update -g npm'
18+
- 'nvm install 2 && nvm use 2 && npm update -g npm'
19+
- 'nvm install 1 && nvm use 1 && npm update -g npm'
20+
- 'nvm install 0.12 && nvm use 0.12 && npm update -g npm'
21+
- 'nvm install 0.10 && nvm use 0.10 && npm update -g npm'
22+
1623

24+
# Custom test commands:
1725
test:
1826
override:
19-
- 'nvm use 0.10 && rm -rf node_modules && npm install && make examples'
20-
- 'nvm use 0.12 && rm -rf node_modules && npm install && make examples'
21-
- 'nvm use 1 && rm -rf node_modules && npm install && make examples'
22-
- 'nvm use 2 && rm -rf node_modules && npm install && make examples'
23-
- 'nvm use 3 && rm -rf node_modules && npm install && make examples'
24-
- 'nvm use 4 && rm -rf node_modules && npm install && make examples'
25-
- 'nvm use 5 && rm -rf node_modules && npm install && make examples'
26-
- 'nvm use 6 && rm -rf node_modules && npm install && make examples'
27-
- 'nvm use node && rm -rf node_modules && npm install && make examples'
27+
- chmod +x ./tools/ci/circle
28+
- ./tools/ci/circle

tools/ci/circle

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Build script to run continuous integration on [Circle CI][1].
4+
#
5+
# [1]: https://circleci.com
6+
7+
8+
# VARIABLES #
9+
10+
# Define a username:
11+
username="${CIRCLE_USERNAME}"
12+
13+
# Get the total number of VMs (parallelism):
14+
total_nodes="${CIRCLE_NODE_TOTAL}"
15+
16+
# Get the VM index:
17+
index="${CIRCLE_NODE_INDEX}"
18+
19+
# Define an output file to store log output:
20+
log_file='/var/log/circle-ci.log'
21+
22+
# Define a heartbeat interval to periodically print messages in order to prevent Circle CI from prematurely ending a build due to long running commands:
23+
heartbeat_interval='30s'
24+
25+
# Declare a variable for storing the heartbeat process id:
26+
heartbeat_pid=""
27+
28+
# Define the number of lines of logged output to print upon completion:
29+
tail_num_lines=4000
30+
31+
32+
# FUNCTIONS #
33+
34+
# Defines an error handler.
35+
#
36+
# $1 - error status
37+
on_error() {
38+
echo 'ERROR: An error was encountered during execution.' >&2
39+
cleanup
40+
exit "$1"
41+
}
42+
43+
# Runs clean-up tasks.
44+
cleanup() {
45+
tail_output "${log_file}" "${tail_num_lines}"
46+
stop_heartbeat
47+
}
48+
49+
# Starts a heartbeat.
50+
#
51+
# $1 - heartbeat interval
52+
start_heartbeat() {
53+
echo 'Starting heartbeat...' >&2
54+
55+
# Create a heartbeat and send to background:
56+
heartbeat "$1" &
57+
58+
# Capture the heartbeat pid:
59+
heartbeat_pid=$!
60+
echo "Heartbeat pid: ${heartbeat_pid}" >&2
61+
}
62+
63+
# Runs an infinite print loop.
64+
#
65+
# $1 - heartbeat interval
66+
heartbeat() {
67+
while true; do
68+
echo "$(date) - heartbeat..." >&2;
69+
sleep "$1";
70+
done
71+
}
72+
73+
# Stops the heartbeat print loop.
74+
stop_heartbeat() {
75+
echo 'Stopping heartbeat...' >&2
76+
kill "${heartbeat_pid}"
77+
}
78+
79+
# Tails a log file.
80+
#
81+
# $1 - log file to tail
82+
# $2 - number of lines to tail
83+
tail_output() {
84+
echo "Printing the last $2 lines of log output..." >&2
85+
tail -"$2" "$1"
86+
}
87+
88+
# Creates an output log file.
89+
#
90+
# $1 - log file path
91+
create_log_file() {
92+
echo "Creating an output log file: $1." >&2
93+
sudo touch "$1"
94+
sudo chown "${username}" "$1"
95+
}
96+
97+
# Prints a success message.
98+
print_success() {
99+
echo 'Success!' >&2
100+
}
101+
102+
# Sets the Node.js version.
103+
#
104+
# $1 - version
105+
node_version() {
106+
echo "Switching to Node.js version: $1..." >&2
107+
nvm use "$1"
108+
}
109+
110+
# Remove node modules.
111+
#
112+
# $1 - log file
113+
clean_node() {
114+
echo 'Removing node module dependencies...' >&2
115+
make clean-node >> "$1" 2>&1
116+
if [[ "$?" -ne 0 ]]; then
117+
echo 'Error when attempting to remove dependencies.' >&2
118+
return 1
119+
fi
120+
echo 'Dependencies successfully removed.' >&2
121+
return 0
122+
}
123+
124+
# Installs dependencies.
125+
#
126+
# $1 - log file
127+
install() {
128+
echo 'Installing...' >&2
129+
make install >> "$1" 2>&1
130+
if [[ "$?" -ne 0 ]]; then
131+
echo 'Error occurred during install.' >&2
132+
return 1
133+
fi
134+
echo 'Install successful.' >&2
135+
return 0
136+
}
137+
138+
# Initializes the Node.js environment.
139+
#
140+
# $1 - Node.js version
141+
# $2 - log file
142+
init() {
143+
node_version "$1"
144+
clean_node "$2"
145+
if [[ "$?" -ne 0 ]]; then
146+
return 1
147+
fi
148+
install "$2"
149+
if [[ "$?" -ne 0 ]]; then
150+
return 1
151+
fi
152+
return 0
153+
}
154+
155+
# Checks dependencies.
156+
#
157+
# $1 - log file
158+
check_deps() {
159+
echo 'Checking dependencies...' >&2
160+
make check-deps >> "$1" 2>&1
161+
if [[ "$?" -ne 0 ]]; then
162+
echo 'Dependencies are out-of-date.' >&2
163+
return 1
164+
fi
165+
echo 'Dependencies are up-to-date.' >&2
166+
return 0
167+
}
168+
169+
# Performs lint tasks.
170+
#
171+
# $1 - log file
172+
lint() {
173+
echo 'Linting filenames...' >&2
174+
make lint-filenames >> "$1" 2>&1
175+
if [[ "$?" -ne 0 ]]; then
176+
echo 'Linting failed.' >&2
177+
return 1
178+
fi
179+
echo 'Linting passed.' >&2
180+
return 0
181+
}
182+
183+
# Main execution sequence.
184+
main() {
185+
create_log_file "${log_file}"
186+
start_heartbeat "${heartbeat_interval}"
187+
188+
# Initialize the Node.js environment:
189+
init stable "${log_file}"
190+
if [[ "$?" -ne 0 ]]; then
191+
on_error 1
192+
fi
193+
194+
# Assign nodes (VMs) initial tasks:
195+
if [[ "${index}" = "0" ]]; then
196+
check_deps "${log_file}"
197+
if [[ "$?" -ne 0 ]]; then
198+
on_error 1
199+
fi
200+
elif [[ "${index}" = "1" ]]; then
201+
lint "${log_file}"
202+
if [[ "$?" -ne 0 ]]; then
203+
on_error 1
204+
fi
205+
fi
206+
cleanup
207+
print_success
208+
exit 0
209+
}
210+
211+
# Run main:
212+
main

tools/ci/travis

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,6 @@ main() {
185185

186186
echo "Task: ${task}." >&2
187187
if [[ "${task}" = "test" ]]; then
188-
# FIXME: remove checking deps once separate build environment
189-
check_deps "${log_file}"
190-
if [[ "$?" -ne 0 ]]; then
191-
on_error 1
192-
fi
193188
run_tests "${log_file}"
194189
if [[ "$?" -ne 0 ]]; then
195190
on_error 1

0 commit comments

Comments
 (0)