-
Notifications
You must be signed in to change notification settings - Fork 306
/
bash_scripts.rb
281 lines (265 loc) · 6.57 KB
/
bash_scripts.rb
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# Regarding problems experienced while shelling out, see:
# http:https://julialang.org/blog/2012/03/shelling-out-sucks/
# But the solution seems to be here:
# http:https://ruby-doc.org/stdlib-1.9.3/libdoc/shell/rdoc/Shell/CommandProcessor.html#method-i-system
# For portability issues, see:
# https://wiki.ubuntu.com/DashAsBinSh
# http:https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/html_node/Limitations-of-Builtins.html
# http:https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/html_node/Limitations-of-Usual-Tools.html
# http:https://heirloom.sourceforge.net/sh.html
CLONE_APP_REPOSITORIES_SCRIPT = <<BASH
# Clone Rails Example App repositories:
repositories=`cat repo-list`
for repo in $repositories
do
if test $repo != rails_apps_composer; then
echo $repo:
if test -d $repo; then :; else
(
set -x # xtrace
git clone [email protected]:RailsApps/$repo.git
cd $repo
git remote rename origin upstream
)
fi
fi
done
)
BASH
=begin
# Utilities:
rails_apps_composer
rails-composer
# Obsolete Rails 3 apps:
Which apps are obsolete?
# Can these work?
rails3-bootstrap-devise-cancan
rails3-devise-rspec-cucumber
rails3-mongoid-devise
rails3-mongoid-omniauth
rails3-subdomains
rails-prelaunch-signup
rails-recurly-subscription-saas
rails-stripe-membership-saas
=end
CREATE_REPOSITORY_LIST_SCRIPT = <<BASH
# Create the repository list (keep utilities first):
cat > repo-list <<HERE
rails_apps_composer
rails-composer
rails-omniauth
HERE
)
BASH
FETCH_APP_UPDATES_SCRIPT = <<BASH
# Fetch Rails Example App updates:
repositories=`cat repo-list`
for repo in $repositories
do
echo
echo $repo:
(
cd $repo
pwd
(
set -x # xtrace
git fetch upstream
)
)
done
)
BASH
GENERATE_APPS_SCRIPT = <<BASH
# Generate Rails Example Apps:
repositories=`cat repo-list`
for repo in $repositories
do
# Keep space between: to avoid the (( builtin.
if ( (test $repo = rails_apps_composer) ||
(test $repo = rails-composer ) ); then :; else
echo $repo:
(
set -x # xtrace
# On Mac OS X (& NetBSD), 'rm' lacks --force and --recursive (as spelled-out options).
rm -rf $directory/$repo
rails_apps_composer new $directory/$repo --quiet --verbose\\
--recipes=`echo $repo | sed s/-/_/g`_testing_recipe railsapps\\
--recipe-dirs=rails_apps_composer/megatest/config\\
--defaults=rails_apps_composer/megatest/config/$repo.yml
)
fi
done
)
BASH
LIST_APP_REMOTES_SCRIPT = <<BASH
# List Rails Example App remotes:
repositories=`cat repo-list`
for repo in $repositories
do
echo
echo $repo:
(
cd $repo
git remote --verbose
)
done
)
BASH
MAKE_APPS_READ_SERVICE_ENV_VARS_SCRIPT = <<BASH
# Make Rails Example Apps read service key environment variables:
sed_commands=`pwd`/sed-commands.txt
cat > $sed_commands <<CAT
s/replace_with_your_recurly_api_key/<%= ENV[ %q{rac_test_RECURLY_API_KEY} ] %>/
s/replace_with_your_recurly_js_private_key/<%= ENV[ %q{rac_test_RECURLY_JS_PRIVATE_KEY} ] %>/
s/Your_Stripe_API_key/<%= ENV[ %q{rac_test_STRIPE_API_KEY} ] %>/
s/Your_Stripe_Public_Key/<%= ENV[ %q{rac_test_STRIPE_PUBLIC_KEY} ] %>/
CAT
repositories=`cat repo-list`
for repo in $repositories
do
if ( (test $repo = rails_apps_composer) ||
(test $repo = rails-composer ) ); then :; else
echo
echo $directory/$repo:
(
cd $directory/$repo
pwd
set -x # xtrace
git checkout --quiet master
set +e # errexit
# On Mac OS X (& NetBSD), 'sed' lacks --file and --in-place (as spelled-out options).
sed -if $sed_commands config/application.yml; true
)
if test $repo = rails-prelaunch-signup; then
echo
(
cd $directory/$repo
set -x # xtrace
git checkout --quiet wip
set +e # errexit
sed -if $sed_commands config/application.yml; true
)
fi
fi
done
rm -f $sed_commands
)
BASH
MIGRATE_APP_DATABASES_SCRIPT = <<BASH
# Migrate Rails Example App databases:
repositories=`cat repo-list`
for repo in $repositories
do
if ( (test $repo = rails_apps_composer) ||
(test $repo = rails-composer ) ); then :; else
echo
(
cd $directory/$repo
pwd
(
set -x # xtrace
git checkout --quiet master
bundle exec rake db:migrate
git status
)
if test $repo = rails-prelaunch-signup; then
(
set -x # xtrace
git checkout --quiet wip
bundle exec rake db:migrate
git status
)
fi
)
fi
done
)
BASH
REBASE_APP_UPDATES_SCRIPT = <<BASH
# Rebase Rails Example App updates:
repositories=`cat repo-list`
for repo in $repositories
do
echo
echo $repo:
(
cd $repo
pwd
(
set -x # xtrace
git checkout master
git rebase upstream/master master
)
if test $repo = rails-prelaunch-signup; then
echo
(
set -x # xtrace
# Till branch 'wip' is added to the GitHub repository, continue on error:
set +e # errexit
git checkout wip
git rebase upstream/wip wip; true
)
fi
)
done
)
BASH
SET_CLONED_DIRECTORY_SCRIPT = <<BASH
# Set the directory to run a parallel script on the cloned repositories:
(
set -e # errexit
cd ..
directory=.
export directory
BASH
SET_GENERATED_DIRECTORY_SCRIPT = <<BASH
# Set the directory to run a parallel script on the generated repositories:
(
set -e # errexit
cd ..
directory=generated
export directory
BASH
SHOW_APPS_GIT_STATUS_SCRIPT = <<BASH
# Show Rails Example Apps' git status
repositories=`cat repo-list`
for repo in $repositories
do
echo
(
set -x # xtrace
cd $directory/$repo
pwd
git status
)
done
)
BASH
TEST_APPS_SCRIPT = <<BASH
# Test Rails Example Apps:
repositories=`cat repo-list`
for repo in $repositories
do
if ( (test $repo = rails_apps_composer) ||
(test $repo = rails-composer ) ); then :; else
(
echo $directory/$repo:
cd $directory/$repo
pwd
(
set -x # xtrace
git checkout --quiet master
bundle exec rake
)
if test $repo = rails-prelaunch-signup; then
(
set -x # xtrace
git checkout --quiet wip
bundle exec rake
)
fi
)
fi
done
)
BASH