buildar 1.4.0.15 → 2.0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YmIzNmVkZGIzNmE5NTRjYmQwNDkzNzIyMzExZjE3YzlhM2M5OTAxYg==
5
+ data.tar.gz: !binary |-
6
+ ZjdiZTg1ZDhkMjg2NmM3N2NkNzk4MDAyZmFkOTBjODYyZTY3ZDY3Ng==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MGFmMmY3MjVjNWU1MTlmOGEzODBmYjAyYjRjZDFkMzg4OGEyNGFhNWNhYmEx
10
+ ZmUyMWVmZTdjZWUwOWIzNTBkZjVjNjYzODY2NDZhNDk5NGRhZTA3ZDM0NmVk
11
+ ZDdiMzJiYzA3MWVjOTYwOTc2Y2ZkNTE2OTM4ZmM5MGU1MmE5NGM=
12
+ data.tar.gz: !binary |-
13
+ MmY5MWE4Mjk4Mzg5ZWM1OWE3YWY1Mzg1ODAyMTBjMjY3MTFmODM4ZjJiNWFm
14
+ NjM2MTNmZDc3ZThmYmU4ZmUyYTA1NTY0NWRhMGMyYTQzYWQ2NTFjYjdiMGY5
15
+ YjUwOTQxYjI4Mjc3ZGJhYTFiNGIyYThkM2NhOTIyMGI4ODI0Yzc=
data/MANIFEST.txt CHANGED
@@ -4,4 +4,3 @@ VERSION
4
4
  README.md
5
5
  rakefile.rb
6
6
  lib/buildar.rb
7
- lib/buildar/tasks.rb
data/README.md CHANGED
@@ -10,19 +10,18 @@ With a set of options to integrate with your current project.
10
10
  Rake tasks
11
11
  ----------
12
12
  Core
13
- * `release` - `message` `build` `tag` `publish`
14
- * `build` - `test` `bump_build` build a .gem file inside pkg/
15
- * `test` - runs your tests using rake/testtask
16
- * `message` - capture a message from ENV['message'] or prompt STDIN
17
- * `install` - `build` uninstall, install built .gem
18
- * `version` - show the current project version
19
- * `buildar` - config check
20
-
21
- With rubygems.org integration
22
- * `publish` - `verify publish credentials` gem push
23
-
24
- With git integration
25
- * `tag` - `test` git tag according to current version, pushed to origin
13
+ * `release` - `build` `publish` `tag`
14
+ * `build` - `pre_build` gem build a pkg/.gem
15
+ * `gem_package` - `pre_build` Gem::PackageTask builds a pkg/.gem
16
+ * `install` - `built` install built .gem
17
+ * `install_new` - `build` install built .gem
18
+ * `version` - show the current project version
19
+ * `buildar` - config check
20
+ * `message` - capture a message from ENV['message'] or prompt STDIN
21
+ * `pre_build` - invoke `test` and `bump_build` conditionally
22
+ * `built` - `build`
23
+ * `publish` - `built` gem push
24
+ * `tag` - `message` git tag according to current version, pushed to origin
26
25
 
27
26
  With version file integration
28
27
  * `bump_build` - increment the 4th version number (1.2.3.4 -> 1.2.3.5)
@@ -35,7 +34,7 @@ With version file integration
35
34
 
36
35
  Tasks which depend on optional functionality will not fail if the option is disabled. They are effectively skipped.
37
36
 
