boxen 2.9.0 → 3.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/boxen.gemspec +12 -12
- data/lib/boxen/check.rb +8 -39
- data/lib/boxen/cli.rb +19 -45
- data/lib/boxen/command.rb +142 -0
- data/lib/boxen/command/help.rb +40 -0
- data/lib/boxen/command/preflight.rb +38 -0
- data/lib/boxen/command/project.rb +49 -0
- data/lib/boxen/command/project/install.rb +33 -0
- data/lib/boxen/command/run.rb +199 -0
- data/lib/boxen/command/service.rb +61 -0
- data/lib/boxen/command/service/disable.rb +15 -0
- data/lib/boxen/command/service/enable.rb +15 -0
- data/lib/boxen/command/service/restart.rb +24 -0
- data/lib/boxen/command/version.rb +29 -0
- data/lib/boxen/command_status.rb +15 -0
- data/lib/boxen/config.rb +43 -61
- data/lib/boxen/hook.rb +15 -8
- data/lib/boxen/keychain.rb +1 -1
- data/lib/boxen/postflight/env.rb +1 -1
- data/lib/boxen/postflight/github_issue.rb +124 -0
- data/lib/boxen/postflight/hooks.rb +16 -0
- data/lib/boxen/postflight/web_hook.rb +63 -0
- data/lib/boxen/preflight.rb +4 -7
- data/lib/boxen/preflight/creds.rb +8 -47
- data/lib/boxen/preflight/facts.rb +36 -0
- data/lib/boxen/preflight/homebrew.rb +13 -0
- data/lib/boxen/preflight/identity.rb +2 -0
- data/lib/boxen/preflight/offline.rb +33 -0
- data/lib/boxen/preflight/os.rb +1 -1
- data/lib/boxen/preflight/update.rb +109 -0
- data/lib/boxen/util/logging.rb +59 -0
- data/lib/boxen/version.rb +3 -0
- data/script/bootstrap +1 -1
- data/script/tests +1 -0
- data/test/boxen/test.rb +1 -1
- data/test/boxen_cli_test.rb +8 -31
- data/test/boxen_command_test.rb +93 -0
- data/test/boxen_config_test.rb +1 -31
- data/test/boxen_directories_test.rb +4 -4
- data/test/boxen_hook_test.rb +25 -0
- data/test/command/help_test.rb +49 -0
- data/test/command/project/install_test.rb +34 -0
- data/test/command/project_test.rb +32 -0
- data/test/command/run_test.rb +21 -0
- data/test/command/service/disable_test.rb +49 -0
- data/test/command/service/enable_test.rb +49 -0
- data/test/command/service/restart_test.rb +53 -0
- data/test/command/service_test.rb +55 -0
- data/test/command/version_test.rb +15 -0
- data/test/{boxen_postflight_active_test.rb → postflight/boxen_postflight_active_test.rb} +3 -3
- data/test/{boxen_postflight_env_test.rb → postflight/boxen_postflight_env_test.rb} +0 -0
- data/test/{boxen_hook_github_issue_test.rb → postflight/boxen_postflight_github_issue_test.rb} +72 -82
- data/test/{boxen_hook_web_test.rb → postflight/boxen_postflight_web_hook_test.rb} +12 -11
- data/test/preflight/boxen_preflight_creds_test.rb +82 -0
- data/test/{boxen_preflight_etc_my_cnf_test.rb → preflight/boxen_preflight_etc_my_cnf_test.rb} +1 -1
- data/test/preflight/boxen_preflight_homebrew_test.rb +10 -0
- data/test/{boxen_preflight_rvm_test.rb → preflight/boxen_preflight_rvm_test.rb} +1 -1
- metadata +247 -171
- checksums.yaml +0 -7
- data/lib/boxen/flags.rb +0 -282
- data/lib/boxen/hook/github_issue.rb +0 -120
- data/lib/boxen/hook/web.rb +0 -56
- data/lib/boxen/puppeteer.rb +0 -121
- data/lib/boxen/runner.rb +0 -149
- data/test/boxen_check_test.rb +0 -55
- data/test/boxen_flags_test.rb +0 -217
- data/test/boxen_preflight_creds_test.rb +0 -177
- data/test/boxen_puppeteer_test.rb +0 -101
- data/test/boxen_runner_test.rb +0 -171
data/lib/boxen/preflight/os.rb
CHANGED
@@ -0,0 +1,109 @@
|
|
1
|
+
require "boxen/preflight"
|
2
|
+
|
3
|
+
class Boxen::Preflight::Update < Boxen::Preflight
|
4
|
+
def ok?
|
5
|
+
if config.offline?
|
6
|
+
warn "Skipping update because we're offline."
|
7
|
+
|
8
|
+
elsif no_pull?
|
9
|
+
debug "Skipping update because we were asked to by the --no-pull flag"
|
10
|
+
|
11
|
+
elsif !on_branch?
|
12
|
+
warn "Boxen not on a branch (ref: #{ref}), cannot update!"
|
13
|
+
|
14
|
+
elsif !on_master_branch?
|
15
|
+
local_branch = current_branch.rpartition("/").last
|
16
|
+
warn "Boxen on a non-master branch '#{local_branch}', cannot update!"
|
17
|
+
|
18
|
+
elsif !fast_forwardable?
|
19
|
+
warn "Boxen has unpushed changes, cannot update!"
|
20
|
+
|
21
|
+
elsif !clean_tree?
|
22
|
+
warn "Boxen repo has untracked or uncommitted changes, cannot update!"
|
23
|
+
|
24
|
+
else
|
25
|
+
update!
|
26
|
+
end
|
27
|
+
|
28
|
+
true
|
29
|
+
end
|
30
|
+
|
31
|
+
def run
|
32
|
+
abort "Auto-update of Boxen FAILED, please fix manually."
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def ref
|
38
|
+
%x(git log -1 --pretty=format:%h)
|
39
|
+
end
|
40
|
+
|
41
|
+
def fetch
|
42
|
+
"git fetch --quiet origin"
|
43
|
+
end
|
44
|
+
|
45
|
+
def reset_hard
|
46
|
+
"git reset --hard origin/master 2>&1 >/dev/null"
|
47
|
+
end
|
48
|
+
|
49
|
+
def clean
|
50
|
+
"git clean -qdf"
|
51
|
+
end
|
52
|
+
|
53
|
+
def update_boxen_checkout
|
54
|
+
%x(#{reset} && #{clean})
|
55
|
+
$? == 0
|
56
|
+
end
|
57
|
+
|
58
|
+
def on_branch?
|
59
|
+
!current_branch.empty?
|
60
|
+
end
|
61
|
+
|
62
|
+
def on_master_branch?
|
63
|
+
current_branch == "refs/heads/master"
|
64
|
+
end
|
65
|
+
|
66
|
+
def clean_tree?
|
67
|
+
%x(git status --porcelain).chomp.empty?
|
68
|
+
end
|
69
|
+
|
70
|
+
def upstream_changes?
|
71
|
+
%x(git rev-list --count HEAD..origin/master).chomp != "0"
|
72
|
+
end
|
73
|
+
|
74
|
+
def no_pull?
|
75
|
+
ARGV.any? { |arg| arg == "--no-pull" }
|
76
|
+
end
|
77
|
+
|
78
|
+
def fast_forwardable?
|
79
|
+
%x(git rev-list --count origin/master..master).chomp == "0"
|
80
|
+
end
|
81
|
+
|
82
|
+
def current_branch
|
83
|
+
@current_branch ||= %x(git symbolic-ref HEAD).chomp
|
84
|
+
end
|
85
|
+
|
86
|
+
def update!
|
87
|
+
info "Updating boxen..."
|
88
|
+
fetch
|
89
|
+
|
90
|
+
if !upstream_changes?
|
91
|
+
info "Boxen is up-to-date with origin/master"
|
92
|
+
|
93
|
+
elsif update_boxen_checkout
|
94
|
+
info "Successfully updated to #{ref}"
|
95
|
+
rerun_boxen
|
96
|
+
|
97
|
+
else
|
98
|
+
warn "Failed to auto-update!"
|
99
|
+
false
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def rerun_boxen
|
104
|
+
command = "#{$0} #{ARGV.join ' '} --no-pull"
|
105
|
+
debug "Re-running boxen:"
|
106
|
+
debug " #{command.inspect}"
|
107
|
+
exec command
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require "ansi"
|
2
|
+
|
3
|
+
module Boxen
|
4
|
+
module Util
|
5
|
+
module Logging
|
6
|
+
|
7
|
+
# A fancier `abort` and `warn`. This will probably really annoy
|
8
|
+
# someone at some point because it's overriding a Kernel method,
|
9
|
+
# but it's limited to checks.
|
10
|
+
|
11
|
+
alias :fail :abort
|
12
|
+
|
13
|
+
def abort(message, *extras)
|
14
|
+
extras << { :color => :red, :stream => $stderr }
|
15
|
+
log "FAIL: #{message}", *extras
|
16
|
+
exit 1
|
17
|
+
end
|
18
|
+
|
19
|
+
def warn(message, *extras)
|
20
|
+
extras << { :color => :yellow, :stream => $stderr }
|
21
|
+
log "--> #{message}", *extras
|
22
|
+
end
|
23
|
+
|
24
|
+
def info(message, *extras)
|
25
|
+
extras << { :color => :cyan }
|
26
|
+
log "--> #{message}", *extras
|
27
|
+
end
|
28
|
+
|
29
|
+
def debug(message, *extras)
|
30
|
+
if debug?
|
31
|
+
extras << { :color => :white }
|
32
|
+
log " DEBUG: #{message}", *extras
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def log(message, *extras)
|
37
|
+
options = Hash === extras.last ? extras.pop : {}
|
38
|
+
|
39
|
+
stream = options[:stream] || $stdout
|
40
|
+
|
41
|
+
if color = options[:color]
|
42
|
+
stream.puts ANSI.send(color) { message }
|
43
|
+
else
|
44
|
+
stream.puts message
|
45
|
+
end
|
46
|
+
|
47
|
+
unless extras.empty?
|
48
|
+
extras.each { |line| stream.puts " #{line}" }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def debug?
|
53
|
+
false
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/script/bootstrap
CHANGED
data/script/tests
CHANGED
data/test/boxen/test.rb
CHANGED
data/test/boxen_cli_test.rb
CHANGED
@@ -1,39 +1,16 @@
|
|
1
|
-
require "boxen/test"
|
2
1
|
require "boxen/cli"
|
3
2
|
|
4
|
-
|
5
|
-
def setup
|
6
|
-
@config = Boxen::Config.new
|
7
|
-
@flags = Boxen::Flags.new
|
8
|
-
@cli = Boxen::CLI.new(@config, @flags)
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_initialize
|
12
|
-
config = Boxen::Config.new
|
13
|
-
flags = Boxen::Flags.new
|
14
|
-
|
15
|
-
cli = Boxen::CLI.new config, flags
|
3
|
+
require "boxen/command_status"
|
16
4
|
|
17
|
-
|
18
|
-
assert_equal flags, cli.flags
|
5
|
+
describe Boxen::CLI do
|
19
6
|
|
20
|
-
|
21
|
-
|
22
|
-
|
7
|
+
it "is a fancy way of reinvoking commands at this time" do
|
8
|
+
config = mock("config")
|
9
|
+
Boxen::Config.expects(:load).returns(config)
|
10
|
+
Boxen::Command.expects(:invoke).with("foo", config).
|
11
|
+
returns(Boxen::CommandStatus.new(0))
|
23
12
|
|
24
|
-
|
25
|
-
@cli.runner.expects(:run)
|
26
|
-
@cli.run
|
13
|
+
Boxen::CLI.run("foo")
|
27
14
|
end
|
28
15
|
|
29
|
-
def test_help
|
30
|
-
$stdout.stubs(:write)
|
31
|
-
|
32
|
-
flags = Boxen::Flags.new('--help')
|
33
|
-
cli = Boxen::CLI.new(@config, flags)
|
34
|
-
cli.runner.expects(:run).never
|
35
|
-
assert_raises SystemExit do
|
36
|
-
cli.run
|
37
|
-
end
|
38
|
-
end
|
39
16
|
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require "boxen/command"
|
2
|
+
|
3
|
+
class Failing < Boxen::Check
|
4
|
+
def initialize(*args); end
|
5
|
+
def ok?; false; end
|
6
|
+
def run; warn "lol this fails in ur face"; end
|
7
|
+
end
|
8
|
+
|
9
|
+
class Boxen::Command::Foo < Boxen::Command
|
10
|
+
def run
|
11
|
+
puts "foo"
|
12
|
+
Boxen::CommandStatus.new(0)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class Boxen::Command::Barnette < Boxen::Command
|
17
|
+
preflight Failing
|
18
|
+
|
19
|
+
def run
|
20
|
+
puts "bar"
|
21
|
+
Boxen::CommandStatus.new(0)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Boxen::Command::Atmos < Boxen::Command
|
26
|
+
postflight Failing
|
27
|
+
|
28
|
+
def run
|
29
|
+
puts "hello, cindarella"
|
30
|
+
Boxen::CommandStatus.new(0)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe Boxen::Command do
|
35
|
+
before do
|
36
|
+
@config = Minitest::Mock.new
|
37
|
+
def @config.debug?; false; end
|
38
|
+
end
|
39
|
+
|
40
|
+
it "registers commands and shoves them into a hash, and can invoke them" do
|
41
|
+
Boxen::Command.register :foo, Boxen::Command::Foo
|
42
|
+
|
43
|
+
stdout, _ = capture_io do
|
44
|
+
Boxen::Command.invoke :foo, @config
|
45
|
+
end
|
46
|
+
|
47
|
+
assert_match "foo", stdout
|
48
|
+
end
|
49
|
+
|
50
|
+
it "fails with UnknownCommandError if the invoked command is not registered" do
|
51
|
+
assert_raises Boxen::Command::UnknownCommandError do
|
52
|
+
Boxen::Command.invoke :random_command
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
it "fails with UnknownCommandError if the invoked command is nil" do
|
57
|
+
assert_raises Boxen::Command::UnknownCommandError do
|
58
|
+
Boxen::Command.invoke nil
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it "registers command aliases" do
|
63
|
+
Boxen::Command.register :foo, Boxen::Command::Foo, :bar
|
64
|
+
|
65
|
+
stdout, _ = capture_io do
|
66
|
+
Boxen::Command.invoke :bar, @config
|
67
|
+
end
|
68
|
+
|
69
|
+
assert_match "foo", stdout
|
70
|
+
end
|
71
|
+
|
72
|
+
it "executes preflight hooks" do
|
73
|
+
Boxen::Command.register :barnette, Boxen::Command::Barnette
|
74
|
+
|
75
|
+
stdout, stderr = capture_io do
|
76
|
+
Boxen::Command.invoke :barnette, @config
|
77
|
+
end
|
78
|
+
|
79
|
+
assert_match "lol this fails in ur face", stderr
|
80
|
+
refute_match "bar", stdout
|
81
|
+
end
|
82
|
+
|
83
|
+
it "executes postflight hooks" do
|
84
|
+
Boxen::Command.register :atmos, Boxen::Command::Atmos
|
85
|
+
|
86
|
+
stdout, stderr = capture_io do
|
87
|
+
Boxen::Command.invoke :atmos, @config
|
88
|
+
end
|
89
|
+
|
90
|
+
assert_match "lol this fails in ur face", stderr
|
91
|
+
assert_match "hello, cindarella", stdout
|
92
|
+
end
|
93
|
+
end
|
data/test/boxen_config_test.rb
CHANGED
@@ -7,13 +7,6 @@ class BoxenConfigTest < Boxen::Test
|
|
7
7
|
@config.repodir = "test/fixtures/repo"
|
8
8
|
end
|
9
9
|
|
10
|
-
def test_debug?
|
11
|
-
refute @config.debug?
|
12
|
-
|
13
|
-
@config.debug = true
|
14
|
-
assert @config.debug?
|
15
|
-
end
|
16
|
-
|
17
10
|
def test_email
|
18
11
|
assert_nil @config.email
|
19
12
|
|
@@ -96,27 +89,6 @@ class BoxenConfigTest < Boxen::Test
|
|
96
89
|
assert_equal "foo", @config.name
|
97
90
|
end
|
98
91
|
|
99
|
-
def test_pretend?
|
100
|
-
refute @config.pretend?
|
101
|
-
|
102
|
-
@config.pretend = true
|
103
|
-
assert @config.pretend?
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_profile?
|
107
|
-
refute @config.profile?
|
108
|
-
|
109
|
-
@config.profile = true
|
110
|
-
assert @config.profile?
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_future_parser?
|
114
|
-
refute @config.future_parser?
|
115
|
-
|
116
|
-
@config.future_parser = true
|
117
|
-
assert @config.future_parser?
|
118
|
-
end
|
119
|
-
|
120
92
|
def test_projects
|
121
93
|
files = Dir["#{@config.repodir}/modules/projects/manifests/*.pp"]
|
122
94
|
assert_equal files.size, @config.projects.size
|
@@ -324,8 +296,6 @@ class BoxenConfigTest < Boxen::Test
|
|
324
296
|
end
|
325
297
|
|
326
298
|
def test_token
|
327
|
-
assert_nil @config.token
|
328
|
-
|
329
299
|
@config.token = "foo"
|
330
300
|
assert_equal "foo", @config.token
|
331
301
|
end
|
@@ -382,7 +352,7 @@ class BoxenConfigTest < Boxen::Test
|
|
382
352
|
ENV["BOXEN_S3_BUCKET"] = val
|
383
353
|
end
|
384
354
|
|
385
|
-
def
|
355
|
+
def test_s3bucket_env_var
|
386
356
|
val = ENV["BOXEN_S3_BUCKET"]
|
387
357
|
|
388
358
|
ENV["BOXEN_S3_BUCKET"] = "my-bucket"
|
@@ -12,25 +12,25 @@ class BoxenPreflightDirectoriesTest < Boxen::Test
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_not_okay_if_homedir_group_wrong
|
15
|
-
directories = Boxen::Preflight::Directories.new(@config)
|
15
|
+
directories = Boxen::Preflight::Directories.new(@config, :command)
|
16
16
|
directories.stubs(:homedir_group).returns(false)
|
17
17
|
refute directories.ok?
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_not_okay_if_homedir_owner_wrong
|
21
|
-
directories = Boxen::Preflight::Directories.new(@config)
|
21
|
+
directories = Boxen::Preflight::Directories.new(@config, :command)
|
22
22
|
directories.stubs(:homedir_owner).returns(false)
|
23
23
|
refute directories.ok?
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_not_okay_unless_homedir_exists
|
27
|
-
directories = Boxen::Preflight::Directories.new(@config)
|
27
|
+
directories = Boxen::Preflight::Directories.new(@config, :command)
|
28
28
|
directories.stubs(:homedir_directory_exists?).returns(false)
|
29
29
|
refute directories.ok?
|
30
30
|
end
|
31
31
|
|
32
32
|
def test_okay_if_allchecks_fine
|
33
|
-
directories = Boxen::Preflight::Directories.new(@config)
|
33
|
+
directories = Boxen::Preflight::Directories.new(@config, :command)
|
34
34
|
directories.stubs(:homedir_directory_exists?).returns(true)
|
35
35
|
directories.stubs(:homedir_owner).returns("foobar")
|
36
36
|
directories.stubs(:homedir_group).returns("staff")
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "boxen/hook"
|
2
|
+
|
3
|
+
class DatHook < Boxen::Hook
|
4
|
+
def enabled?
|
5
|
+
true
|
6
|
+
end
|
7
|
+
|
8
|
+
def run
|
9
|
+
puts "yolo"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe Boxen::Hook do
|
14
|
+
|
15
|
+
it "registers hooks and executes them" do
|
16
|
+
Boxen::Hook.register DatHook
|
17
|
+
|
18
|
+
stdout, _ = capture_io do
|
19
|
+
Boxen::Hook.run
|
20
|
+
end
|
21
|
+
|
22
|
+
assert_equal "yolo\n", stdout
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|