bozo 0.3.3 → 0.3.4

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.
data/lib/bozo/runner.rb CHANGED
@@ -1,58 +1,58 @@
1
- module Bozo
2
-
3
- # Module mixed into the all Bozo executors that provides functionality for
4
- # command execution and logging.
5
- module Runner
6
-
7
- include Bozo::Logging
8
-
9
- # Returns the global parameters.
10
- attr_accessor :global_params
11
-
12
- # Returns the command parameters.
13
- attr_accessor :params
14
-
15
- # Returns the environment variables.
16
- attr_accessor :env
17
-
18
- # Returns the build configuration.
19
- attr_accessor :build_configuration
20
-
21
- # Returns whether the build is being run on a build server.
22
- def build_server?
23
- global_params[:build_server]
24
- end
25
-
26
- # Returns the environment the build is being execute in.
27
- def environment
28
- global_params[:environment]
29
- end
30
-
31
- # Executes a command line tool.
32
- #
33
- # Raises a `Bozo::ExecutionError` if the command responds with a non-zero
34
- # exit code.
35
- #
36
- # @param [Symbol] tool
37
- # A friendly identifier for the tool.
38
- # @param [Array] args
39
- # An array of arguments making up the command to execute.
40
- def execute_command(tool, args)
41
- args.flatten!
42
-
43
- executable = File.basename(args.first)
44
- arguments = args[1..-1].join(' ')
45
-
46
- log_info " #{tool} - #{executable} #{arguments}"
47
-
48
- raise Bozo::ExecutionError.new(tool, args, $?.exitstatus) unless system args.join ' '
49
- end
50
-
51
- # Returns the build version.
52
- def version
53
- build_configuration.version
54
- end
55
-
56
- end
57
-
58
- end
1
+ module Bozo
2
+
3
+ # Module mixed into the all Bozo executors that provides functionality for
4
+ # command execution and logging.
5
+ module Runner
6
+
7
+ include Bozo::Logging
8
+
9
+ # Returns the global parameters.
10
+ attr_accessor :global_params
11
+
12
+ # Returns the command parameters.
13
+ attr_accessor :params
14
+
15
+ # Returns the environment variables.
16
+ attr_accessor :env
17
+
18
+ # Returns the build configuration.
19
+ attr_accessor :build_configuration
20
+
21
+ # Returns whether the build is being run on a build server.
22
+ def build_server?
23
+ global_params[:build_server]
24
+ end
25
+
26
+ # Returns the environment the build is being execute in.
27
+ def environment
28
+ global_params[:environment]
29
+ end
30
+
31
+ # Executes a command line tool.
32
+ #
33
+ # Raises a `Bozo::ExecutionError` if the command responds with a non-zero
34
+ # exit code.
35
+ #
36
+ # @param [Symbol] tool
37
+ # A friendly identifier for the tool.
38
+ # @param [Array] args
39
+ # An array of arguments making up the command to execute.
40
+ def execute_command(tool, args)
41
+ args.flatten!
42
+
43
+ executable = File.basename(args.first)
44
+ arguments = args[1..-1].join(' ')
45
+
46
+ log_info " #{tool} - #{executable} #{arguments}"
47
+
48
+ raise Bozo::ExecutionError.new(tool, args, $?.exitstatus) unless system args.join ' '
49
+ end
50
+
51
+ # Returns the build version.
52
+ def version
53
+ build_configuration.version
54
+ end
55
+
56
+ end
57
+
58
+ end
@@ -1,87 +1,87 @@
1
- module Bozo::Versioning
2
-
3
- class Version
4
-
5
- # @param major [Integer]
6
- # @param minor [Integer]
7
- # @param patch [Integer]
8
- def initialize(major, minor, patch)
9
- @major = major
10
- @minor = minor
11
- @patch = patch
12
- end
13
-
14
- # Loads the version from the VERSION file
15
- def self.load_from_file
16
- raise no_version_file unless File.exist? 'VERSION'
17
- version = File.read('VERSION').strip
18
- raise no_version if version.empty?
19
- parse version
20
- end
21
-
22
- # Parses a version string to create a Version instance
23
- #
24
- # @param version [String]
25
- def self.parse(version)
26
- major, minor, patch = *version.split('.').map(&:to_i)
27
- Version.new major, minor, patch
28
- end
29
-
30
- def major
31
- @major
32
- end
33
-
34
- def minor
35
- @minor
36
- end
37
-
38
- def patch
39
- @patch
40
- end
41
-
42
- # Writes the version from the VERSION file
43
- def write_to_file
44
- File.open("VERSION", 'w') { |f| f << to_s }
45
- end
46
-
47
- # Bumps the part of the version
48
- #
49
- # @param part [Symbol]
50
- def bump(part)
51
- send "bump_#{part}".to_sym
52
- end
53
-
54
- def to_s
55
- "#{@major}.#{@minor}.#{@patch}"
56
- end
57
-
58
- private
59
-
60
- def bump_major
61
- @major += 1
62
- @minor = 0
63
- @patch = 0
64
- end
65
-
66
- def bump_minor
67
- @minor += 1
68
- @patch = 0
69
- end
70
-
71
- def bump_patch
72
- @patch += 1
73
- end
74
-
75
- # Error if no version has been specified
76
- def self.no_version
77
- Bozo::ConfigurationError.new 'No version specified'
78
- end
79
-
80
- # Error if the version file could not be found
81
- def self.no_version_file
82
- Bozo::ConfigurationError.new "VERSION file could not be found in project #{Dir.pwd}"
83
- end
84
-
85
- end
86
-
1
+ module Bozo::Versioning
2
+
3
+ class Version
4
+
5
+ # @param major [Integer]
6
+ # @param minor [Integer]
7
+ # @param patch [Integer]
8
+ def initialize(major, minor, patch)
9
+ @major = major
10
+ @minor = minor
11
+ @patch = patch
12
+ end
13
+
14
+ # Loads the version from the VERSION file
15
+ def self.load_from_file
16
+ raise no_version_file unless File.exist? 'VERSION'
17
+ version = File.read('VERSION').strip
18
+ raise no_version if version.empty?
19
+ parse version
20
+ end
21
+
22
+ # Parses a version string to create a Version instance
23
+ #
24
+ # @param version [String]
25
+ def self.parse(version)
26
+ major, minor, patch = *version.split('.').map(&:to_i)
27
+ Version.new major, minor, patch
28
+ end
29
+
30
+ def major
31
+ @major
32
+ end
33
+
34
+ def minor
35
+ @minor
36
+ end
37
+
38
+ def patch
39
+ @patch
40
+ end
41
+
42
+ # Writes the version from the VERSION file
43
+ def write_to_file
44
+ File.open("VERSION", 'w') { |f| f << to_s }
45
+ end
46
+
47
+ # Bumps the part of the version
48
+ #
49
+ # @param part [Symbol]
50
+ def bump(part)
51
+ send "bump_#{part}".to_sym
52
+ end
53
+
54
+ def to_s
55
+ "#{@major}.#{@minor}.#{@patch}"
56
+ end
57
+
58
+ private
59
+
60
+ def bump_major
61
+ @major += 1
62
+ @minor = 0
63
+ @patch = 0
64
+ end
65
+
66
+ def bump_minor
67
+ @minor += 1
68
+ @patch = 0
69
+ end
70
+
71
+ def bump_patch
72
+ @patch += 1
73
+ end
74
+
75
+ # Error if no version has been specified
76
+ def self.no_version
77
+ Bozo::ConfigurationError.new 'No version specified'
78
+ end
79
+
80
+ # Error if the version file could not be found
81
+ def self.no_version_file
82
+ Bozo::ConfigurationError.new "VERSION file could not be found in project #{Dir.pwd}"
83
+ end
84
+
85
+ end
86
+
87
87
  end