38
- [Just show me the file](https://github.com/rickhull/buildar/blob/master/lib/buildar/tasks.rb)
37
+ [Just show me the tasks](https://github.com/rickhull/buildar/blob/master/lib/buildar.rb#L73)
39
38
 
40
39
  Install
41
40
  -------
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.4.0.15
1
+ 2.0.0.4
data/lib/buildar.rb CHANGED
@@ -1,40 +1,13 @@
1
- # Buildar is effectively a hand-rolled singleton. Yes, a NIH miserable excuse
2
- # for a global.
3
- # Look, we want to be able to call Buildar.conf in the project rakefile, but
4
- # we need that data accessible here and inside lib/buildar/tasks.
5
- # So we need a "global".
6
- # But if we use a class-based singleton, it's namespaced.
7
- # And it can't be set to nil, for example.
8
- #
9
- class Buildar
1
+ require 'rake'
2
+ require 'rake/clean'
3
+ require 'rake/tasklib'
4
+
5
+ class Buildar < Rake::TaskLib
10
6
  def self.version
11
7
  file = File.expand_path('../../VERSION', __FILE__)
12
8
  File.read(file).chomp
13
9
  end
14
10
 
15
- # Call this from the rakefile, like:
16
- # Buildar.conf(__FILE__) do |b|
17
- # b.name = 'foo'
18
- # # ...
19
- # end
20
- #
21
- def self.conf(rakefile = nil)
22
- unless defined?(@@instance)
23
- root = rakefile ? File.expand_path('..', rakefile) : nil
24
- @@instance = Buildar.new root
25
- end
26
- yield @@instance if block_given?
27
- end
28
-
29
- # Confirming singleton.
30
- # Only buildar/raketasks should need to call this
31
- # Use conf inside project/Rakefile
32
- #
33
- def self.instance
34
- raise "no instance; call Buildar.conf" unless defined?(@@instance)
35
- @@instance
36
- end
37
-
38
11
  # e.g. bump(:minor, '1.2.3') #=> '1.3.0'
39
12
  # only works for versions consisting of integers delimited by periods (dots)
40
13
  #
@@ -58,85 +31,189 @@ class Buildar
58
31
  }.join('.')
59
32
  end
60
33
 
61
- attr_accessor :root, :name,
62
- :use_git, :publish,
63
- :use_gemspec_file, :gemspec_filename,
64
- :use_version_file, :version_filename
65
-
66
- attr_writer :gemspec_filename
34
+ attr_accessor :gemspec_file, :version_file, :use_git, :pkg_dir, :ns
67
35
 
68
- def initialize(root = nil)
69
- @root = root ? File.expand_path(root) : Dir.pwd
70
- @name = File.split(@root).last
36
+ def initialize
37
+ @gemspec_file = nil
38
+ @version_file = nil
71
39
  @use_git = false
72
- @publish = { rubygems: false }
73
- @use_gemspec_file = true
74
- @use_version_file = false
75
- @version_filename = 'VERSION'
40
+ @pkg_dir = 'pkg'
41
+ @ns = ''
42
+
43
+ if block_given?
44
+ yield self
45
+ define
46
+ end
76
47
  end
77
48
 
78
49
  def gemspec
79
- @use_gemspec_file ? self.hard_gemspec : self.soft_gemspec
50
+ if @gemspec_file
51
+ Gem::Specification.load @gemspec_file
52
+ else
53
+ @gemspec ||= Gem::Specification.new
54
+ @gemspec.version = self.read_version if @version_file
55
+ @gemspec
56
+ end
80
57
  end
81
58
 
82
- def soft_gemspec
83
- @soft_gemspec ||= Gem::Specification.new
84
- @soft_gemspec.name = @name
85
- @soft_gemspec.version = self.version if @use_version_file
86
- @soft_gemspec
59
+ def read_version
60
+ raise "no @version_file" unless @version_file
61
+ File.read(@version_file).chomp
87
62
  end
88
63
 
89
- # load every time; cache locally if you must
90
- #
91
- def hard_gemspec
92
- Gem::Specification.load self.gemspec_file
64
+ def write_version(new_version)
65
+ raise "no @version_file" unless @version_file
66
+ File.open(@version_file, 'w') { |f| f.write(new_version) }
93
67
  end
94
68
 
95
- def gemspec_file
96
- File.join(@root, self.gemspec_filename)
69
+ def gem_file
70
+ File.join(@pkg_dir, "#{gemspec.name}-#{gemspec.version}.gem")
97
71
  end
98
72
 
99
- # @name.gemspec is the default, but don't set this in the constructor
100
- # it's common to set the name after intialization. e.g. via Buildar.conf
101
- # so set the default on first invocation. After that, it's an accessor.
102
- #
103
- def gemspec_filename
104
- @gemspec_filename ||= "#{@name}.gemspec"
105
- @gemspec_filename
106
- end
73
+ def define
74
+ directory @pkg_dir
75
+ CLOBBER.include @pkg_dir
107
76
 
108
- def gemspec_location
109
- @use_gemspec_file ? self.gemspec_filename : 'Rakefile'
110
- end
77
+ if @ns and !@ns.empty?
78
+ namespace @ns do
79
+ define_tasks
80
+ end
81
+ else
82
+ define_tasks
83
+ end
111
84
 
112
- def version
113
- File.read(self.version_file).chomp
114
- end
85
+ #
86
+ # tasks to be kept out of any optional namespace
87
+ #
88
+
89
+ desc "config check"
90
+ task :buildar do
91
+ spacer = " " * 14
92
+ gemspec = self.gemspec
93
+ puts
94
+ puts <<EOF
95
+ Project: #{gemspec.name} #{gemspec.version}
96
+ Gemspec file: #{@gemspec_file}
97
+ Version file: #{@version_file}
98
+ Use git: #{@use_git}
99
+ Package dir: #{@pkg_dir}
100
+ Files: #{gemspec.files.join("\n#{spacer}")}
101
+ Built gems: #{Dir[@pkg_dir + '/*.gem'].join("\n#{spacer}")}
102
+ # using Buildar #{Buildar.version}
103
+ EOF
104
+ puts
105
+ end
115
106
 
116
- def write_version new_version
117
- File.open(self.version_file, 'w') { |f| f.write(new_version) }
107
+ if @version_file
108
+ # tasks :bump_major, :bump_minor, :bump_patch, :bump_build
109
+ # commit the version file if @use_git
110
+ #
111
+ [:major, :minor, :patch, :build].each { |v|
112
+ desc "increment the #{v} number in #{@version_file}"
113
+ namespace :bump do
114
+ task v do
115
+ old_version = self.read_version
116
+ new_version = self.class.bump(v, old_version)
117
+
118
+ puts "bumping #{old_version} to #{new_version}"
119
+ self.write_version new_version
120
+
121
+ if @use_git
122
+ msg = "Buildar version:bump_#{v} to #{new_version}"
123
+ sh "git commit #{@version_file} -m #{msg.inspect}"
124
+ end
125
+ end
126
+ end
127
+ }
128
+ end
118
129
  end
119
130
 
120
- def version_file
121
- File.join(@root, @version_filename)
122
- end
131
+ def define_tasks
132
+ desc "invoke :test and :bump_build conditionally"
133
+ task :pre_build do
134
+ Rake::Task[:test].invoke if Rake::Task.task_defined? :test
135
+ Rake::Task['bump:build'].invoke if @version_file
136
+ end
123
137
 
124
- def available_version
125
- return self.version if @use_version_file
126
- version = self.gemspec.version
127
- raise "gemspec.version is missing" if !version or version.to_s.empty?
128
- version
129
- end
138
+ # can't make this a file task, because the version could be bumped
139
+ # as a dependency, changing the target file
140
+ #
141
+ desc "build a .gem in #{@pkg_dir}/ using `gem build`"
142
+ task :build => :pre_build do
143
+ if @gemspec_file
144
+ sh "gem build #{@gemspec_file}"
145
+ mv File.basename(self.gem_file), self.gem_file
146
+ else
147
+ Rake::Task[:gem_package].invoke
148
+ end
149
+ end
130
150
 
131
- def version_location
132
- @use_version_file ? self.version_filename : self.gemspec_filename
133
- end
151
+ # roughly equivalent to `gem build self.gemspec`
152
+ # operates with a hard or soft gemspec
153
+ #
154
+ desc "build a .gem in #{@pkg_dir}/ using Gem::PackageTask"
155
+ task :gem_package => :pre_build do
156
+ # definine the task at runtime, rather than requiretime
157
+ # so that the gemspec will reflect any version bumping since requiretime
158
+ require 'rubygems/package_task'
159
+ Gem::PackageTask.new(self.gemspec).define
160
+ Rake::Task["package"].invoke
161
+ end
134
162
 
135
- # where we expect a built gem to land
136
- #
137
- def gemfile
138
- path = File.join(@root, 'pkg', "#{@name}-#{self.available_version}.gem")
139
- raise "gemfile #{path} does not exist" unless File.exists?(path)
140
- path
163
+ # desc "used internally; make sure we have .gem for the current version"
164
+ task :built do
165
+ Rake::Task[:build].invoke unless File.exists? self.gem_file
166
+ end
167
+
168
+ desc "publish the current version to rubygems.org"
169
+ task :publish => :built do
170
+ sh "gem push #{self.gem_file}"
171
+ end
172
+
173
+ desc "build, publish" << (@use_git ? ", tag " : '')
174
+ task :release => [:build, :publish] do
175
+ Rake::Task[:tag].invoke if @use_git
176
+ end
177
+
178
+ desc "install the current version"
179
+ task :install => :built do
180
+ sh "gem install #{self.gem_file}"
181
+ end
182
+
183
+ desc "build a new version and install"
184
+ task :install_new => [:build, :install]
185
+
186
+ #
187
+ # Optional tasks
188
+ #
189
+
190
+ if @version_file
191
+ [:major, :minor, :patch].each { |v|
192
+ namespace :release do
193
+ desc "increment the #{v} number and release"
194
+ task v => ["bump:#{v}", :release]
195
+ end
196
+ }
197
+ end
198
+
199
+ if @use_git
200
+ desc "annotated git tag with version and message"
201
+ task :tag => :message do
202
+ Rake::Task[:test].invoke if Rake::Task.defined? :test
203
+ tagname = "v#{self.gemspec.version}"
204
+ message = ENV['message'] || "auto-tagged #{tagname} by Buildar"
205
+ sh "git tag -a #{tagname.inspect} -m #{message.inspect}"
206
+ sh "git push origin --tags"
207
+ end
208
+
209
+ # right now only :tag depends on this, but maybe others in the future?
210
+ # desc "used internally; make sure ENV['message'] is populated"
211
+ task :message do
212
+ if !ENV['message'] or ENV['message'].empty?
213
+ print "This task requires a message:\n> "
214
+ ENV['message'] = $stdin.gets.chomp
215
+ end
216
+ end
217
+ end
141
218
  end
142
219
  end
data/rakefile.rb CHANGED
@@ -1,14 +1,8 @@
1
- require 'buildar/tasks'
2
- require 'rake/testtask'
1
+ require 'buildar'
3
2
 
4
- Buildar.conf(__FILE__) do |b|
5
- b.name = 'buildar'
6
- b.use_version_file = true
7
- b.version_filename = 'VERSION'
8
- b.use_git = true
9
- b.publish[:rubygems] = true
10
- end
11
-
12
- Rake::TestTask.new :test do |t|
13
- t.pattern = 'test/*.rb'
3
+ Buildar.new do |b|
4
+ b.gemspec_file = 'buildar.gemspec'
5
+ b.version_file = 'VERSION'
6
+ b.use_git = true
7
+ # b.ns = 'gem'
14
8
  end
metadata CHANGED
@@ -1,32 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: buildar
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0.15
5
- prerelease:
4
+ version: 2.0.0.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Rick Hull
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-07-10 00:00:00.000000000 Z
11
+ date: 2013-07-11 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '8'
22
- type: :runtime
23
- prerelease: false
24
20
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
21
  requirements:
27
22
  - - ! '>='
28
23
  - !ruby/object:Gem::Version
29
24
  version: '8'
25
+ type: :runtime
26
+ prerelease: false
30
27
  description: Buildar helps automate the release process with versioning, building,
31
28
  packaging, and publishing. Optional git integration.
32
29
  email:
@@ -40,30 +37,28 @@ files:
40
37
  - README.md
41
38
  - rakefile.rb
42
39
  - lib/buildar.rb
43
- - lib/buildar/tasks.rb
44
40
  homepage: https://github.com/rickhull/buildar
45
41
  licenses:
46
42
  - MIT
43
+ metadata: {}
47
44
  post_install_message:
48
45
  rdoc_options: []
49
46
  require_paths:
50
47
  - lib
51
48
  required_ruby_version: !ruby/object:Gem::Requirement
52
- none: false
53
49
  requirements:
54
50
  - - ! '>='
55
51
  - !ruby/object:Gem::Version
56
52
  version: '0'
57
53
  required_rubygems_version: !ruby/object:Gem::Requirement
58
- none: false
59
54
  requirements:
60
55
  - - ! '>='
61
56
  - !ruby/object:Gem::Version
62
57
  version: '0'
63
58
  requirements: []
64
59
  rubyforge_project:
65
- rubygems_version: 1.8.23
60
+ rubygems_version: 2.0.3
66
61
  signing_key:
67
- specification_version: 3
62
+ specification_version: 4
68
63
  summary: Buildar crept inside your rakefile and scratched upon the tasking post
69
64
  test_files: []
data/lib/buildar/tasks.rb DELETED
@@ -1,141 +0,0 @@
1
- require 'buildar'
2
-
3
- # shortcut to Buildar's data from the project rakefile
4
- #
5
- def proj
6
- Buildar.instance
7
- end
8
-
9
- # the reason you're here
10
- #
11
- task :release => [:message, :build, :tag, :publish]
12
-
13
- # these are handy
14
- #
15
- task :release_patch => [:bump_patch, :release]
16
- task :release_minor => [:bump_minor, :release]
17
- task :release_major => [:bump_major, :release]
18
-
19
- # make sure ENV['message'] is populated
20
- #
21
- task :message do
22
- if !ENV['message'] or ENV['message'].empty?
23
- print "This task requires a message:\n> "
24
- ENV['message'] = $stdin.gets.chomp
25
- end
26
- end
27
-
28
- # uses Gem::PackageTask to build via Gem API
29
- # roughly equivalent to `gem build foo.gemspec`
30
- # operates with a hard or soft gemspec
31
- #
32
- task :gem_package => [:test, :bump_build] do
33
- # definine the task at runtime, rather than requiretime
34
- # so that the gemspec will reflect any version bumping since requiretime
35
- require 'rubygems/package_task'
36
- Gem::PackageTask.new(proj.gemspec).define
37
- Rake::Task["package"].invoke
38
- end
39
-
40
- # if proj.use_gemspec_file
41
- # exactly equiavlent to `gem build #{proj.gemspec_filename}`
42
- # otherwise fall back to :gem_package
43
- #
44
- task :build => [:test, :bump_build] do
45
- if proj.use_gemspec_file
46
- sh "gem build #{proj.gemspec_filename}"
47
- target_file = "#{proj.name}-#{proj.available_version}.gem"
48
- if File.exists? target_file
49
- sh "mv #{target_file} pkg/#{target_file}"
50
- else
51
- puts "warning: expected #{target_file} but didn't find it"
52
- end
53
- else
54
- Rake::Task[:gem_package].invoke
55
- end
56
- end
57
-
58
- # build, install
59
- #
60
- task :install => [:build] do
61
- sh "gem install #{proj.gemfile}"
62
- end
63
-
64
- # if proj.use_version_file
65
- # tasks :bump_major, :bump_minor, :bump_patch, :bump_build
66
- # commit the version file if proj.use_git
67
- #
68
- [:major, :minor, :patch, :build].each { |v|
69
- task "bump_#{v}" do
70
- if proj.use_version_file
71
- old_version = proj.version
72
- new_version = Buildar.bump(v, old_version)
73
- puts "bumping #{old_version} to #{new_version}"
74
- proj.write_version new_version
75
- if proj.use_git
76
- msg = "rake bump_#{v} to #{new_version}"
77
- sh "git commit #{proj.version_file} -m '#{msg}'"
78
- end
79
- end
80
- end
81
- }
82
-
83
- # if proj.use_git
84
- # create annotated git tag based on VERSION and ENV['message'] if available
85
- # push tags to origin
86
- #
87
- task :tag => [:test] do
88
- if proj.use_git
89
- tagname = "v#{proj.available_version}"
90
- message = ENV['message'] || "auto-tagged #{tagname} by Rake"
91
- sh %Q{git tag -a "#{tagname}" -m "#{message}"}
92
- sh "git push origin --tags"
93
- end
94
- end
95
-
96
- # if proj.publish[:rubygems]
97
- # roughly, gem push foo-VERSION.gem
98
- #
99
- task :publish => [:verify_publish_credentials] do
100
- sh "gem push #{proj.gemfile}" if proj.publish[:rubygems]
101
- end
102
-
103
- # if proj.publish[:rubygems]
104
- # just make sure the ~/.gem/credentials file is readable
105
- #
106
- task :verify_publish_credentials do
107
- if proj.publish[:rubygems]
108
- creds = '~/.gem/credentials'
109
- fp = File.expand_path(creds)
110
- raise "#{creds} does not exist" unless File.exists?(fp)
111
- raise "can't read #{creds}" unless File.readable?(fp)
112
- end
113
- end
114
-
115
- # display project name and version
116
- #
117
- task :version do
118
- puts "#{proj.name} #{proj.available_version}"
119
- end
120
-
121
- # if the user wants a bump, make it a patch; not used internally
122
- #
123
- task :bump => [:bump_patch]
124
-
125
- # config check
126
- #
127
- task :buildar do
128
- puts
129
- puts <<EOF
130
- Project: #{proj.name} #{proj.version}
131
- Root: #{proj.root}
132
- Use gemspec file: #{proj.use_gemspec_file}
133
- Gemspec source: #{proj.gemspec_location}
134
- Use version file: #{proj.use_version_file}
135
- Version source: #{proj.version_location}
136
- Use git: #{proj.use_git}
137
- Publish: #{proj.publish.keys}
138
- # using Buildar #{Buildar.version}
139
- EOF
140
- puts
141
- end