buildar 0.3.2.2 → 1.0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/MANIFEST.txt +2 -0
  2. data/VERSION +1 -1
  3. data/lib/buildar.rb +114 -0
  4. data/lib/buildar/tasks.rb +114 -0
  5. data/rakefile.rb +14 -198
  6. metadata +25 -6
@@ -1,3 +1,5 @@
1
1
  MANIFEST.txt
2
2
  VERSION
3
3
  rakefile.rb
4
+ lib/buildar.rb
5
+ lib/buildar/tasks.rb
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.2.2
1
+ 1.0.0.1
@@ -0,0 +1,114 @@
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/raketasks.
5
+ # So we need a global. But if we use a class-based singleton, it's namespaced.
6
+ # And it can't be set to nil, for example.
7
+ #
8
+ class Buildar
9
+ # Call this from the rakefile, like:
10
+ # Buildar.conf(__FILE__) do |b|
11
+ # b.name = 'foo'
12
+ # # ...
13
+ # end
14
+ #
15
+ def self.conf(rakefile = nil)
16
+ unless defined?(@@instance)
17
+ args = rakefile ? [File.dirname(rakefile)] : []
18
+ @@instance = Buildar.new(*args)
19
+ end
20
+ yield @@instance if block_given?
21
+ end
22
+
23
+ # Confirming singleton.
24
+ # Only buildar/raketasks should need to call this
25
+ # Use conf inside project/Rakefile
26
+ #
27
+ def self.instance
28
+ raise "no instance; call Buildar.conf" unless defined?(@@instance)
29
+ @@instance
30
+ end
31
+
32
+ # e.g. bump(:minor, '1.2.3') #=> '1.3.0'
33
+ # only works for versions consisting of integers delimited by periods (dots)
34
+ #
35
+ def self.bump(position, version)
36
+ pos = [:major, :minor, :patch, :build].index(position) || position
37
+ places = version.split('.')
38
+ if pos >= places.length and pos <= places.length + 2
39
+ # add zeroes to places up to pos
40
+ # allows bump(:build, '0') #=> '0.0.0.1'
41
+ places.length.upto(pos) { |i| places[i] = 0 }
42
+ end
43
+ raise "bad position: #{pos} (for version #{version})" unless places[pos]
44
+ places.map.with_index { |place, i|
45
+ if i < pos
46
+ place
47
+ elsif i == pos
48
+ place.to_i + 1
49
+ else
50
+ 0
51
+ end
52
+ }.join('.')
53
+ end
54
+
55
+ attr_accessor :root, :version_filename, :manifest_filename,
56
+ :use_git, :publish, :use_manifest_file
57
+ attr_reader :name
58
+
59
+ def initialize(root = nil, name = nil)
60
+ @root = root ? File.expand_path(root) : Dir.pwd
61
+ @name = name || File.split(@root).last
62
+ @version_filename = 'VERSION'
63
+ @use_manifest_file = true
64
+ @manifest_filename = 'MANIFEST.txt'
65
+ @use_git = true
66
+ @publish = { rubygems: true }
67
+ end
68
+
69
+ # previously, we did this in initialize
70
+ # now, give conf a chance to fix things up before calling self.version etc.
71
+ #
72
+ def gemspec
73
+ @gemspec ||= Gem::Specification.new do |s|
74
+ # Static assignments
75
+ s.summary = "FIX"
76
+ s.description = "FIX"
77
+ s.authors = ["FIX"]
78
+ s.email = "FIX@FIX.COM"
79
+ s.homepage = "http://FIX.COM/"
80
+ s.licenses = ['FIX']
81
+ # s.has_rdoc = true
82
+ # s.test_files = ['FIX']
83
+
84
+ s.add_development_dependency "minitest", [">= 0"]
85
+ s.add_development_dependency "rake", [">= 0"]
86
+ s.add_development_dependency "buildar", ["> 0.4"]
87
+ end
88
+ # Make sure things tracked elsewhere stay updated
89
+ @gemspec.name = @name
90
+ @gemspec.files = self.manifest if @use_manifest_file
91
+ @gemspec.version = self.version
92
+ @gemspec
93
+ end
94
+
95
+ def version_file
96
+ File.join(@root, @version_filename)
97
+ end
98
+
99
+ def version
100
+ File.read(self.version_file).chomp
101
+ end
102
+
103
+ def write_version new_version
104
+ File.open(self.version_file, 'w') { |f| f.write(new_version) }
105
+ end
106
+
107
+ def manifest_file
108
+ File.join(@root, @manifest_filename)
109
+ end
110
+
111
+ def manifest
112
+ File.readlines(self.manifest_file).map { |line| line.chomp }
113
+ end
114
+ end
@@ -0,0 +1,114 @@
1
+ require 'buildar'
2
+ require 'rubygems/package_task'
3
+
4
+ # shortcut to Buildar's data from the project rakefile
5
+ #
6
+ def proj
7
+ Buildar.instance
8
+ end
9
+
10
+ # the reason you're here
11
+ #
12
+ task :release => [:message, :build, :tag, :publish]
13
+
14
+ # these are handy
15
+ #
16
+ task :release_patch => [:bump_patch, :release]
17
+ task :release_minor => [:bump_minor, :release]
18
+ task :release_major => [:bump_major, :release]
19
+
20
+ # make sure ENV['message'] is populated
21
+ #
22
+ task :message do
23
+ unless ENV['message']
24
+ print "Enter a one-line message:\n> "
25
+ ENV['message'] = $stdin.gets.chomp
26
+ end
27
+ end
28
+
29
+ # roughly equivalent to `gem build foo.gemspec`
30
+ # places .gem file in pkg/
31
+ #
32
+ task :build => [: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
+ Gem::PackageTask.new(proj.gemspec).define
36
+ Rake::Task["package"].invoke
37
+ end
38
+
39
+ # tasks :bump_major, :bump_minor, :bump_patch, :bump_build
40
+ # commit the version file if proj.use_git
41
+ #
42
+ [:major, :minor, :patch, :build].each { |v|
43
+ task "bump_#{v}" do
44
+ old_version = proj.version
45
+ new_version = Buildar.bump(v, old_version)
46
+ puts "bumping #{old_version} to #{new_version}"
47
+ proj.write_version new_version
48
+ if proj.use_git
49
+ msg = "rake bump_#{v} to #{new_version}"
50
+ sh "git commit #{proj.version_file} -m '#{msg}'"
51
+ end
52
+ end
53
+ }
54
+
55
+ # if proj.use_git:
56
+ # create annotated git tag based on VERSION and ENV['message'] if available
57
+ # push tags to origin
58
+ #
59
+ task :tag => [:test] do
60
+ if proj.use_git
61
+ tagname = "v#{proj.version}"
62
+ message = ENV['message'] || "auto-tagged #{tagname} by Rake"
63
+ sh "git tag -a '#{tagname}' -m '#{message}'"
64
+ sh "git push origin --tags"
65
+ end
66
+ end
67
+
68
+ # roughly, gem push foo-VERSION.gem
69
+ #
70
+ task :publish => [:verify_publish_credentials] do
71
+ if proj.publish[:rubygems]
72
+ fragment = "-#{proj.version}.gem"
73
+ pkg_dir = File.join(proj.root, 'pkg')
74
+ Dir.chdir(pkg_dir) {
75
+ candidates = Dir.glob "*#{fragment}"
76
+ # sanity check
77
+ case candidates.length
78
+ when 0
79
+ raise "could not find .gem matching #{fragment}"
80
+ when 1
81
+ sh "gem push #{candidates.first}"
82
+ else
83
+ raise "multiple candidates found matching #{fragment}"
84
+ end
85
+ }
86
+ end
87
+ end
88
+
89
+ # just make sure the ~/.gem/credentials file is readable
90
+ #
91
+ task :verify_publish_credentials do
92
+ if proj.publish[:rubygems]
93
+ creds = '~/.gem/credentials'
94
+ fp = File.expand_path(creds)
95
+ raise "#{creds} does not exist" unless File.exists?(fp)
96
+ raise "can't read #{creds}" unless File.readable?(fp)
97
+ end
98
+ end
99
+
100
+ # display project name and version
101
+ #
102
+ task :version do
103
+ puts "#{proj.name} #{proj.version}"
104
+ end
105
+
106
+ # display Buildar's understanding of the manifest file
107
+ #
108
+ task :manifest do
109
+ puts proj.manifest.join("\n") if proj.use_manifest_file
110
+ end
111
+
112
+ # if the user wants a bump, make it a patch
113
+ #
114
+ task :bump => [:bump_patch]
@@ -1,204 +1,20 @@
1
- require 'rubygems/package_task'
1
+ require 'buildar/tasks'
2
2
  require 'rake/testtask'
3
3
 
4
- module Buildar
5
- ##############################################
6
- # Project-specific settings. Edit as needed.
7
- #
8
- #
9
- PROJECT_ROOT = File.dirname(__FILE__)
10
- PROJECT_NAME = File.split(PROJECT_ROOT).last
11
- VERSION_FILE = File.join(PROJECT_ROOT, 'VERSION')
12
- MANIFEST_FILE = File.join(PROJECT_ROOT, 'MANIFEST.txt')
13
-
14
- USE_GIT = true
15
- GIT_COMMIT_VERSION = true # commit version bump automatically
16
- PUBLISH = {
17
- rubygems: true, # publish .gem to http://rubygems.org/
18
- }
19
-
20
- def self.gemspec
21
- Gem::Specification.new do |s|
22
- # Static assignments
23
- s.name = PROJECT_NAME
24
- s.summary = "FIX"
25
- s.description = "FIX"
26
- s.authors = ["FIX"]
27
- s.email = "FIX@FIX.COM"
28
- s.homepage = "http://FIX.COM/"
29
- s.licenses = ['FIX']
30
- s.has_rdoc = true
31
- # s.test_files = ['FIX']
32
-
33
- # Dynamic assignments
34
- s.files = manifest
35
- s.version = version
36
- # s.date = Time.now.strftime("%Y-%m-%d")
37
-
38
- # s.add_runtime_dependency "rest-client", ["~> 1"]
39
- # s.add_runtime_dependency "json", ["~> 1"]
40
- s.add_development_dependency "minitest", [">= 0"]
41
- s.add_development_dependency "rake", [">= 0"]
42
- end
43
- end
44
- #
45
- #
46
- # End project-specific settings.
47
- ################################
48
-
49
- def self.version
50
- File.read(VERSION_FILE).chomp
51
- end
52
-
53
- def self.manifest
54
- File.readlines(MANIFEST_FILE).map { |line| line.chomp }
55
- end
56
-
57
- def self.write_version new_version
58
- File.open(VERSION_FILE, 'w') { |f| f.write(new_version) }
59
- end
60
-
61
- # e.g. bump(:minor, '1.2.3') #=> '1.3.0'
62
- # only works for versions consisting of integers delimited by periods (dots)
63
- #
64
- def self.bump(position, version)
65
- pos = [:major, :minor, :patch, :build].index(position) || position
66
- places = version.split('.')
67
- if pos >= places.length and pos <= places.length + 2
68
- # add zeroes to places up to pos
69
- # allows bump(:build, '0') #=> '0.0.0.1'
70
- places.length.upto(pos) { |i| places[i] = 0 }
71
- end
72
- raise "bad position: #{pos} (for version #{version})" unless places[pos]
73
- places.map.with_index { |place, i|
74
- if i < pos
75
- place
76
- elsif i == pos
77
- place.to_i + 1
78
- else
79
- 0
80
- end
81
- }.join('.')
82
- end
4
+ Buildar.conf(__FILE__) do |b|
5
+ b.version_filename = 'VERSION'
6
+ b.manifest_filename = 'MANIFEST.txt'
7
+ b.use_git = true
8
+ b.publish[:rubygems] = true
9
+ b.gemspec.name = 'buildar'
10
+ b.gemspec.summary = 'Buildar crept inside your rakefile and scratched some tasks'
11
+ b.gemspec.description = 'Buildar helps automate the release process with versioning, building, packaging, and publishing. Optional git integration'
12
+ b.gemspec.author = 'Rick Hull'
13
+ b.gemspec.homepage = 'https://github.com/rickhull/buildar'
14
+ b.gemspec.license = 'MIT'
15
+ b.gemspec.has_rdoc = true
83
16
  end
84
17
 
85
-
86
- #######
87
- # Tasks
88
- #
89
- #
90
-
91
- # i.e. task :test, runs your test files
92
- #
93
18
  Rake::TestTask.new :test do |t|
94
- t.pattern = 'test/*.rb' # FIX for your layout
95
- end
96
-
97
- # display project name and version
98
- #
99
- task :version do
100
- puts "#{Buildar::PROJECT_NAME} #{Buildar.version}"
101
- end
102
-
103
- # make sure ENV['message'] is populated
104
- #
105
- task :message do
106
- unless ENV['message']
107
- print "Enter a one-line message:\n> "
108
- ENV['message'] = $stdin.gets.chomp
109
- end
110
- end
111
-
112
- # if USE_GIT:
113
- # create annotated git tag based on VERSION and ENV['message'] if available
114
- # push tags to origin
115
- #
116
- task :tag => [:test] do
117
- if Buildar::USE_GIT
118
- message = ENV['message'] || "auto-tagged #{tagname} by Rake"
119
- sh "git tag -a 'v#{Buildar.version}' -m '#{message}'"
120
- sh "git push origin --tags"
121
- end
19
+ t.pattern = 'test/*.rb'
122
20
  end
123
-
124
- # display Buildar's understanding of the MANIFEST.txt file
125
- #
126
- task :manifest do
127
- puts Buildar.manifest.join("\n")
128
- end
129
-
130
- # roughly equivalent to `gem build foo.gemspec`
131
- # places .gem file in pkg/
132
- #
133
- task :build => [:test, :bump_build] do
134
- # definine the task at runtime, rather than requiretime
135
- # so that the gemspec will reflect any version bumping since requiretime
136
- #
137
- Gem::PackageTask.new(Buildar.gemspec).define
138
- Rake::Task["package"].invoke
139
- end
140
-
141
- # e.g. task :bump_build, with VERSION 1.2.3.4, updates VERSION to 1.2.3.5
142
- # if USE_GIT and GIT_COMMIT_VERSION: add VERSION and commit
143
- #
144
- [:major, :minor, :patch, :build].each { |v|
145
- task "bump_#{v}" do
146
- old_version = Buildar.version
147
- new_version = Buildar.bump(v, old_version)
148
- puts "bumping #{old_version} to #{new_version}"
149
- Buildar.write_version new_version
150
- if Buildar::USE_GIT and Buildar::GIT_COMMIT_VERSION
151
- msg = "rake bump_#{v} to #{new_version}"
152
- sh "git commit #{Buildar::VERSION_FILE} -m '#{msg}'"
153
- end
154
- end
155
- }
156
-
157
- # not used internally, but if the user wants a bump, make it a patch
158
- #
159
- task :bump => [:bump_patch]
160
-
161
- # just make sure the ~/.gem/credentials file is readable
162
- #
163
- task :verify_publish_credentials do
164
- if Buildar::PUBLISH[:rubygems]
165
- creds = '~/.gem/credentials'
166
- fp = File.expand_path(creds)
167
- raise "#{creds} does not exist" unless File.exists?(fp)
168
- raise "can't read #{creds}" unless File.readable?(fp)
169
- end
170
- end
171
-
172
-
173
- # roughly, gem push foo-VERSION.gem
174
- #
175
- task :publish => [:verify_publish_credentials] do
176
- if Buildar::PUBLISH[:rubygems]
177
- fragment = "-#{Buildar.version}.gem"
178
- pkg_dir = File.join(Buildar::PROJECT_ROOT, 'pkg')
179
- Dir.chdir(pkg_dir) {
180
- candidates = Dir.glob "*#{fragment}"
181
- case candidates.length
182
- when 0
183
- raise "could not find .gem matching #{fragment}"
184
- when 1
185
- sh "gem push #{candidates.first}"
186
- else
187
- raise "multiple candidates found matching #{fragment}"
188
- end
189
- }
190
- end
191
- end
192
-
193
- # if USE_GIT: git push origin
194
- #
195
- task :gitpush do
196
- # may prompt
197
- sh "git push origin" if Buildar::USE_GIT
198
- end
199
-
200
- task :release => [:message, :build, :tag, :publish, :gitpush]
201
-
202
- task :release_patch => [:bump_patch, :release]
203
- task :release_minor => [:bump_minor, :release]
204
- task :release_major => [:bump_major, :release]
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: buildar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2.2
4
+ version: 1.0.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
- - FIX
8
+ - Rick Hull
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
@@ -43,7 +43,24 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
- description: FIX
46
+ - !ruby/object:Gem::Dependency
47
+ name: buildar
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>'
52
+ - !ruby/object:Gem::Version
53
+ version: '0.4'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>'
60
+ - !ruby/object:Gem::Version
61
+ version: '0.4'
62
+ description: Buildar helps automate the release process with versioning, building,
63
+ packaging, and publishing. Optional git integration
47
64
  email: FIX@FIX.COM
48
65
  executables: []
49
66
  extensions: []
@@ -52,9 +69,11 @@ files:
52
69
  - MANIFEST.txt
53
70
  - VERSION
54
71
  - rakefile.rb
55
- homepage: http://FIX.COM/
72
+ - lib/buildar.rb
73
+ - lib/buildar/tasks.rb
74
+ homepage: https://github.com/rickhull/buildar
56
75
  licenses:
57
- - FIX
76
+ - MIT
58
77
  post_install_message:
59
78
  rdoc_options: []
60
79
  require_paths:
@@ -76,5 +95,5 @@ rubyforge_project:
76
95
  rubygems_version: 1.8.23
77
96
  signing_key:
78
97
  specification_version: 3
79
- summary: FIX
98
+ summary: Buildar crept inside your rakefile and scratched some tasks
80
99
  test_files: []