@@ -1,30 +1,30 @@
1
- module Bozo::Versioning
2
-
3
- # Error raised when a runner or hook finds the configuration or build in an
4
- # unexpected state.
5
- class VersionBumpError < StandardError
6
-
7
- # The code the program should exit with upon handling this error.
8
- attr_reader :exit_code
9
-
10
- # A message explaining the corrective actions someone can take to avoid the
11
- # error.
12
- attr_reader :message
13
-
14
- # Creates a new instance.
15
- #
16
- # @param [String] message
17
- # A message explaining the corrective actions someone can take to avoid
18
- # the error.
19
- def initialize(message)
20
- @message = message
21
- @exit_code = -1
22
- end
23
-
24
- def inspect
25
- "Version bump error: #{message}"
26
- end
27
-
28
- end
29
-
1
+ module Bozo::Versioning
2
+
3
+ # Error raised when a runner or hook finds the configuration or build in an
4
+ # unexpected state.
5
+ class VersionBumpError < StandardError
6
+
7
+ # The code the program should exit with upon handling this error.
8
+ attr_reader :exit_code
9
+
10
+ # A message explaining the corrective actions someone can take to avoid the
11
+ # error.
12
+ attr_reader :message
13
+
14
+ # Creates a new instance.
15
+ #
16
+ # @param [String] message
17
+ # A message explaining the corrective actions someone can take to avoid
18
+ # the error.
19
+ def initialize(message)
20
+ @message = message
21
+ @exit_code = -1
22
+ end
23
+
24
+ def inspect
25
+ "Version bump error: #{message}"
26
+ end
27
+
28
+ end
29
+
30
30
  end
