app_up 0.0.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +3 -0
- data/README.md +2 -31
- data/bin/app_up +22 -9
- data/bin/git_up +14 -0
- data/lib/app_up/configuration/config.rb +13 -0
- data/lib/app_up/configuration/loader.rb +21 -0
- data/lib/app_up/hooks/loader.rb +14 -0
- data/lib/app_up/hooks/rails_up.rb +11 -5
- data/lib/app_up/hooks/runner.rb +18 -0
- data/lib/app_up/repo.rb +9 -2
- data/lib/app_up/shell/color.rb +26 -0
- data/lib/app_up/shell/runner.rb +78 -0
- data/lib/app_up/utils/path.rb +32 -0
- data/lib/app_up/version.rb +1 -1
- data/lib/app_up.rb +9 -5
- data/test/git_up/hooks/rails_up_test.rb +22 -20
- data/test/test_helper.rb +0 -1
- metadata +9 -5
- data/lib/app_up/hook_loader.rb +0 -12
- data/lib/app_up/hook_runner.rb +0 -16
- data/lib/app_up/shell_runner.rb +0 -99
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6264df18b90b7334a402f1014f216dff432adcf
|
4
|
+
data.tar.gz: 8fe5a3b5832b6b28dc25e2e5603da299de8108e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 746d761c3b042190eae0047be9d768df94e0347d07e4ac1afc84a4c74b4672ec3cee10bee1f95d7b8d04178b9a90fb13b5b2b9e8e25f91838ef17482ba6592ae
|
7
|
+
data.tar.gz: 79bef96bf3eb9f891298604e4c5044f68cb1115b3d12cc8dc9a15b38f8320eabb41ac2fca49b52d78e69a958707fd1f2da213f39dc016d817de3be2ac936f1a9
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,31 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
TODO: Write a gem description
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
gem 'app_up'
|
11
|
-
```
|
12
|
-
|
13
|
-
And then execute:
|
14
|
-
|
15
|
-
$ bundle
|
16
|
-
|
17
|
-
Or install it yourself as:
|
18
|
-
|
19
|
-
$ gem install git_up
|
20
|
-
|
21
|
-
## Usage
|
22
|
-
|
23
|
-
TODO: Write usage instructions here
|
24
|
-
|
25
|
-
## Contributing
|
26
|
-
|
27
|
-
1. Fork it ( https://github.com/[my-github-username]/git_up/fork )
|
28
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
-
5. Create a new Pull Request
|
1
|
+
Todo:
|
2
|
+
this
|
data/bin/app_up
CHANGED
@@ -1,24 +1,37 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'thor'
|
4
|
-
|
4
|
+
require 'app_up'
|
5
5
|
|
6
6
|
class AppUpCLI < Thor
|
7
7
|
|
8
|
-
desc :
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
desc :run_hooks, %{Run "app_up --help run_hooks" to learn more}
|
9
|
+
long_desc <<-DESC
|
10
|
+
app_up automatically run "bundle install" and "rake db:migrate" in your app. It decides what to do based on the options listed above.
|
11
|
+
|
12
|
+
The AppUp gem installs two executables: "app_up" and "git_up". It is often more convenient to use the "git_up" command, which itself calls this "app_up" executable.
|
13
|
+
DESC
|
14
|
+
|
15
|
+
option :diff, type: :array, desc: %{Provide Git SHAs to be diffed. e.g. "app_up --diff HEAD d3be822a". If only one SHA is given, the second will default to HEAD.}
|
16
|
+
option :all, type: :boolean, desc: %{Run all hooks without diffing anything. This is the default action.}
|
17
|
+
option :verbose, type: :boolean, desc: %{Show the commands being run}
|
18
|
+
option :db_reset, aliases: ['--reset', '--drop-dbs'], type: :boolean, desc: %{Drop databases before creating and migrating}
|
13
19
|
|
14
20
|
def run_hooks
|
15
|
-
shell = AppUp::
|
21
|
+
shell = AppUp::Shell::Runner.new(
|
16
22
|
log_path: '/tmp/app_up.log',
|
17
|
-
working_directory: '.'
|
23
|
+
working_directory: '.',
|
24
|
+
verbose: options[:verbose],
|
18
25
|
)
|
19
26
|
|
27
|
+
if !options.has_key?(:diff)
|
28
|
+
options[:all] = true
|
29
|
+
elsif options[:diff].size == 1
|
30
|
+
options[:diff] << "HEAD"
|
31
|
+
end
|
32
|
+
|
20
33
|
files = AppUp::Repo.new(shell, options).files
|
21
|
-
AppUp::
|
34
|
+
AppUp::Hooks::Runner.new(shell, files, options).run
|
22
35
|
end
|
23
36
|
|
24
37
|
default_task :run_hooks
|
data/bin/git_up
CHANGED
@@ -1,6 +1,20 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
#PETE: make this a bash script
|
4
|
+
if ARGV[0] == "--help" || ARGV[0] == "-h"
|
5
|
+
puts <<-HELP
|
6
|
+
---
|
7
|
+
git_up is a wrapper for git. It compares the starting SHA and ending SHA of a git action and will run hooks to bundle and migrate your application.
|
8
|
+
|
9
|
+
You can pass git_up any git command. e.g. "git_up pull origin master"
|
10
|
+
|
11
|
+
If you pass no arguments, git_up will default to calling "git_up pull --rebase origin master"
|
12
|
+
|
13
|
+
See "app_up --help run_hooks" to see how the bundle/migration works.
|
14
|
+
---
|
15
|
+
HELP
|
16
|
+
exit
|
17
|
+
end
|
4
18
|
|
5
19
|
def get_sha
|
6
20
|
%x{git rev-parse HEAD}.chomp
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "app_up/configuration/config"
|
2
|
+
|
3
|
+
module AppUp
|
4
|
+
module Configuration
|
5
|
+
module Loader
|
6
|
+
|
7
|
+
def user_config(config_class: Config, filename:)
|
8
|
+
|
9
|
+
self.singleton_class.send(:define_method, :config) do |&config_block|
|
10
|
+
config_block.call(config_class)
|
11
|
+
end
|
12
|
+
|
13
|
+
home = File.expand_path("~")
|
14
|
+
config_file = File.join(home, filename)
|
15
|
+
if File.exists?(config_file)
|
16
|
+
load config_file
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -14,12 +14,18 @@ module AppUp
|
|
14
14
|
shell.notify( "Running RailsUp\n----------")
|
15
15
|
|
16
16
|
files.each do |file|
|
17
|
-
|
18
|
-
|
17
|
+
exploded_path = Utils::Path.split(file)
|
18
|
+
|
19
|
+
# allow rebundle on only Gemfile edit, in case you're
|
20
|
+
# upping a gem, which probably doesn't have the Gemfile.lock
|
21
|
+
# checked in
|
22
|
+
if exploded_path.last.match(/Gemfile(\.lock)?|gemspec$/)
|
23
|
+
add_command(:bundle, dir: exploded_path[0..-2])
|
19
24
|
end
|
20
25
|
|
21
|
-
if
|
22
|
-
|
26
|
+
if exploded_path.include?("migrate")
|
27
|
+
last_db_index = exploded_path.rindex("db")
|
28
|
+
add_command(:migrate, dir: exploded_path[0...last_db_index])
|
23
29
|
end
|
24
30
|
end
|
25
31
|
|
@@ -47,7 +53,7 @@ module AppUp
|
|
47
53
|
}
|
48
54
|
|
49
55
|
actions.each do |command|
|
50
|
-
shell.enqueue(:notify, "#{i.to_s.rjust(command_count.length)}/#{command_count.to_s} #{command.to_s.ljust(7)} : #{dir}")
|
56
|
+
shell.enqueue(:notify, "#{i.to_s.rjust(command_count.length)}/#{command_count.to_s} #{command.to_s.ljust(7)} : #{Utils::Path.join(dir)}")
|
51
57
|
i+=1
|
52
58
|
end
|
53
59
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "app_up/hooks/loader"
|
2
|
+
|
3
|
+
module AppUp
|
4
|
+
module Hooks
|
5
|
+
class Runner < Struct.new(:shell, :files, :options)
|
6
|
+
|
7
|
+
def run
|
8
|
+
hooks = Hooks::Loader.load
|
9
|
+
|
10
|
+
hooks.each do |hook|
|
11
|
+
hook.run(shell, files, options)
|
12
|
+
end
|
13
|
+
|
14
|
+
shell.flush
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/app_up/repo.rb
CHANGED
@@ -1,7 +1,16 @@
|
|
1
1
|
module AppUp
|
2
2
|
class Repo < Struct.new(:shell, :options)
|
3
3
|
|
4
|
+
private :shell, :options
|
5
|
+
|
4
6
|
def files
|
7
|
+
ignores = options.has_key?(:ingore) ? options[:ignore] : Configuration::Config.ignore
|
8
|
+
default_files.reject {|f| ignores.any? {|i| f.match(i)} }
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def default_files
|
5
14
|
if options[:diff]
|
6
15
|
diff(*options[:diff])
|
7
16
|
else
|
@@ -9,8 +18,6 @@ module AppUp
|
|
9
18
|
end
|
10
19
|
end
|
11
20
|
|
12
|
-
private
|
13
|
-
|
14
21
|
def all
|
15
22
|
shell.run "git ls-tree --full-tree -r HEAD --name-only"
|
16
23
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module AppUp
|
2
|
+
module Shell
|
3
|
+
module Color
|
4
|
+
CODES = {
|
5
|
+
red: 31,
|
6
|
+
green: 32,
|
7
|
+
yellow: 33,
|
8
|
+
pink: 35,
|
9
|
+
}.freeze
|
10
|
+
|
11
|
+
CODES.each do |color, code|
|
12
|
+
self.send(:define_method, color) do |string|
|
13
|
+
colorize(string, code)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
# colorization
|
20
|
+
def colorize(string, color_code)
|
21
|
+
"\e[#{color_code}m#{string}\e[0m"
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require "work_queue"
|
2
|
+
require "app_up/shell/color"
|
3
|
+
|
4
|
+
module AppUp
|
5
|
+
module Shell
|
6
|
+
class Runner
|
7
|
+
include Color
|
8
|
+
|
9
|
+
MAX_PROCESS_COUNT = 8
|
10
|
+
CommandFailureError = Class.new(StandardError)
|
11
|
+
|
12
|
+
attr_accessor :working_directory, :log_path, :queue
|
13
|
+
private :working_directory, :log_path, :queue
|
14
|
+
|
15
|
+
def initialize(log_path:, working_directory:, verbose: false)
|
16
|
+
@working_directory = working_directory
|
17
|
+
@log_path = log_path
|
18
|
+
@verbose = verbose
|
19
|
+
|
20
|
+
@queue = WorkQueue.new(MAX_PROCESS_COUNT, nil)
|
21
|
+
|
22
|
+
%x{echo "" > #{log_path}}
|
23
|
+
Dir.chdir(%x[ git rev-parse --show-toplevel ].chomp)
|
24
|
+
end
|
25
|
+
|
26
|
+
# The block passed to run is a callback. It is used
|
27
|
+
# to add a dependent command to the queue.
|
28
|
+
def run(cmd, dir: working_directory, &block)
|
29
|
+
command = "cd #{Utils::Path.relative_join(dir)} && #{cmd}"
|
30
|
+
handle_output_for(command)
|
31
|
+
|
32
|
+
shell_out(command).split("\n").tap do
|
33
|
+
block.call if block_given?
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def warn(msg)
|
38
|
+
log msg.to_s
|
39
|
+
print "#{red(msg.to_s)}\n"
|
40
|
+
end
|
41
|
+
|
42
|
+
def notify(msg)
|
43
|
+
return if @verbose
|
44
|
+
|
45
|
+
log msg.to_s
|
46
|
+
print "#{yellow(msg.to_s)}\n"
|
47
|
+
end
|
48
|
+
|
49
|
+
def enqueue(method, *args, &block)
|
50
|
+
queue.enqueue_b do
|
51
|
+
send(method, *args, &block)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def flush
|
56
|
+
queue.join
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def log(msg)
|
62
|
+
%x{echo "#{msg.to_s}" >> #{log_path}}
|
63
|
+
end
|
64
|
+
|
65
|
+
def handle_output_for(cmd)
|
66
|
+
puts cmd if @verbose
|
67
|
+
log(cmd)
|
68
|
+
end
|
69
|
+
|
70
|
+
def shell_out(command)
|
71
|
+
%x{ set -o pipefail && #{command} 2>> #{log_path} | tee -a #{log_path} }.chomp.tap do
|
72
|
+
warn "The following command has failed: #{command}. See #{log_path} for a full log." if ($?.exitstatus != 0)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
3
|
+
module AppUp
|
4
|
+
module Utils
|
5
|
+
module Path
|
6
|
+
|
7
|
+
def self.split(filename)
|
8
|
+
self.prepend_pwd(Pathname.new(filename).each_filename.to_a)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.path_for(filename)
|
12
|
+
self.split(File.split(file)[0])
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.join(*array)
|
16
|
+
File.join(*array)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.prepend_pwd(dirs)
|
20
|
+
if dirs[0] == "."
|
21
|
+
dirs
|
22
|
+
else
|
23
|
+
["."] + dirs
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.relative_join(array)
|
28
|
+
join(prepend_pwd(array))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/app_up/version.rb
CHANGED
data/lib/app_up.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
require "app_up/version"
|
2
|
+
require "app_up/utils/path"
|
3
|
+
require "app_up/hooks/runner"
|
4
|
+
require "app_up/repo"
|
5
|
+
require "app_up/shell/runner"
|
6
|
+
require "app_up/configuration/loader"
|
5
7
|
|
6
8
|
module AppUp
|
7
|
-
|
9
|
+
extend Configuration::Loader
|
10
|
+
|
11
|
+
user_config filename: ".app_up"
|
8
12
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "test_helper"
|
2
2
|
|
3
3
|
module AppUp
|
4
4
|
module Hooks
|
@@ -31,44 +31,46 @@ module AppUp
|
|
31
31
|
|
32
32
|
def test_bundle_directories
|
33
33
|
files = [
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
"folder/sub_folder/Gemfile",
|
35
|
+
"other_folder/other_subfolder/more/Gemfile.lock",
|
36
|
+
"some_gem/thing/thing.gemspec",
|
37
|
+
"unused/Gemthingspec",
|
37
38
|
]
|
38
39
|
|
39
40
|
hook = RailsUp.new(@shell, files, {})
|
40
41
|
|
41
42
|
hook.run
|
42
|
-
assert_equal
|
43
|
-
assert @shell.history[:enqueue].include?([:run, RailsUp::BUNDLE_COMMAND, dir:
|
44
|
-
assert @shell.history[:enqueue].include?([:run, RailsUp::BUNDLE_COMMAND, dir:
|
43
|
+
assert_equal 3, @shell.history[:enqueue].select {|c| c[0]==:run}.size
|
44
|
+
assert @shell.history[:enqueue].include?([:run, RailsUp::BUNDLE_COMMAND, dir: [".", "folder", "sub_folder"]]), @shell.history
|
45
|
+
assert @shell.history[:enqueue].include?([:run, RailsUp::BUNDLE_COMMAND, dir: [".", "other_folder", "other_subfolder", "more"]]), @shell.history
|
46
|
+
assert @shell.history[:enqueue].include?([:run, RailsUp::BUNDLE_COMMAND, dir: [".", "some_gem", "thing"]]), @shell.history
|
45
47
|
end
|
46
48
|
|
47
49
|
def test_migrate_directories
|
48
50
|
files = [
|
49
|
-
|
50
|
-
|
51
|
-
|
51
|
+
"folder/sub_folder/db/migrate/migration.rb",
|
52
|
+
"other_folder/other_subfolder/more/db/migrate/migration.rb",
|
53
|
+
"unused/db/config.rb",
|
52
54
|
]
|
53
55
|
|
54
56
|
hook = RailsUp.new(@shell, files, {})
|
55
|
-
hook.stubs(:migrate).with(
|
56
|
-
hook.stubs(:migrate).with(
|
57
|
+
hook.stubs(:migrate).with("test").returns("migrate_test")
|
58
|
+
hook.stubs(:migrate).with("development").returns("migrate_development")
|
57
59
|
|
58
60
|
hook.run
|
59
61
|
assert_equal 4, @shell.history[:enqueue].select {|c| c[0]==:run}.size
|
60
|
-
assert @shell.history[:enqueue].include?([:run,
|
61
|
-
assert @shell.history[:enqueue].include?([:run,
|
62
|
-
assert @shell.history[:enqueue].include?([:run,
|
63
|
-
assert @shell.history[:enqueue].include?([:run,
|
62
|
+
assert @shell.history[:enqueue].include?([:run, "migrate_test", dir: [".", "folder", "sub_folder"]]), @shell.history
|
63
|
+
assert @shell.history[:enqueue].include?([:run, "migrate_development", dir: [".", "folder", "sub_folder"]]), @shell.history
|
64
|
+
assert @shell.history[:enqueue].include?([:run, "migrate_test", dir: [".", "other_folder", "other_subfolder", "more"]]), @shell.history
|
65
|
+
assert @shell.history[:enqueue].include?([:run, "migrate_development", dir: [".", "other_folder", "other_subfolder", "more"]]), @shell.history
|
64
66
|
end
|
65
67
|
|
66
68
|
def test_migrate__drops_db
|
67
|
-
no_drop_hook = RailsUp.new(
|
68
|
-
assert_equal nil, no_drop_hook.send(:migrate,
|
69
|
+
no_drop_hook = RailsUp.new("stub", "stub", {})
|
70
|
+
assert_equal nil, no_drop_hook.send(:migrate, "test").match(/db:drop/)
|
69
71
|
|
70
|
-
no_drop_hook = RailsUp.new(
|
71
|
-
assert no_drop_hook.send(:migrate,
|
72
|
+
no_drop_hook = RailsUp.new("stub", "stub", {db_reset: true})
|
73
|
+
assert no_drop_hook.send(:migrate, "test").match(/db:drop/)
|
72
74
|
end
|
73
75
|
end
|
74
76
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: app_up
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pete Kinnecom
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -96,12 +96,16 @@ files:
|
|
96
96
|
- bin/app_up
|
97
97
|
- bin/git_up
|
98
98
|
- lib/app_up.rb
|
99
|
-
- lib/app_up/
|
100
|
-
- lib/app_up/
|
99
|
+
- lib/app_up/configuration/config.rb
|
100
|
+
- lib/app_up/configuration/loader.rb
|
101
101
|
- lib/app_up/hooks/hook.rb
|
102
|
+
- lib/app_up/hooks/loader.rb
|
102
103
|
- lib/app_up/hooks/rails_up.rb
|
104
|
+
- lib/app_up/hooks/runner.rb
|
103
105
|
- lib/app_up/repo.rb
|
104
|
-
- lib/app_up/
|
106
|
+
- lib/app_up/shell/color.rb
|
107
|
+
- lib/app_up/shell/runner.rb
|
108
|
+
- lib/app_up/utils/path.rb
|
105
109
|
- lib/app_up/version.rb
|
106
110
|
- test/git_up/hooks/rails_up_test.rb
|
107
111
|
- test/test_helper.rb
|
data/lib/app_up/hook_loader.rb
DELETED
data/lib/app_up/hook_runner.rb
DELETED
data/lib/app_up/shell_runner.rb
DELETED
@@ -1,99 +0,0 @@
|
|
1
|
-
require 'work_queue'
|
2
|
-
|
3
|
-
module AppUp
|
4
|
-
class ShellRunner
|
5
|
-
MAX_PROCESS_COUNT = 8
|
6
|
-
CommandFailureError = Class.new(StandardError)
|
7
|
-
|
8
|
-
attr_accessor :working_directory, :log_path, :queue
|
9
|
-
private :working_directory, :log_path, :queue
|
10
|
-
|
11
|
-
def initialize(log_path:, working_directory:, verbose: false)
|
12
|
-
@working_directory = working_directory
|
13
|
-
@log_path = log_path
|
14
|
-
@queue = WorkQueue.new(MAX_PROCESS_COUNT, nil)
|
15
|
-
@verbose = verbose
|
16
|
-
Dir.chdir(%x[ git rev-parse --show-toplevel ].chomp)
|
17
|
-
|
18
|
-
reset_log
|
19
|
-
end
|
20
|
-
|
21
|
-
# The block passed to run is a callback. It is used
|
22
|
-
# to add a dependent command to the queue.
|
23
|
-
def run(cmd, dir: working_directory, &block)
|
24
|
-
command = "cd #{dir} && #{cmd}"
|
25
|
-
handle_output_for(command)
|
26
|
-
|
27
|
-
shell_out(command).split("\n").tap do
|
28
|
-
block.call if block_given?
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def warn(msg)
|
33
|
-
log msg.to_s
|
34
|
-
print "#{msg.to_s.red}\n"
|
35
|
-
end
|
36
|
-
|
37
|
-
def notify(msg)
|
38
|
-
log msg.to_s
|
39
|
-
print "#{msg.to_s.yellow}\n"
|
40
|
-
end
|
41
|
-
|
42
|
-
def enqueue(method, *args, &block)
|
43
|
-
queue.enqueue_b do
|
44
|
-
send(method, *args, &block)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def flush
|
49
|
-
queue.join
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
53
|
-
|
54
|
-
def log(msg)
|
55
|
-
%x{echo "#{msg.to_s}" >> #{log_path}}
|
56
|
-
end
|
57
|
-
|
58
|
-
def reset_log
|
59
|
-
%x{echo "" > #{log_path}}
|
60
|
-
end
|
61
|
-
|
62
|
-
def handle_output_for(cmd)
|
63
|
-
puts cmd if @verbose
|
64
|
-
log(cmd)
|
65
|
-
end
|
66
|
-
|
67
|
-
def shell_out(command)
|
68
|
-
%x{ set -o pipefail && #{command} 2>> #{log_path} | tee -a #{log_path} }.chomp.tap do
|
69
|
-
warn "The following command has failed: #{command}. See #{log_path} for a full log." if ($?.exitstatus != 0)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
#PETE: hack
|
77
|
-
|
78
|
-
class String
|
79
|
-
# colorization
|
80
|
-
def colorize(color_code)
|
81
|
-
"\e[#{color_code}m#{self}\e[0m"
|
82
|
-
end
|
83
|
-
|
84
|
-
def red
|
85
|
-
colorize(31)
|
86
|
-
end
|
87
|
-
|
88
|
-
def green
|
89
|
-
colorize(32)
|
90
|
-
end
|
91
|
-
|
92
|
-
def yellow
|
93
|
-
colorize(33)
|
94
|
-
end
|
95
|
-
|
96
|
-
def pink
|
97
|
-
colorize(35)
|
98
|
-
end
|
99
|
-
end
|