forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcanvas_update
executable file
·158 lines (133 loc) · 3.89 KB
/
canvas_update
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
#!/bin/bash
# TODO: improve usage / help
function usage {
echo "usage: canvas_update [[[-q]] | [-h]]"
}
function echo_console_and_log {
echo "$1"
echo "$1" >>"$LOG"
}
function is_git_dir {
git rev-parse --is-inside-git-dir >/dev/null 2>&1 && [ -d .git ]
return $?
}
function is_canvas_root {
CANVAS_IN_README=$(head -1 README.md 2>/dev/null | grep 'Canvas LMS')
[[ "$CANVAS_IN_README" != "" ]] && is_git_dir
return $?
}
function ensure_in_canvas_root_directory {
if ! is_canvas_root; then
echo "Please run from a Canvas root directory"
exit 0
fi
}
function intro_message {
echo "Bringing Canvas up to date ..."
echo " Log file is $LOG"
echo >>"$LOG"
echo "-----------------------------" >>"$LOG"
echo "Canvas Update ($(date)):" >>"$LOG"
echo "-----------------------------" >>"$LOG"
}
function update_plugin {
(
cd "$1"
if is_git_dir; then
echo_console_and_log " Updating plugin $1 ..."
( git checkout master >>"$LOG" 2>&1 && \
git pull --rebase >>"$LOG" 2>&1 ) || \
( echo " failed to pull plugin (see $LOG)"; kill -INT $$ )
fi
)
}
function update_plugins {
# Loop through each plugin dir, and if it's a git repo, update it
# This needs to be done first so that db:migrate can pull in any plugin-
# precipitated changes to the database.
for dir in {gems,vendor}; do
if [ -d "$dir/plugins" ]; then
for plugin in $dir/plugins/*; do update_plugin "$plugin"; done
fi
done
}
function rebase_canvas {
echo_console_and_log " Pulling Canvas code ..."
( git checkout master >>"$LOG" 2>&1 && git pull --rebase >>"$LOG" 2>&1 ) || \
( echo " failed to pull Canvas (see $LOG)"; kill -INT $$ )
}
function bundle_install_with_check {
echo_console_and_log " Checking your gems (bundle check) ..."
if bundle check >>"$LOG" 2>&1 ; then
echo_console_and_log " Gems are up to date, no need to bundle install ..."
else
bundle_install
fi
}
function bundle_install {
echo_console_and_log " Installing gems (bundle install) ..."
rm Gemfile.lock* >/dev/null 2>&1
bundle install >>"$LOG" 2>&1 || \
( echo " failed to bundle install (see $LOG)"; kill -INT $$ )
}
function rake_db_migrate_dev_and_test {
echo_console_and_log " Migrating DB ..."
RAILS_ENV=development bundle exec rake db:migrate >>"$LOG" 2>&1 || \
( echo " failed to migrate db (development) (see $LOG)"; kill -INT $$ )
RAILS_ENV=test bundle exec rake db:migrate >>"$LOG" 2>&1 || \
( echo " failed to migrate db (test) (see $LOG)"; kill -INT $$ )
}
function npm_install {
echo_console_and_log " Installing npm packages ..."
npm install >>"$LOG" 2>&1 || \
( echo " failed to install npm packages (see $LOG)"; kill -INT $$ )
}
function compile_assets {
echo_console_and_log " compiling assets ..."
bundle exec rake 'canvas:compile_assets_dev' >>"$LOG" 2>&1 || \
( echo " failed to generate JS (see $LOG)"; kill -INT $$ )
}
# TODO: moar tips plz
function tips {
echo "Tips:"
echo " - 'bundle exec guard': auto-compiles JS files while developing"
echo " - 'script/delayed_job run': run delayed jobs in the foreground"
}
function update_canvas {
ensure_in_canvas_root_directory
intro_message
update_plugins
rebase_canvas
bundle_install_with_check
rake_db_migrate_dev_and_test
npm_install
# skip if QUICK_MODE
if ! $1; then
compile_assets
fi
tips
}
LOG="$(pwd)/log/canvas_update.log"
# default options
PERFORM_UPDATE=true
QUICK_MODE=false
# parse options
# http://www.tldp.org/LDP/abs/html/internal.html#EX33
while getopts ":qh" Option
do
case $Option in
q )
echo "Quick mode enabled (assumes you have guard running and don't want to generate docs)"
QUICK_MODE=true;;
h )
PERFORM_UPDATE=false
usage;;
* )
PERFORM_UPDATE=false
echo "Sorry, that's not a valid option!"
usage;;
esac
done
if $PERFORM_UPDATE; then
update_canvas $QUICK_MODE
fi