-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_project
executable file
·7246 lines (6177 loc) · 281 KB
/
build_project
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash -e
debug_mode="true"
debug_mode="false"
# TODO -- Add --heroku option for:
# build
# db_reset
# deploy?
# Reinstall all gems...
# uninstall() {
# list=`gem list --no-versions`
# for gem in $list; do
# gem uninstall $gem -aIx
# done
# gem list
# gem install bundler
# }
#
# #rbenv versions --bare
# RBENVPATH=`rbenv root`
# echo $RBENVPATH
# RUBIES=`ls $RBENVPATH/versions`
# for ruby in $RUBIES; do
# echo '---------------------------------------'
# echo $ruby
# rbenv local $ruby
# uninstall
# done
function load_project_settings
{
exe_name="${1}"
# Default values based on the system being build for the Sparrow project.
# sparrow
project_base_name="sparrow"
# Sparrow/
project_base_parent_dir="Sparrow/"
# SageACT
project_repository_name="SageACT"
# sparrow_host
project_app_directory="sparrow_host"
db_root_user_password=""
# build_project
proj_dir="${exe_name:0:$((${#exe_name} - 13))}"
if [ -f ${proj_dir}/settings_for_build_project ]; then
settings_lines=$(cat ${proj_dir}/settings_for_build_project)
while read exec_setting_val; do
eval ${exec_setting_val}
done <<< "${settings_lines}"
fi
if [ -f ${proj_dir}/private_settings_for_build_project ]; then
settings_lines=$(cat ${proj_dir}/private_settings_for_build_project)
while read exec_setting_val; do
eval ${exec_setting_val}
done <<< "${settings_lines}"
fi
}
load_project_settings "${0}"
# Todo:
# undo commit # git reset --hard HEAD~1
# git merge --abort
# global variables...
declare -a branches
declare -a command_descriptions
declare -a command_options_show
declare -a command_options
declare -a command_vars
declare -a additional_params
time_format_sting="+%Y-%m-%d-%H-%M-%S"
merge_conflict_status_grep="^\(DD\|AA\|.U\|U.\)"
test_param_test_number=""
test_param_test_line=""
smoke_browser_set="false"
local_branch=-1
local_branch_name="master"
command_line_arguments=("$@")
current_directory="$(pwd)"
rails_env_to_use="development"
return_line="
"
tab_character=" "
build_base_directory="${current_directory}/${project_base_name}"
build_parent_directory="${current_directory}"
build_log_directory="${build_parent_directory}/BuildLogs"
# The script was originally built "outside" the project directory, and I like it that way
# however in order to be able to check it in, it needs to be in the project directory,
# and should therefore be able to run there.
#
# So, the script works on 3 levels:
#
# 1) It can be run directly from the project folder.
# 2) It can be run from the directory that contains the project folder
# 3) It can be run from the directory I like which contains a directory
# named "<project name>" that then contains the project itself.
if [ -d "${current_directory}/.git" ]; then
if [ -f "${current_directory}/.git/config" ]; then
project_is_local="false"
if ! grep -q "[email protected]:${project_repository_name}/${project_base_name}.git" ${current_directory}/.git/config; then
project_is_local="true"
fi
if ! grep -q "https://github.com/${project_repository_name}/${project_base_name}.git" ${current_directory}/.git/config; then
project_is_local="true"
fi
if [ "${project_is_local}" = "true" ]; then
build_base_directory=${current_directory}
cd ..
build_parent_directory="$(pwd)"
cd ${build_base_directory}
fi
fi
fi
if [ ! -d "${build_base_directory}/.git" ]; then
if [ -d "${current_directory}/${project_base_parent_dir}${project_base_name}/.git" ]; then
build_base_directory="${current_directory}/${project_base_parent_dir}${project_base_name}"
build_parent_directory="${current_directory}/${project_base_parent_dir}"
fi
fi
build_log_directory="${build_parent_directory}/BuildLogs"
function initialize_commands
{
# We initialize the the list of commands into an array so that
# we can easily add new commands and parse them here.
# Having them in the array also simplifies the help screen and
# a command prompt option.
# -b, --build - Build the project
# -t, --test - Run tests
# -p, --pull - Pull the source
# -m, --merge - Merge a branch
# -h, --push - Push committed changes to GitHub
# -u, --status - Just do a git status on the current branch...
# -n, --new_branch --new-branch - Create a branch
# -?, --help - Show help
# -s, --switch - Switch branches
# -d, --delete - Delete a branch
# -g, --guard - Launch Gaurd continuous testing
# -e, --reset_db --reset-db - Delete and reset/recreate DBs
# -c, --console - Run the Rails console
# -r, --run - Run the application
# -v, --move - Move the current git directory out of the way
# -l, --clone - Clone the repository
# -o, --production - Production Deployment
# --base_dir --base-dir - The base directory to work in (the parent to the project)
# --rails_env --rails-env - The RAILS_ENV to use for build/deploy
# -y --deploy - Deploy the system to one of the known machines
# --history - Show recent history
# --stash_locks --stash-locks - Backup the Gemfile.lock files that are not checked in
# ---stash - Menuized version of git stash
# --stash - Stash the current branch
# --drop_stash --drop-stash - Drop a stash
# --unstash - Apply a stash
# --reset_git --reset-git - Do a hard reset
# --smoke - Do a partial test of only running the ci:smoke.
# ---test - Menuized testing options
# --test_params --test-params - Parameters for running the menuized tests in the form of "<test number>[:<line_number>]"
# --check-merge --check_merge - Uses git-status to validate/check/add and finally commit files with merge conflicts
# --db-dump --db_dump - Drop the test databases and recreate them to dump the schema into the schema.rb file.
# --db-branch --db_branch - Configure wether or not the database is branched as well.
# --clean - Do a clean of the git repository...
# --patch - Create a patch file
# --apply-patch - Apply a patch to the current branch.
# --list - List branches
# --reset-build-cache - Reset the cache of build information to force the bundle instal to run.
# If this has been called before, don't do it again...
if [ "${#command_vars[@]}" -le "0" ]; then
# -b, --build - Build the project
command_vars[${#command_vars[@]}]="do_build_project"
command_options_show[${#command_options_show[@]}]="-b --build"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]}"
command_descriptions[${#command_descriptions[@]}]="Build ${project_base_name}"
# -t, --test - Run tests
command_vars[${#command_vars[@]}]="do_run_tests"
command_options_show[${#command_options_show[@]}]="-t --test"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]}"
command_descriptions[${#command_descriptions[@]}]="Run tests"
# -p, --pull - Pull the source
command_vars[${#command_vars[@]}]="do_pull_source"
command_options_show[${#command_options_show[@]}]="-p --pull"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]}"
command_descriptions[${#command_descriptions[@]}]="Pull the source"
# -m, --merge - Merge a branch
command_vars[${#command_vars[@]}]="do_merge"
command_options_show[${#command_options_show[@]}]="-m --merge"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]}"
command_descriptions[${#command_descriptions[@]}]="Merge a branch"
# -h, --push - Push committed changes to GitHub
command_vars[${#command_vars[@]}]="do_push_source"
command_options_show[${#command_options_show[@]}]="-h --push"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]}"
command_descriptions[${#command_descriptions[@]}]="Push committed changes to GitHub"
# -u, --status - Just do a git status on the current branch...
command_vars[${#command_vars[@]}]="do_show_status"
command_options_show[${#command_options_show[@]}]="-u --status"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]}"
command_descriptions[${#command_descriptions[@]}]="Just do a git status on the current branch..."
# -n, --new_branch --new-branch - Create a branch
command_vars[${#command_vars[@]}]="do_create_branch"
command_options_show[${#command_options_show[@]}]="-n --new_branch"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]} --new-branch --new"
command_descriptions[${#command_descriptions[@]}]="Create a branch"
# -?, --help - Show help
command_vars[${#command_vars[@]}]="show_help"
command_options_show[${#command_options_show[@]}]="-? --help"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]}"
command_descriptions[${#command_descriptions[@]}]="Show help"
# -s, --switch - Switch branches
command_vars[${#command_vars[@]}]="do_switch"
command_options_show[${#command_options_show[@]}]="-s --switch"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]}"
command_descriptions[${#command_descriptions[@]}]="Switch branches"
# -d, --delete - Delete a branch
command_vars[${#command_vars[@]}]="do_delete_branch"
command_options_show[${#command_options_show[@]}]="-d --delete"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]}"
command_descriptions[${#command_descriptions[@]}]="Delete a branch"
# -g, --guard - Launch Gaurd continuous testing
command_vars[${#command_vars[@]}]="do_start_guard"
command_options_show[${#command_options_show[@]}]="-g --guard"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]}"
command_descriptions[${#command_descriptions[@]}]="Launch Gaurd continuous testing"
# -e, --reset_db --reset-db - Delete and reset/recreate DBs
command_vars[${#command_vars[@]}]="do_reset_db"
command_options_show[${#command_options_show[@]}]="-e --reset_db"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]} --reset-db"
command_descriptions[${#command_descriptions[@]}]="Delete and reset/recreate DBs"
# -c, --console - Run the Rails console
command_vars[${#command_vars[@]}]="do_launch_console"
command_options_show[${#command_options_show[@]}]="-c --console"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]}"
command_descriptions[${#command_descriptions[@]}]="Run the Rails console"
# -r, --run - Run the application
command_vars[${#command_vars[@]}]="do_run_site"
command_options_show[${#command_options_show[@]}]="-r --run"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]}"
command_descriptions[${#command_descriptions[@]}]="Run the application"
# -v, --move - Move the current git directory out of the way
command_vars[${#command_vars[@]}]="do_move_site"
command_options_show[${#command_options_show[@]}]="-v --move"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]}"
command_descriptions[${#command_descriptions[@]}]="Move the current git directory out of the way"
# -l, --clone - Clone the repository
command_vars[${#command_vars[@]}]="do_clone"
command_options_show[${#command_options_show[@]}]="-l --clone"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]}"
command_descriptions[${#command_descriptions[@]}]="Clone the repository"
# -o, --production - Production Deployment
command_vars[${#command_vars[@]}]="do_production_deployment"
command_options_show[${#command_options_show[@]}]="-o --production"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]}"
command_descriptions[${#command_descriptions[@]}]="Production Deployment"
# --base_dir --base-dir - The base directory to work in
command_vars[${#command_vars[@]}]="set_base_dir base_dir_param"
command_options_show[${#command_options_show[@]}]="--base_dir"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]} --base-dir"
command_descriptions[${#command_descriptions[@]}]="The base directory to work in (the parent to ${project_base_name})"
# --rails_env --rails-env - The RAILS_ENV to use for build/deploy
command_vars[${#command_vars[@]}]="change_rails_env rails_env_param"
command_options_show[${#command_options_show[@]}]="--rails_env"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]} --rails-env"
command_descriptions[${#command_descriptions[@]}]="The RAILS_ENV to use for build/deploy"
# -y --deploy - Deploy the system to one of the known machines
command_vars[${#command_vars[@]}]="do_deploy"
command_options_show[${#command_options_show[@]}]="-y --deploy"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]}"
command_descriptions[${#command_descriptions[@]}]="Deploy the system to one of the known machines"
# --history - Show recent history
command_vars[${#command_vars[@]}]="do_show_history"
command_options_show[${#command_options_show[@]}]="--history"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]}"
command_descriptions[${#command_descriptions[@]}]="Show recent history"
# --stash_locks --stash-locks - Backup the Gemfile.lock files that are not checked in
command_vars[${#command_vars[@]}]="do_stash_lockfiles"
command_options_show[${#command_options_show[@]}]="--stash_locks"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]} --stash-locks"
command_descriptions[${#command_descriptions[@]}]="Backup the Gemfile.lock files that are not checked in"
# ---stash - Menuized version of git stash
command_vars[${#command_vars[@]}]="do_stash_menu"
command_options_show[${#command_options_show[@]}]="---stash"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]}"
command_descriptions[${#command_descriptions[@]}]="Menuized version of git stash"
# --stash - Stash the current branch
command_vars[${#command_vars[@]}]="do_stash_command"
command_options_show[${#command_options_show[@]}]="--stash"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]}"
command_descriptions[${#command_descriptions[@]}]="Stash the current branch"
# --drop_stash --drop-stash - Drop a stash
command_vars[${#command_vars[@]}]="do_stash_drop"
command_options_show[${#command_options_show[@]}]="--drop_stash"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]} --drop-stash"
command_descriptions[${#command_descriptions[@]}]="Drop a stash"
# --unstash - Apply a stash
command_vars[${#command_vars[@]}]="do_stash_unstash"
command_options_show[${#command_options_show[@]}]="--unstash"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]}"
command_descriptions[${#command_descriptions[@]}]="Apply a stash"
# --reset_git --reset-git - Do a hard reset
command_vars[${#command_vars[@]}]="do_git_reset"
command_options_show[${#command_options_show[@]}]="--reset_git"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]} --reset-git --reset"
command_descriptions[${#command_descriptions[@]}]="Do a hard reset"
# --smoke - Do a partial test of only running the ci:smoke.
command_vars[${#command_vars[@]}]="do_cucumber_smoke"
command_options_show[${#command_options_show[@]}]="--smoke"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]}"
command_descriptions[${#command_descriptions[@]}]="Do a partial test of only running the ci:smoke."
# ---test - Menuized testing options
command_vars[${#command_vars[@]}]="do_test_menu"
command_options_show[${#command_options_show[@]}]="---test"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]}"
command_descriptions[${#command_descriptions[@]}]="Menuized testing options"
# --test_params --test-params - Parameters for running the menuized tests in the form of "<test number>[:<line_number>]"
command_vars[${#command_vars[@]}]="use_menu_test_parameters menu_test_param_value"
command_options_show[${#command_options_show[@]}]="--test_params"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]} --test-params"
command_descriptions[${#command_descriptions[@]}]="Parameters for running the menuized tests in the form of \"<test number>[:<line_number>]\""
# --check-merge --check_merge - Uses git-status to validate/check/add and finally commit files with merge conflicts
command_vars[${#command_vars[@]}]="do_merge_validation"
command_options_show[${#command_options_show[@]}]="--check_merge"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]} --check-merge --merge-check --merge_check"
command_descriptions[${#command_descriptions[@]}]="Uses git-status to validate/check/add and finally commit files with merge conflicts"
# --db-dump --db_dump - Drop the test databases and recreate them to dump the schema into the schema.rb file.
command_vars[${#command_vars[@]}]="do_schema_recreate"
command_options_show[${#command_options_show[@]}]="--db_dump"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]} --db-dump"
command_descriptions[${#command_descriptions[@]}]="Drop the test databases and recreate them to dump the schema into the schema.rb file."
# --db-branch --db_branch - Configure wether or not the database is branched as well.
command_vars[${#command_vars[@]}]="do_database_branching"
command_options_show[${#command_options_show[@]}]="--db_branch"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]} --db-branch --branch-db --branch_db"
command_descriptions[${#command_descriptions[@]}]="Configure wether or not the database is branched as well."
# --clean - Do a clean of the git repository...
command_vars[${#command_vars[@]}]="do_database_clean"
command_options_show[${#command_options_show[@]}]="--clean"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]}"
command_descriptions[${#command_descriptions[@]}]="Do a clean of the git repository..."
# --patch - Create a patch file
command_vars[${#command_vars[@]}]="do_create_patch create_patch_file_name"
command_options_show[${#command_options_show[@]}]="--patch"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]}"
command_descriptions[${#command_descriptions[@]}]="Create a patch file"
# --apply-patch - Apply a patch to the current branch.
command_vars[${#command_vars[@]}]="do_apply_patch apply_patch_file_name"
command_options_show[${#command_options_show[@]}]="--apply"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]} --apply-patch"
command_descriptions[${#command_descriptions[@]}]="Apply a patch to the current branch."
# --list - List branches
command_vars[${#command_vars[@]}]="do_list_branches"
command_options_show[${#command_options_show[@]}]="--list"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]}"
command_descriptions[${#command_descriptions[@]}]="List branches"
# --reset-build-cache - Reset the cache of build information to force the bundle instal to run.
command_vars[${#command_vars[@]}]="do_reset_build_cache_files"
command_options_show[${#command_options_show[@]}]="--reset-build-cache"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]} --reset_build_cache"
command_descriptions[${#command_descriptions[@]}]="Reset the cache of build information to force the bundle instal to run."
# --smoke-params - Parameters to pass into the smoke
command_vars[${#command_vars[@]}]="do_set_smoke_params user_smoke_params"
command_options_show[${#command_options_show[@]}]="--smoke-params"
command_options[${#command_options[@]}]="${command_options_show[$((${#command_options_show[@]} - 1))]} --smoke_params"
command_descriptions[${#command_descriptions[@]}]="Parameters to pass into the smoke"
fi
}
function append_array_value
{
# This funciton appends the passed in value to an array.
#
# PARAMETERS:
# ${1} - array_append_var - The array variable to append to.
# ${2} - array_append_val - The value to append to the array.
array_append_var="${1}"
array_append_val="${2}"
# OK, I admit it, I don't really know why this line works exactly, but it does
# and I couldn't figure out something that would work the way I wanted it to
# so, I'm just leaving it as is.
#
# if you put "'s arond the line here, it breaks because the string may contain
# "s, which ends the string and breaks it.
# This line works because we have a string that we set using:
# '<string>'
# If <string> == <string 1>'<string 2>, it is changed to:
# '<string 1>'"'"'<string 2>' which is interpreted as the concatination of 3 strings
# which results in:
# <string 1>'<string 2>
array_append_val=${array_append_val//\'/\'\"\'\"\'}
eval ${array_append_var}[\${#${array_append_var}[@]}]="'${array_append_val}'"
}
function set_param_value
{
# This funciton sets the passed in value to a variable.
#
# PARAMETERS:
# ${1} - set_var - The array variable to append to.
# ${2} - set_val - The value to append to the array.
set_var="${1}"
set_val="${2}"
# OK, I admit it, I don't know why this line works exactly, but it does
# and I couldn't figure out something that would work the way I wanted it to
# so, I'm just leaving it as is.
# if you put "'s arond the line here, it breaks.
# set_val=${set_val//\"/\\\"}
set_val=${set_val//\'/\'\"\'\"\'}
eval ${set_var}="'${set_val}'"
}
function execute_command
{
# This executes a command and echos the output.
#
# NOTE: The value of success_return_var may not be accurate if the
# value of file_to_echo_to is set.
#
# If file_to_echo_to is used, you should parse the output
# to validate success.
#
# PARAMETERS:
# ${1} - command_to_execute - The command to execute
# ${2} - file_to_echo_to - A file to output the text into.
# ${3} - success_return_var - The variable to return the success/failure in
# ${4} - execute_text_return_var - The variable to return the text in
command_to_execute="${1}"
file_to_echo_to="${2}"
success_return_var="${3}"
execute_text_return_var="${4}"
if [ ! -z "${file_to_echo_to}" ]; then
echo "$(pwd) \$ ${command_to_execute}" 2>&1 | tee -a ${file_to_echo_to}
else
echo "$(pwd) \$ ${command_to_execute}"
fi
if [ ! -z "${file_to_echo_to}" ]; then
command_to_execute="${command_to_execute} 2>&1 | tee -a ${file_to_echo_to}"
fi
if [ ! -z "${execute_text_return_var}" ]; then
command_to_execute="execute_text=\$(${command_to_execute}"
if [ -z "${file_to_echo_to}" ]; then
command_to_execute="${command_to_execute} 2>&1"
fi
command_to_execute="${command_to_execute})"
fi
if [ ! -z "${success_return_var}" ]; then
set +e
fi
eval "${command_to_execute}"
execute_command_successful="${?}"
if [ ! -z "${success_return_var}" ]; then
set -e
fi
if [ ! -z "${execute_text_return_var}" ]; then
echo "${execute_text}"
fi
if [ ! -z "${success_return_var}" ]; then
set_param_value "${success_return_var}" "${execute_command_successful}"
fi
if [ ! -z "${execute_text_return_var}" ]; then
set_param_value "${execute_text_return_var}" "${execute_text}"
fi
}
function heroku_run
{
# This function executes heroku run for the passed in command.
# This allows for problems with fire-walls by checking if the initial
# run fails, and if so, does the run in an alternate form.
#
# PARAMETERS:
# ${1} - heroku_run_command - The command to run.
# ${2} - heroku_run_log_file - The log file to output information to.
heroku_run_command="${1}"
heroku_run_log_file="${2}"
heroku_run_success="1"
backup_outputs "${build_log_directory}" "single_heroku_deploy.txt" "1w" "7 days"
execute_command "heroku run ${heroku_run_command}" "${build_log_directory}/single_heroku_deploy.txt" heroku_run_success ""
cat ${build_log_directory}/single_heroku_deploy.txt >> ${heroku_run_log_file}
if [ "${heroku_run_success}" = "0" ]; then
if grep "Error connecting to process" ${build_log_directory}/single_heroku_deploy.txt; then
heroku_run_success="1"
fi
fi
if [ "${heroku_run_success}" != "0" ]; then
execute_command "heroku run:detached ${heroku_run_command}" "${build_log_directory}/single_heroku_deploy.txt" heroku_run_success heroku_run_text
cat ${build_log_directory}/single_heroku_deploy.txt >> ${heroku_run_log_file}
run_heroku_log=$(grep "Use \`heroku" ${build_log_directory}/single_heroku_deploy.txt)
split_line_on_char "${run_heroku_log}" "\`" run_heroku_ignore_text run_heroku_log
split_line_on_char "${run_heroku_log}" "\`" run_heroku_log run_heroku_ignore_text
heroku_prev_process_id="${run_heroku_log}"
while [ ! -z "${heroku_prev_process_id}" ]; do
heroku_process_id="${heroku_prev_process_id}"
split_line_on_char "${heroku_prev_process_id}" " " run_heroku_ignore_text heroku_prev_process_id
done
while heroku ps | grep "${heroku_process_id}"; do
sleep 1
done
execute_command "${run_heroku_log}" "" "" ""
fi
}
function yes_no_prompt
{
# This function presents the user with a y/n message and reads the response.
# The response is validated, and if blank either the user is re-prompted or
# a default value is used if supplied.
# This function will only return y or n.
#
# PARAMETERS:
# ${1} - yes_no_prompt_text
# ${2} - yes_no_default_value
# ${3} - yes_no_selected_value_var
yes_no_prompt_text="${1}"
yes_no_default_value="${2}"
yes_no_selected_value_var="${3}"
# default may only be y or n
if [ ! -z "${yes_no_default_value}" ]; then
if [ "${yes_no_default_value:0:1}" = "(" ]; then
yes_no_default_value=""
else
if [ "${yes_no_default_value:0:1}" = ")" ]; then
yes_no_default_value=""
fi
fi
fi
if [ ! -z "${yes_no_default_value}" ]; then
if [ "${yes_no_default_value:0:1}" = "Y" -o "${yes_no_default_value:0:1}" = "y" ]; then
yes_no_default_value="y"
else
if [ "${yes_no_default_value:0:1}" = "N" -o "${yes_no_default_value:0:1}" = "n" ]; then
yes_no_default_value="n"
else
yes_no_default_value=""
fi
fi
fi
yes_no_selected_val=""
format_line "${yes_no_prompt_text}" "" yes_no_prompt_text
while [ -z "${yes_no_selected_val}" ]; do
read -p "${yes_no_prompt_text}" yes_no_user_input
echo ""
if [ -z "${yes_no_user_input}" ]; then
yes_no_user_input="${yes_no_default_value}"
fi
if [ ! -z "${yes_no_user_input}" ]; then
if [ "${yes_no_user_input:0:1}" = "(" ]; then
yes_no_user_input="x"
fi
if [ "${yes_no_user_input:0:1}" = ")" ]; then
yes_no_user_input="x"
fi
fi
if [ ! -z "${yes_no_user_input}" ]; then
if [ "${yes_no_user_input:0:1}" = "Y" -o "${yes_no_user_input:0:1}" = "y" ]; then
yes_no_selected_val="y"
else
if [ "${yes_no_user_input:0:1}" = "N" -o "${yes_no_user_input:0:1}" = "n" ]; then
yes_no_selected_val="n"
fi
fi
fi
done
set_param_value "${yes_no_selected_value_var}" "${yes_no_selected_val}"
}
function update_origin_branch
{
# This function edits the .git/config file to change the
# "merge" for a branch from master to the branch of the same name
#
# This is so that when manual commands are executed not through the
# script, they will work as though through the script if something is
# dropped off...
#
# [branch "master"]
# remote = origin
# merge = refs/heads/master
#
# PARAMETERS:
# ${1} - update_local_name - The local branch name
# ${2} - update_remote_name - The remote branch name
# ${3} - orig_remote_branch_name - The name of the branch that this branch was created from.
cd ${build_base_directory}
update_local_name="${1}"
update_remote_name="${2}"
orig_remote_branch_name="${3}"
if [ -z "${orig_remote_branch_name}" ]; then
orig_remote_branch_name="master"
fi
orig_remote_branch_name="refs/heads/${orig_remote_branch_name}"
record_branch update_origin_branch_name
if [ -z "${update_local_name}" ]; then
update_local_name="${update_origin_branch_name}"
fi
if [ -z "${update_remote_name}" ]; then
get_origin_branch "${update_local_name}" "push" "true" update_remote_name
fi
set +e
merge_config="$(git config branch.${update_local_name}.merge)"
set -e
if [ "${merge_config}" = "${orig_remote_branch_name}" -o -z "${merge_config}" ]; then
execute_command "git config branch.${update_local_name}.merge \"refs/heads/${update_remote_name}\"" "" "" ""
fi
}
function get_origin_branch
{
# This function gets the origin branch for the specified branch.
# It does this by querying git with git remote show origin and if it
# cannot find th origin that way, it will guess and provide a default.
# The default is: origin/<branch_name>
#
# PARAMETERS:
# ${1} - find_origin_for_branch_name - The name of the branch we are querying on
# ${2} - origin_find_action - The action (pull/push) to look for the origin for
# ${3} - origin_find_allow_default - true/false if a default value may be returned
# ${4} - found_origin_name_var - The origin name that was found (if any)
find_origin_for_branch_name="${1}"
origin_find_action="${2}"
origin_find_allow_default="${3}"
found_origin_name_var="${4}"
# This code was from before I learned about git config branch.<branch>.[merge|push|pull]
# # Sample output:
# # * remote origin
# # Fetch URL: [email protected]:SageACT/s parrow.git
# # Push URL: [email protected]:SageACT/s parrow.git
# # HEAD branch: master
# # Remote branches:
# # B-03837-linkedin_basic_feed tracked
# # Local branches configured for 'git pull':
# # B-03837-linkedin_basic_feed merges with remote B-03837-linkedin_basic_feed
# # Local refs configured for 'git push':
# # B-03837-linkedin_basic_feed pushes to B-03837-linkedin_basic_feed (local out of date)
# set +e
# origin_information="$(git remote show origin)"
# origin_information_available="${?}"
# set -e
# if [ "${origin_information_available}" != "0" ]; then
# # Ideally we would support pull and push, but for efficiencies
# # I assume that push and pull will go to the same place, so I can
# # use cached information.
# origin_find_action="pull"
# origin_information="$(git remote show -n origin)"
# fi
# in_get_origin_section="false"
# get_remote_branch_name=""
# while read origin_info_line; do
# if [ "${in_get_origin_section}" = "true" ]; then
# if [ "${origin_info_line}" = "Local branches configured for 'git pull':" ]; then
# in_get_origin_section="false"
# else
# if [ "${origin_info_line}" = "Local refs configured for 'git push':" ]; then
# in_get_origin_section="false"
# fi
# fi
# fi
# if [ "${in_get_origin_section}" = "true" ]; then
# split_line_on_char "${origin_info_line:4}" " " get_origin_branch_name git_origin_merges_with
# if [ "${get_origin_branch_name}" = "${find_origin_for_branch_name}" ]; then
# ltrim_line "${git_origin_merges_with}" git_origin_merges_with
# if [ ${#git_origin_merges_with} -gt 10 ]; then
# if [ "${git_origin_merges_with:0:10}" = "pushes to " ]; then
# git_origin_merges_with="${git_origin_merges_with:10}"
# fi
# fi
# if [ ${#git_origin_merges_with} -gt 12 ]; then
# if [ "${git_origin_merges_with:0:12}" = "merges with " ]; then
# git_origin_merges_with="${git_origin_merges_with:12}"
# fi
# fi
# split_line_on_char "${git_origin_merges_with}" " " get_remote_branch_name remote_branch_status
# break
# fi
# fi
# if [ "${origin_info_line}" = "Local branches configured for 'git ${origin_find_action}':" ]; then
# in_get_origin_section="true"
# else
# if [ "${origin_info_line}" = "Local refs configured for 'git ${origin_find_action}':" ]; then
# in_get_origin_section="true"
# fi
# fi
# done <<< "${origin_information}"
set +e
get_remote_branch_name="$(git config branch.${find_origin_for_branch_name}.merge)"
set -e
if [ -z "${get_remote_branch_name}" ]; then
set +e
get_remote_branch_name="$(git config branch.${find_origin_for_branch_name}.${origin_find_action})"
set -e
fi
if [ ${#get_remote_branch_name} -gt 11 ]; then
if [ "${get_remote_branch_name:0:11}" = "refs/heads/" ]; then
get_remote_branch_name="${get_remote_branch_name:11}"
fi
fi
# We don't want to return master unless we are on the master branch.
if [ "${get_remote_branch_name}" = "master" ]; then
if [ "${find_origin_for_branch_name}" != "master" ]; then
get_remote_branch_name=""
fi
fi
if [ -z "${get_remote_branch_name}" ]; then
# couldn't find the remote by searching through git remote show origin.
# try looking at remote branches and find it there...
# If we find a properly named branch, assume the branch was created "badly"
# and the intent is to use the same named branch.
initialize_branch_information false true false
get_origin_branch_index=0
while [ ${get_origin_branch_index} -lt ${#branches[@]} ]; do
if [ "${branches[${get_origin_branch_index}]}" = "origin/${find_origin_for_branch_name}" ]; then
get_remote_branch_name="${branches[${get_origin_branch_index}]:7}"
break
fi
get_origin_branch_index=$((${get_origin_branch_index} + 1))
done
fi
if [ -z "${get_remote_branch_name}" ]; then
if [ "${origin_find_allow_default}" = "true" ]; then
get_remote_branch_name="${find_origin_for_branch_name}"
fi
fi
set_param_value "${found_origin_name_var}" "${get_remote_branch_name}"
}
function format_line
{
# This function wraps a line of text for nice output.
#
# PARAMETERS:
# ${1} - format_line_text - The line to format
# ${2} - format_indent_text - Prefix text to put in front of wrapped lines
# ${3} - formatted_line_var - The variable to return the formatted text
format_line_with_prefix "" "${1}" "${2}" "${3}"
}
function format_line_with_prefix
{
# This function wraps a line of text for nice output.
#
# PARAMETERS:
# ${1} - multi_format_line_prefix - The prefix to add to the first line.
# ${2} - multi_format_line_text - The line to format
# ${3} - multi_format_indent_text - Prefix text to put in front of wrapped lines
# ${4} - multi_formatted_line_var - The variable to return the formatted text
multi_format_line_prefix="${1}"
multi_format_line_text="${2}"
multi_format_indent_text="${3}"
multi_formatted_line_var="${4}"
declare -a lines_to_format
while [ ! -z "${multi_format_line_text}" ]; do
split_line_on_char "${multi_format_line_text}" "${return_line}" first_line_found multi_format_line_text
lines_to_format[${#lines_to_format[@]}]="${first_line_found}"
total_lines_to_format=$((${total_lines_to_format} - 1))
done
final_format_text=""
format_line_index=0
while [ ${format_line_index} -lt ${#lines_to_format[@]} ]; do
if [ ${#multi_format_line_prefix} -lt ${#lines_to_format[${format_line_index}]} ]; then
if [ "${multi_format_line_prefix}" = "${lines_to_format[${format_line_index}]:0:${#multi_format_line_prefix}}" ]; then
lines_to_format[${format_line_index}]="${lines_to_format[${format_line_index}]:${#multi_format_line_prefix}}"
fi
fi
format_single_line_with_prefix "${multi_format_line_prefix}" "${lines_to_format[${format_line_index}]}" "${multi_format_indent_text}" mutlit_line_sub_text
if [ ! -z "${final_format_text}" ]; then
final_format_text="${final_format_text}${return_line}"
fi
final_format_text="${final_format_text}${mutlit_line_sub_text}"
multi_format_line_prefix="${multi_format_indent_text}"
format_line_index=$((${format_line_index} + 1))
done
set_param_value "${multi_formatted_line_var}" "${final_format_text}"
}
function format_single_line_with_prefix
{
# This function wraps a line of text for nice output.
#
# PARAMETERS:
# ${1} - format_line_prefix - The prefix to add to the first line.
# ${2} - format_line_text - The line to format
# ${3} - format_indent_text - Prefix text to put in front of wrapped lines
# ${4} - formatted_line_var - The variable to return the formatted text
format_line_prefix="${1}"
format_line_text="${2}"
format_indent_text="${3}"
formatted_line_var="${4}"
formatted_output_line=""
max_line_width="$(tput cols)"
extra_line_text_len=${#format_line_prefix}
if [ ${max_line_width} -gt ${#format_indent_text} ]; then
while [ $((${max_line_width} - ${extra_line_text_len})) -lt ${#format_line_text} ]; do
# Search backwards for whitespace to break on.
last_pos=$((${max_line_width} - 1 - ${extra_line_text_len}))
while [ ${last_pos} -ge 0 ]; do
if [ "${format_line_text:${last_pos}:1}" = " " ]; then
break
fi
if [ "${format_line_text:${last_pos}:${#return_line}}" = "${return_line}" ]; then
break
fi
last_pos=$((${last_pos} - 1))
done
# if no whitespace found, try to break on / instead
if [ ${last_pos} -lt 0 ]; then
last_pos=$((${max_line_width} - 1 - ${extra_line_text_len}))
while [ ${last_pos} -ge 0 ]; do
if [ "${format_line_text:${last_pos}:1}" = "/" ]; then
break
fi
last_pos=$((${last_pos} - 1))
done
fi
# We're at the first whitespace location. Now go back to the fist non-whitespace
# character which is where we will actually break...
while [ ${last_pos} -ge 0 ]; do
if [ "${format_line_text:${last_pos}:1}" != " " ]; then
if [ "${format_line_text:${last_pos}:${#return_line}}" != "${return_line}" ]; then
break
fi
fi
last_pos=$((${last_pos} - 1))
done
# Go forward one character to the whitespace character
last_pos=$((${last_pos} + 1))
# if we cannot break on whitespace, go to the last character and just break mid-line.
if [ ${last_pos} -le 0 ]; then
last_pos=$((${max_line_width} - 1 - ${extra_line_text_len}))
fi
# Split the line with a return...
if [ ${last_pos} -gt 0 ]; then
if [ -z "${formatted_output_line}" ]; then
formatted_output_line="${format_line_prefix}"
else
formatted_output_line="${formatted_output_line}${return_line}${format_indent_text}"
fi
formatted_output_line="${formatted_output_line}${format_line_text:0:${last_pos}}"
fi
# Since we've split the line, strip out the whitespace where we split...
while [ ${last_pos} -lt ${#format_line_text} ]; do
if [ "${format_line_text:${last_pos}:1}" != " " ]; then
if [ "${format_line_text:${last_pos}:${#return_line}}" != "${return_line}" ]; then
break
else
# if after the newline is 2 or more spaces, just break here and assume that the
# text is pre-formatted for output...
if [ $((${last_pos} + ${#format_indent_text})) -lt ${#format_line_text} ]; then
if [ "${format_line_text:${last_pos} + 1:${#format_indent_text}}" = "${format_indent_text}" ]; then
last_pos=$((${last_pos} + ${#format_indent_text} + 1))
break
fi
fi
fi
fi
last_pos=$((${last_pos} + 1))
done
# Now we've split and stripped, format the rest of the line...
if [ ${last_pos} -lt ${#format_line_text} ]; then
format_line_text="${format_line_text:${last_pos}}"
else
format_line_text=""
fi
extra_line_text_len=${#format_indent_text}
done
# If there is any more text left over, add it to the last line.
if [ ! -z "${format_line_text}" ]; then
if [ -z "${formatted_output_line}" ]; then
formatted_output_line="${format_line_prefix}"
else
formatted_output_line="${formatted_output_line}${return_line}${format_indent_text}"
fi
formatted_output_line="${formatted_output_line}${format_line_text}"
fi
else
formatted_output_line="${format_line_text}"
fi
set_param_value "${formatted_line_var}" "${formatted_output_line}"
}
function format_line_for_menu
{
# This function is a simplistic funtion for formatting a menu item selection
#
# PARAMETERS:
# ${1} - menu_format_line_number - The number of the line.