@@ -1,36 +1,36 @@
1
- module Bozo::Versioning
2
-
3
- class VersionBumper
4
-
5
- include Bozo::Logging
6
-
7
- def bump(part)
8
- unless can_be_bumped?
9
- raise VersionBumpError.new "State of the repository means the version can't be bumped. Ensure the staging index is empty."
10
- end
11
-
12
- version = Version.load_from_file
13
- original_version = version.to_s
14
-
15
- version.bump part
16
- version.write_to_file
17
-
18
- commit_version original_version, version
19
-
20
- log_info "Bumped #{original_version} to #{version}"
21
- end
22
-
23
- private
24
-
25
- def can_be_bumped?
26
- `git diff --cached --name-only`.length == 0
27
- end
28
-
29
- def commit_version(original, new)
30
- `git add VERSION`
31
- `git commit -m "Bumped #{original} to #{new}."`
32
- end
33
-
34
- end
35
-
36
- end
1
+ module Bozo::Versioning
2
+
3
+ class VersionBumper
4
+
5
+ include Bozo::Logging
6
+
7
+ def bump(part)
8
+ unless can_be_bumped?
9
+ raise VersionBumpError.new "State of the repository means the version can't be bumped. Ensure the staging index is empty."
10
+ end
11
+
12
+ version = Version.load_from_file
13
+ original_version = version.to_s
14
+
15
+ version.bump part
16
+ version.write_to_file
17
+
18
+ commit_version original_version, version
19
+
20
+ log_info "Bumped #{original_version} to #{version}"
21
+ end
22
+
23
+ private
24
+
25
+ def can_be_bumped?
26
+ `git diff --cached --name-only`.length == 0
27
+ end
28
+
29
+ def commit_version(original, new)
30
+ `git add VERSION`
31
+ `git commit -m "Bumped #{original} to #{new}."`
32
+ end
33
+
34
+ end
35
+
36
+ end
data/lib/bozo.rb CHANGED
@@ -1,131 +1,131 @@
1
- $:.push File.expand_path(File.dirname(__FILE__))
2
-
3
- require 'rubygems'
4
- require 'rainbow'
5
- require 'rainbow/ext/string'
6
- require 'gli'
7
- require 'gli_version'
8
- require 'bozo/bozo'
9
- require 'bozo/class_name_helpers'
10
- require 'bozo/logging'
11
- require 'bozo/runner'
12
- require 'bozo/executor'
13
- require 'bozo/bozo_configuration'
14
- require 'bozo/configuration_error'
15
- require 'bozo/execution_error'
16
- require 'bozo/versioning/version'
17
- require 'bozo/versioning/version_bumper'
18
- require 'bozo/versioning/version_bump_error'
19
-
20
- include GLI
21
-
22
- # Set the location of the bozo runtime configuration file
23
- config_file '.bozorc'
24
-
25
- version Bozo::VERSION
26
-
27
- desc 'Run as a build server, allows more destructive actions'
28
- switch 'build-server'
29
-
30
- default_config_file = 'bozorc.rb'
31
-
32
- desc "The build configuration file (defaults to #{default_config_file})"
33
- default_value default_config_file
34
- arg_name 'path'
35
- flag 'config-file'
36
-
37
- default_environment = 'development'
38
-
39
- desc "The build environment (defaults to #{default_environment})"
40
- default_value default_environment
41
- arg_name 'name'
42
- flag :environment
43
-
44
- pre do |global_options, command, options, arguments|
45
- # Load the configuration file.
46
- config = Bozo::BozoConfiguration.new
47
- config.load global_options[:'config-file']
48
-
49
- puts "Building #{config.version} using Bozo #{Bozo::VERSION}"
50
- puts ''
51
-
52
- # Initialize the executor.
53
- @executor = Bozo::Executor.new config, global_options
54
-
55
- true
56
- end
57
-
58
- # Helper method for defining a command that invokes a bozo task.
59
- #
60
- # The first provided name will be passed on to bozo.
61
- #
62
- # Takes an optional block for defining command-specific flags and switches.
63
- #
64
- # @param [Symbol] command_names
65
- # The names to give the command.
66
- def bozo_command(*command_names)
67
- command_name = command_names.first
68
- command command_names do |c|
69
- yield c if block_given?
70
- c.action do |global_options, options, arguments|
71
- @executor.execute command_name, options, ENV.to_hash
72
- end
73
- end
74
- end
75
-
76
- desc 'Remove bozo and all its artifacts'
77
- bozo_command :uninstall
78
-
79
- desc 'Remove all build artifacts'
80
- bozo_command :clean
81
-
82
- desc 'Retrieve all project dependencies'
83
- bozo_command :dependencies
84
-
85
- desc 'Prepare the project'
86
- bozo_command :prepare
87
-
88
- desc 'Compile the project'
89
- bozo_command :compile, :c
90
-
91
- desc 'Run the tests for the project'
92
- bozo_command :test, :t
93
-
94
- desc 'Create a package'
95
- bozo_command :package, :p do |c|
96
- c.desc 'Force a pre-release package to be created'
97
- c.switch 'pre-release'
98
- end
99
-
100
- desc 'Publish a package'
101
- bozo_command :publish do |c|
102
- c.desc 'Force a pre-release package to be published'
103
- c.switch 'pre-release'
104
- end
105
-
106
- desc 'Bump the version number'
107
- long_desc <<EOS
108
- Specify either 'major', 'minor' or 'patch' as an argument. For example: `bozo bump major`
109
- EOS
110
- command :bump do |c|
111
- c.action do |global_options, options, args|
112
- if args.empty?
113
- puts "Specify either 'major', 'minor' or 'patch' as an argument"
114
- else
115
- version_bumper = Bozo::Versioning::VersionBumper.new
116
- version_bumper.bump args[0].to_sym
117
- end
118
- end
119
- end
120
-
121
- on_error do |exception|
122
- puts exception.inspect.color(:red).bright
123
-
124
- if exception.kind_of? Bozo::ExecutionError or exception.kind_of? Bozo::ConfigurationError
125
- false
126
- else
127
- puts ''
128
- puts exception.backtrace.join("\n").color(:red)
129
- true
130
- end
1
+ $:.push File.expand_path(File.dirname(__FILE__))
2
+
3
+ require 'rubygems'
4
+ require 'rainbow'
5
+ require 'rainbow/ext/string'
6
+ require 'gli'
7
+ require 'gli_version'
8
+ require 'bozo/bozo'
9
+ require 'bozo/class_name_helpers'
10
+ require 'bozo/logging'
11
+ require 'bozo/runner'
12
+ require 'bozo/executor'
13
+ require 'bozo/bozo_configuration'
14
+ require 'bozo/configuration_error'
15
+ require 'bozo/execution_error'
16
+ require 'bozo/versioning/version'
17
+ require 'bozo/versioning/version_bumper'
18
+ require 'bozo/versioning/version_bump_error'
19
+
20
+ include GLI
21
+
22
+ # Set the location of the bozo runtime configuration file
23
+ config_file '.bozorc'
24
+
25
+ version Bozo::VERSION
26
+
27
+ desc 'Run as a build server, allows more destructive actions'
28
+ switch 'build-server'
29
+
30
+ default_config_file = 'bozorc.rb'
31
+
32
+ desc "The build configuration file (defaults to #{default_config_file})"
33
+ default_value default_config_file
34
+ arg_name 'path'
35
+ flag 'config-file'
36
+
37
+ default_environment = 'development'
38
+
39
+ desc "The build environment (defaults to #{default_environment})"
40
+ default_value default_environment
41
+ arg_name 'name'
42
+ flag :environment
43
+
44
+ pre do |global_options, command, options, arguments|
45
+ # Load the configuration file.
46
+ config = Bozo::BozoConfiguration.new
47
+ config.load global_options[:'config-file']
48
+
49
+ puts "Building #{config.version} using Bozo #{Bozo::VERSION}"
50
+ puts ''
51
+
52
+ # Initialize the executor.
53
+ @executor = Bozo::Executor.new config, global_options
54
+
55
+ true
56
+ end
57
+
58
+ # Helper method for defining a command that invokes a bozo task.
59
+ #
60
+ # The first provided name will be passed on to bozo.
61
+ #
62
+ # Takes an optional block for defining command-specific flags and switches.
63
+ #
64
+ # @param [Symbol] command_names
65
+ # The names to give the command.
66
+ def bozo_command(*command_names)
67
+ command_name = command_names.first
68
+ command command_names do |c|
69
+ yield c if block_given?
70
+ c.action do |global_options, options, arguments|
71
+ @executor.execute command_name, options, ENV.to_hash
72
+ end
73
+ end
74
+ end
75
+
76
+ desc 'Remove bozo and all its artifacts'
77
+ bozo_command :uninstall
78
+
79
+ desc 'Remove all build artifacts'
80
+ bozo_command :clean
81
+
82
+ desc 'Retrieve all project dependencies'
83
+ bozo_command :dependencies
84
+
85
+ desc 'Prepare the project'
86
+ bozo_command :prepare
87
+
88
+ desc 'Compile the project'
89
+ bozo_command :compile, :c
90
+
91
+ desc 'Run the tests for the project'
92
+ bozo_command :test, :t
93
+
94
+ desc 'Create a package'
95
+ bozo_command :package, :p do |c|
96
+ c.desc 'Force a pre-release package to be created'
97
+ c.switch 'pre-release'
98
+ end
99
+
100
+ desc 'Publish a package'
101
+ bozo_command :publish do |c|
102
+ c.desc 'Force a pre-release package to be published'
103
+ c.switch 'pre-release'
104
+ end
105
+
106
+ desc 'Bump the version number'
107
+ long_desc <<EOS
108
+ Specify either 'major', 'minor' or 'patch' as an argument. For example: `bozo bump major`
109
+ EOS
110
+ command :bump do |c|
111
+ c.action do |global_options, options, args|
112
+ if args.empty?
113
+ puts "Specify either 'major', 'minor' or 'patch' as an argument"
114
+ else
115
+ version_bumper = Bozo::Versioning::VersionBumper.new
116
+ version_bumper.bump args[0].to_sym
117
+ end
118
+ end
119
+ end
120
+
121
+ on_error do |exception|
122
+ puts exception.inspect.color(:red).bright
123
+
124
+ if exception.kind_of? Bozo::ExecutionError or exception.kind_of? Bozo::ConfigurationError
125
+ false
126
+ else
127
+ puts ''
128
+ puts exception.backtrace.join("\n").color(:red)
129
+ true
130
+ end
131
131
  end