boxen 3.0.0.beta1 → 3.1.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.
Files changed (73) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +0 -1
  3. data/README.md +1 -1
  4. data/boxen.gemspec +13 -13
  5. data/lib/boxen/check.rb +39 -8
  6. data/lib/boxen/cli.rb +45 -19
  7. data/lib/boxen/config.rb +61 -43
  8. data/lib/boxen/flags.rb +282 -0
  9. data/lib/boxen/hook.rb +8 -15
  10. data/lib/boxen/hook/github_issue.rb +120 -0
  11. data/lib/boxen/hook/web.rb +56 -0
  12. data/lib/boxen/keychain.rb +1 -1
  13. data/lib/boxen/postflight/env.rb +1 -1
  14. data/lib/boxen/preflight.rb +7 -4
  15. data/lib/boxen/preflight/creds.rb +47 -8
  16. data/lib/boxen/preflight/identity.rb +0 -2
  17. data/lib/boxen/preflight/os.rb +6 -2
  18. data/lib/boxen/puppeteer.rb +121 -0
  19. data/lib/boxen/runner.rb +149 -0
  20. data/script/bootstrap +1 -1
  21. data/script/tests +0 -1
  22. data/test/boxen/test.rb +1 -1
  23. data/test/boxen_check_test.rb +55 -0
  24. data/test/boxen_cli_test.rb +31 -8
  25. data/test/boxen_config_test.rb +31 -1
  26. data/test/boxen_directories_test.rb +4 -4
  27. data/test/boxen_flags_test.rb +217 -0
  28. data/test/{postflight/boxen_postflight_github_issue_test.rb → boxen_hook_github_issue_test.rb} +82 -72
  29. data/test/{postflight/boxen_postflight_web_hook_test.rb → boxen_hook_web_test.rb} +11 -12
  30. data/test/{postflight/boxen_postflight_active_test.rb → boxen_postflight_active_test.rb} +3 -3
  31. data/test/{postflight/boxen_postflight_env_test.rb → boxen_postflight_env_test.rb} +0 -0
  32. data/test/boxen_preflight_creds_test.rb +177 -0
  33. data/test/{preflight/boxen_preflight_etc_my_cnf_test.rb → boxen_preflight_etc_my_cnf_test.rb} +1 -1
  34. data/test/{preflight/boxen_preflight_rvm_test.rb → boxen_preflight_rvm_test.rb} +1 -1
  35. data/test/boxen_puppeteer_test.rb +101 -0
  36. data/test/boxen_runner_test.rb +171 -0
  37. metadata +172 -251
  38. data/lib/boxen/command.rb +0 -142
  39. data/lib/boxen/command/help.rb +0 -40
  40. data/lib/boxen/command/preflight.rb +0 -38
  41. data/lib/boxen/command/project.rb +0 -49
  42. data/lib/boxen/command/project/install.rb +0 -33
  43. data/lib/boxen/command/run.rb +0 -199
  44. data/lib/boxen/command/service.rb +0 -61
  45. data/lib/boxen/command/service/disable.rb +0 -15
  46. data/lib/boxen/command/service/enable.rb +0 -15
  47. data/lib/boxen/command/service/restart.rb +0 -24
  48. data/lib/boxen/command/version.rb +0 -29
  49. data/lib/boxen/command_status.rb +0 -15
  50. data/lib/boxen/postflight/github_issue.rb +0 -124
  51. data/lib/boxen/postflight/hooks.rb +0 -16
  52. data/lib/boxen/postflight/web_hook.rb +0 -63
  53. data/lib/boxen/preflight/facts.rb +0 -36
  54. data/lib/boxen/preflight/homebrew.rb +0 -13
  55. data/lib/boxen/preflight/offline.rb +0 -33
  56. data/lib/boxen/preflight/update.rb +0 -109
  57. data/lib/boxen/util/logging.rb +0 -59
  58. data/lib/boxen/version.rb +0 -3
  59. data/lib/system_timer.rb +0 -13
  60. data/test/boxen_command_test.rb +0 -93
  61. data/test/boxen_hook_test.rb +0 -25
  62. data/test/command/help_test.rb +0 -49
  63. data/test/command/project/install_test.rb +0 -34
  64. data/test/command/project_test.rb +0 -32
  65. data/test/command/run_test.rb +0 -21
  66. data/test/command/service/disable_test.rb +0 -49
  67. data/test/command/service/enable_test.rb +0 -49
  68. data/test/command/service/restart_test.rb +0 -53
  69. data/test/command/service_test.rb +0 -55
  70. data/test/command/version_test.rb +0 -15
  71. data/test/preflight/boxen_preflight_creds_test.rb +0 -82
  72. data/test/preflight/boxen_preflight_homebrew_test.rb +0 -10
  73. data/test/system_timer.rb +0 -10
@@ -1,61 +0,0 @@
1
- require "boxen/command"
2
- require "boxen/service"
3
-
4
- class Boxen::Command::Service < Boxen::Command
5
- def self.detailed_help
6
- <<-EOS
7
-
8
- boxen service
9
-
10
- Display all services Boxen knows about.
11
-
12
- boxen service:enable <service1> [<service2> ...]
13
-
14
- Enable and start a Boxen-managed service. If none are given,
15
- enables and starts all Boxen-managed services.
16
-
17
- boxen service:disable <service1> [<service2> ...]
18
-
19
- Disable and stop a Boxen-managed service. If none are given,
20
- disables and stops all Boxen-managed services.
21
-
22
- boxen service:restart [<service1> <service2> ...]
23
-
24
- Restart a Boxen-managed service. If none are given, restarts all
25
- Boxen-managed services.
26
-
27
- NOTE: 'boxen service' is aliased to 'services' for convenience
28
-
29
- EOS
30
- end
31
-
32
- def self.help
33
- "Show and manage Boxen services."
34
- end
35
-
36
- def run
37
- @args = [] # we don't care about args here
38
-
39
- puts "Boxen manages the following services:\n\n"
40
-
41
- services.each do |service|
42
- puts " #{service.name}"
43
- end
44
-
45
- Boxen::CommandStatus.new(0)
46
- end
47
-
48
- def services
49
- @services ||= if @args.any?
50
- @args.map { |s| Boxen::Service.new(s) }
51
- else
52
- Boxen::Service.list
53
- end
54
- end
55
- end
56
-
57
- require "boxen/command/service/enable"
58
- require "boxen/command/service/disable"
59
- require "boxen/command/service/restart"
60
-
61
- Boxen::Command.register :service, Boxen::Command::Service, :services
@@ -1,15 +0,0 @@
1
- require "boxen/command/service"
2
-
3
- class Boxen::Command::Service::Disable < Boxen::Command::Service
4
- def run
5
- services.each do |service|
6
- puts "Disabling service: #{service.name}"
7
- service.disable
8
- end
9
-
10
- Boxen::CommandStatus.new(0)
11
- end
12
- end
13
-
14
- Boxen::Command.register :"service:disable", Boxen::Command::Service::Disable
15
- Boxen::Command.register :"services:disable", Boxen::Command::Service::Disable
@@ -1,15 +0,0 @@
1
- require "boxen/command/service"
2
-
3
- class Boxen::Command::Service::Enable < Boxen::Command::Service
4
- def run
5
- services.each do |service|
6
- puts "Enabling service: #{service.name}"
7
- service.enable
8
- end
9
-
10
- Boxen::CommandStatus.new(0)
11
- end
12
- end
13
-
14
- Boxen::Command.register :"service:enable", Boxen::Command::Service::Enable
15
- Boxen::Command.register :"services:enable", Boxen::Command::Service::Enable
@@ -1,24 +0,0 @@
1
- require "boxen/command/service"
2
-
3
- class Boxen::Command::Service::Restart < Boxen::Command::Service
4
- def run
5
- services.each do |service|
6
- puts "Restarting service: #{service.name}"
7
- service.disable
8
- service.enable
9
- end
10
-
11
- Boxen::CommandStatus.new(0)
12
- end
13
-
14
- def services
15
- @services ||= if @args.any?
16
- @args.map { |s| Boxen::Service.new(s) }
17
- else
18
- Boxen::Service.list_enabled
19
- end
20
- end
21
- end
22
-
23
- Boxen::Command.register :"service:restart", Boxen::Command::Service::Restart
24
- Boxen::Command.register :"services:restart", Boxen::Command::Service::Restart
@@ -1,29 +0,0 @@
1
- require "boxen/command"
2
- require "boxen/version"
3
-
4
- class Boxen::Command::Version < Boxen::Command
5
- def self.help
6
- "Displays the current version of Boxen"
7
- end
8
-
9
- def self.detailed_help
10
- <<-EOS
11
-
12
- boxen version
13
-
14
- Display the current version of the Boxen gem.
15
-
16
- EOS
17
- end
18
-
19
- def run
20
- puts "Boxen #{version}"
21
- Boxen::CommandStatus.new(0)
22
- end
23
-
24
- def version
25
- Boxen::VERSION
26
- end
27
- end
28
-
29
- Boxen::Command.register :version, Boxen::Command::Version, :"-v", :"--version"
@@ -1,15 +0,0 @@
1
- module Boxen
2
- class CommandStatus
3
- attr_reader :code, :successful_on
4
-
5
- def initialize(code, successful_on = [0])
6
- @successful_on = successful_on
7
- @code = code
8
- end
9
-
10
- def success?
11
- successful_on.member? code
12
- end
13
-
14
- end
15
- end
@@ -1,124 +0,0 @@
1
- require "boxen/postflight"
2
- require "boxen/checkout"
3
-
4
- # Checks to see if the basic environment is loaded.
5
-
6
- class Boxen::Postflight::GithubIssue < Boxen::Postflight
7
- def checkout
8
- @checkout ||= Boxen::Checkout.new(@config)
9
- end
10
-
11
- def ok?
12
- # Only run if we have credentials and we're on master
13
- !enabled? || config.login.to_s.empty? || !checkout.master?
14
- end
15
-
16
- def run
17
- if command.success?
18
- close_failures
19
- else
20
- warn "Sorry! Creating an issue on #{config.reponame}"
21
- record_failure
22
- end
23
- end
24
-
25
- def compare_url
26
- return unless config.reponame
27
- "#{config.ghurl}/#{config.reponame}/compare/#{checkout.sha}...master"
28
- end
29
-
30
- def hostname
31
- Socket.gethostname
32
- end
33
-
34
- def os
35
- `sw_vers -productVersion`.strip
36
- end
37
-
38
- def shell
39
- ENV["SHELL"]
40
- end
41
-
42
- def logfile
43
- File.read config.logfile
44
- end
45
-
46
- def record_failure
47
- return unless issues?
48
-
49
- title = "Failed for #{config.user}"
50
- config.api.create_issue config.reponame,
51
- title,
52
- failure_details,
53
- :labels => [
54
- failure_label
55
- ]
56
- end
57
-
58
- def close_failures
59
- return unless issues?
60
-
61
- comment = "Succeeded at version #{checkout.sha}."
62
- failures.each do |issue|
63
- config.api.add_comment(config.reponame, issue.number, comment)
64
- config.api.close_issue(config.reponame, issue.number)
65
- end
66
- end
67
-
68
- def failures
69
- return [] unless issues?
70
-
71
- issues = config.api.list_issues(config.reponame, :state => 'open',
72
- :labels => failure_label, :creator => config.login)
73
- issues.reject! {|i| i.labels.collect(&:name).include?(ongoing_label)}
74
- issues
75
- end
76
-
77
- def failure_details
78
- body = ''
79
- body << "Running on `#{hostname}` (OS X #{os}) under `#{shell}`, "
80
- body << "version #{checkout.sha} ([compare to master](#{compare_url}))."
81
- body << "\n\n"
82
-
83
- if checkout.dirty?
84
- body << "### Changes"
85
- body << "\n\n"
86
- body << "```\n#{checkout.changes}\n```"
87
- body << "\n\n"
88
- end
89
-
90
- body << "### Output (from #{config.logfile})"
91
- body << "\n\n"
92
- body << "```\n#{logfile}\n```\n"
93
-
94
- body
95
- end
96
-
97
- attr_writer :failure_label
98
- def failure_label
99
- @failure_label ||= 'failure'
100
- end
101
-
102
- attr_writer :ongoing_label
103
- def ongoing_label
104
- @ongoing_label ||= 'ongoing'
105
- end
106
-
107
- def issues?
108
- return unless config.reponame
109
- return if config.reponame == 'boxen/our-boxen'
110
-
111
- config.api.repository(config.reponame).has_issues
112
- end
113
-
114
- def required_environment_variables
115
- ['BOXEN_ISSUES_ENABLED']
116
- end
117
-
118
- def enabled?
119
- required_vars = Array(required_environment_variables)
120
- required_vars.any? && required_vars.all? do |var|
121
- ENV[var] && !ENV[var].empty?
122
- end
123
- end
124
- end
@@ -1,16 +0,0 @@
1
- require "boxen/postflight"
2
- require "boxen/hook"
3
-
4
- # Prints deprecation notices for all pre-3.x style hooks
5
-
6
- class Boxen::Postflight::Hooks < Boxen::Postflight
7
- def ok?
8
- !Boxen::Hook.all.any?
9
- end
10
-
11
- def run
12
- ::Boxen::Hook.all.each do |hook|
13
- warn "DEPRECATION WARNING: Boxen::Hook is deprecated (#{hook})"
14
- end
15
- end
16
- end
@@ -1,63 +0,0 @@
1
- require "boxen/postflight"
2
- require "json"
3
- require "net/http"
4
-
5
- class Boxen::Postflight::WebHook < Boxen::Postflight
6
- def ok?
7
- !enabled?
8
- end
9
-
10
- attr_writer :checkout
11
- def checkout
12
- @checkout ||= Boxen::Checkout.new(config)
13
- end
14
-
15
- def run
16
- payload = {
17
- :login => config.user,
18
- :sha => checkout.sha,
19
- :status => command.success? ? 'success' : 'failure',
20
- :time => "#{Time.now.utc.to_i}"
21
- }
22
-
23
- post_web_hook payload
24
- end
25
-
26
- def post_web_hook(payload)
27
- headers = { 'Content-Type' => 'application/json' }
28
-
29
- uri = URI.parse(URI.escape(ENV['BOXEN_WEB_HOOK_URL']))
30
-
31
- user, pass, host, port, path = \
32
- uri.user, uri.pass, uri.host, uri.port, uri.path
33
-
34
- request = Net::HTTP::Post.new(path, headers)
35
-
36
- if uri.scheme =~ /https/
37
- http.use_ssl = true
38
- end
39
-
40
- if user && pass
41
- request.basic_auth user, pass
42
- end
43
-
44
- request.body = payload.to_json
45
-
46
- response = Net::HTTP.new(host, port).start do |http|
47
- http.request(request)
48
- end
49
-
50
- response
51
- end
52
-
53
- def required_environment_variables
54
- ['BOXEN_WEB_HOOK_URL']
55
- end
56
-
57
- def enabled?
58
- required_vars = Array(required_environment_variables)
59
- required_vars.any? && required_vars.all? do |var|
60
- ENV[var] && !ENV[var].empty?
61
- end
62
- end
63
- end
@@ -1,36 +0,0 @@
1
- require "fileutils"
2
- require "pathname"
3
-
4
- require "boxen/preflight"
5
-
6
- class Boxen::Preflight::Facts < Boxen::Preflight
7
- def ok?
8
- write_facts
9
-
10
- true
11
- end
12
-
13
- def run
14
- end
15
-
16
- private
17
-
18
- def facter_d
19
- Pathname.new("#{config.homedir}/facts.d")
20
- end
21
-
22
- def write_facts
23
- FileUtils.mkdir_p facter_d
24
-
25
- write_fact "offline", config.offline?
26
- end
27
-
28
- def write_fact(name, value)
29
- File.open("#{facter_d}/#{name}.txt", "w") do |f|
30
- f.write "#{name}=#{value}\n"
31
- end
32
-
33
- debug "Setting global fact `#{name}` to `#{value}`"
34
- end
35
-
36
- end
@@ -1,13 +0,0 @@
1
- require "boxen/preflight"
2
-
3
- class Boxen::Preflight::Homebrew < Boxen::Preflight
4
- def run
5
- warn "You have an existing Homebrew install in /usr/local",
6
- "The Boxen provides its own Homebrew, so consider deleting yours.",
7
- "Keeping both will confuse many projects."
8
- end
9
-
10
- def ok?
11
- !File.exist? "/usr/local/Library/Homebrew"
12
- end
13
- end
@@ -1,33 +0,0 @@
1
- require "socket"
2
- require "timeout"
3
-
4
- require "boxen/preflight"
5
-
6
- class Boxen::Preflight::Offline < Boxen::Preflight
7
- def ok?
8
- config.offline = !google_reachable?
9
-
10
- info "Running boxen in offline mode as we couldn't reach google." if config.offline?
11
-
12
- true
13
- end
14
-
15
- def run
16
- end
17
-
18
- private
19
-
20
- def google_reachable?
21
- @online = begin
22
- timeout(3) do
23
- s = TCPSocket.new('google.com', 80)
24
- s.close
25
- end
26
- true
27
- rescue Errno::ECONNREFUSED
28
- true
29
- rescue Timeout::Error, StandardError
30
- false
31
- end
32
- end
33
- end