rake-deveiate 0.15.1 → 0.17.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0fd5ebf2ecae73378b090addfcda377b8f6eaa034d4c7a3ad39de0649701c5fe
4
- data.tar.gz: 22b38e5878db4fd78e4cbc5a0bcbff0813812d4a57ed236fbaf00ae60d1c9794
3
+ metadata.gz: de2405bf5083d92c729274fd014c28dde7cee3ceca67e503f6a3d229630af493
4
+ data.tar.gz: ae2704b280ccb8556146e404b70199dbdee7c892fbfd2903f83d80fa085fea9f
5
5
  SHA512:
6
- metadata.gz: 715be431cafef4db394efc1740b35bbb61d8df3f53b850837a66d82ca9d2cb0095bf2c88ad8b93316600ca00b6769060b9cf7b635ee032896bac48709935e0b1
7
- data.tar.gz: f172e22901d23884594f6703dec21f3af5976aa67460a9e062323578f5987680e2edbdb196f6d37cc4f227df72552922702cb30737d4f757d79a01241325fe88
6
+ metadata.gz: f617162a43c43b1a7206ab225c7481768f7a11d1397fa4bcd5ceb90f52415c4cc9aa7b5d3a7f00b625e4118a0c4808b258222e8e11fad58e210a76608d4cdfb3
7
+ data.tar.gz: 21c03296ab75a4fc0b18946ac34d38cb267f37079e0c4ad2cfb7e1048e4f0b5844f6d6fec01d6690d527b07c896ce5bdc1d7ecab3981d327ebadc565bd2f9b72
Binary file
data.tar.gz.sig CHANGED
Binary file
data/History.md CHANGED
@@ -1,6 +1,42 @@
1
1
  # Release History for rake-deveiate
2
2
 
3
3
  ---
4
+
5
+ ## v0.17.1 [2020-12-28] Michael Granger <ged@FaerieMUD.org>
6
+
7
+ Bugfixes:
8
+
9
+ - Update hglib dependency
10
+
11
+
12
+ ## v0.17.0 [2020-12-28] Michael Granger <ged@FaerieMUD.org>
13
+
14
+ Improvements:
15
+
16
+ - Allow multi-level extension directory structure.
17
+
18
+
19
+ ## v0.16.2 [2020-11-23] Michael Granger <ged@FaerieMUD.org>
20
+
21
+ Bugfixes:
22
+
23
+ - Include another missing file.
24
+
25
+
26
+ ## v0.16.1 [2020-11-23] Michael Granger <ged@FaerieMUD.org>
27
+
28
+ Bugfixes:
29
+
30
+ - Include missing `git` tasklib.
31
+
32
+
33
+ ## v0.16.0 [2020-11-23] Michael Granger <ged@FaerieMUD.org>
34
+
35
+ Improvements:
36
+
37
+ - Add support for projects managed with Git.
38
+
39
+
4
40
  ## v0.15.1 [2020-10-29] Michael Granger <ged@FaerieMUD.org>
5
41
 
6
42
  Bugfixes:
@@ -35,7 +35,7 @@ class Rake::DevEiate < Rake::TaskLib
35
35
  VERSION_PATTERN = /VERSION\s*=\s*(?<quote>['"])(?<version>\d+(\.\d+){2}.*)\k<quote>/
36
36
 
37
37
  # The version of this library
38
- VERSION = '0.15.1'
38
+ VERSION = '0.17.1'
39
39
 
40
40
  # The server to release to by default
41
41
  DEFAULT_GEMSERVER = 'https://rubygems.org/'
@@ -46,6 +46,9 @@ class Rake::DevEiate < Rake::TaskLib
46
46
  # The version to use if one cannot be read from the source
47
47
  DEFAULT_VERSION = '0.1.0'
48
48
 
49
+ # The prefix to use for release version tags by default
50
+ DEFAULT_RELEASE_TAG_PREFIX = 'v'
51
+
49
52
  # Words in the package/gem name that should not be included in deriving paths,
50
53
  # file names, etc.
51
54
  PACKAGE_IGNORE_WORDS = %w[ruby]
@@ -158,6 +161,7 @@ class Rake::DevEiate < Rake::TaskLib
158
161
  @licenses = [ DEFAULT_LICENSE ]
159
162
  @version_from = env( :version_from, as_pathname: true ) ||
160
163
  LIB_DIR + "%s.rb" % [ version_file_from(name) ]
164
+ @release_tag_prefix = DEFAULT_RELEASE_TAG_PREFIX
161
165
 
162
166
  @docs_dir = DOCS_DIR.dup
163
167
 
@@ -289,6 +293,10 @@ class Rake::DevEiate < Rake::TaskLib
289
293
  # The version of Ruby required by this gem, in Gem version format.
290
294
  attr_accessor :required_ruby_version
291
295
 
296
+ ##
297
+ # The prefix to use for version tags
298
+ attr_accessor :release_tag_prefix
299
+
292
300
 
293
301
  #
294
302
  # Task definition
@@ -372,6 +380,11 @@ class Rake::DevEiate < Rake::TaskLib
372
380
  self.install_dependencies
373
381
  end
374
382
 
383
+ desc "Turn on maintainer mode: build with extra warnings and debugging"
384
+ task :maint do
385
+ ENV['MAINTAINER_MODE'] = 'yes'
386
+ end
387
+
375
388
  end
376
389
 
377
390
 
@@ -532,6 +545,24 @@ class Rake::DevEiate < Rake::TaskLib
532
545
  end
533
546
 
534
547
 
548
+ ### Return a Regexp that matches the project's convention for versions.
549
+ def release_tag_pattern
550
+ prefix = self.release_tag_prefix
551
+ return /#{prefix}\d+(\.\d+)+/
552
+ end
553
+
554
+
555
+ ### Fetch the list of the versions of releases that have entries in the history
556
+ ### file.
557
+ def get_history_file_versions
558
+ tag_pattern = self.release_tag_pattern
559
+
560
+ return IO.readlines( self.history_file ).grep( tag_pattern ).map do |line|
561
+ line[ /^(?:h\d\.|#+|=+)\s+(#{tag_pattern})\s+/, 1 ]
562
+ end.compact
563
+ end
564
+
565
+
535
566
  ### Returns +true+ if the manifest file exists and is readable.
536
567
  def has_manifest?
537
568
  return self.manifest_file.readable?
@@ -665,6 +696,7 @@ class Rake::DevEiate < Rake::TaskLib
665
696
 
666
697
  ### Install the gems listed in the gem dependencies file.
667
698
  def install_dependencies
699
+ self.prompt.say "Installing dependencies"
668
700
  ruby '-S', 'gem', 'i', '-Ng'
669
701
  end
670
702
 
@@ -744,9 +776,9 @@ class Rake::DevEiate < Rake::TaskLib
744
776
  self.prompt.say( "Summary: " )
745
777
  self.prompt.say( summary, color: :bold )
746
778
  self.prompt.say( "Description:" )
747
- self.prompt.say( description, color: :bold )
779
+ self.prompt.say( " " + description, color: :bold )
748
780
  self.prompt.say( "Homepage:" )
749
- self.prompt.say( homepage, color: :bold )
781
+ self.prompt.say( " " + homepage, color: :bold )
750
782
  self.prompt.say( "\n" )
751
783
  end
752
784
 
@@ -824,4 +856,29 @@ class Rake::DevEiate < Rake::TaskLib
824
856
  join( '/' )
825
857
  end
826
858
 
859
+
860
+ ### Delete the files in the given +filelist+ after confirming with the user.
861
+ def delete_extra_files( *filelist )
862
+ description = humanize_file_list( filelist, ' ' )
863
+ self.prompt.say "Files to delete:"
864
+ self.prompt.say( description )
865
+
866
+ if self.prompt.yes?( "Really delete them?" ) {|q| q.default(false) }
867
+ filelist.each do |f|
868
+ rm_rf( f, verbose: true )
869
+ end
870
+ end
871
+ end
872
+
873
+
874
+ ### Returns a human-scannable file list by joining and truncating the list if it's too long.
875
+ def humanize_file_list( list, indent=FILE_INDENT )
876
+ listtext = list[0..5].join( "\n#{indent}" )
877
+ if list.length > 5
878
+ listtext << " (and %d other/s)" % [ list.length - 5 ]
879
+ end
880
+
881
+ return listtext
882
+ end
883
+
827
884
  end # class Rake::DevEiate
@@ -74,10 +74,14 @@ module Rake::DevEiate::Extension
74
74
 
75
75
  require 'rake/extensiontask'
76
76
  self.extensions.each do |extconf|
77
- Rake::ExtensionTask.new( extconf.pathmap('%-1d') )
77
+ Rake::ExtensionTask.new( extconf.pathmap('%{ext,}d') )
78
78
  end
79
79
 
80
80
  task :spec => :compile
81
+
82
+ task :maint do
83
+ ENV['V'] = 1
84
+ end
81
85
  end
82
86
 
83
87
 
@@ -89,20 +93,21 @@ module Rake::DevEiate::Extension
89
93
  end
90
94
 
91
95
 
92
-
93
96
  ### Task function -- output debugging for extension tasks.
94
97
  def do_extensions_debug( task, args )
95
98
  self.prompt.say( "Extension config scripts:", color: :bright_green )
96
99
 
97
100
  if self.extensions.empty?
98
- self.prompt.say( "None." )
101
+ self.prompt.say "None."
99
102
  else
100
- self.extensions.each do |path|
103
+ self.extensions.uniq.each do |path|
101
104
  self.prompt.say "- %s" % [ path ]
102
105
  end
103
106
  end
104
107
 
105
108
  if self.has_rakecompiler_dependency?
109
+ self.prompt.say "\n"
110
+ self.prompt.say "✔ has rake-compiler dependency"
106
111
  end
107
112
 
108
113
  self.prompt.say( "\n" )
@@ -204,6 +204,10 @@ module Rake::DevEiate::Gemspec
204
204
  bt_uri = source_uri.dup
205
205
  bt_uri.host = 'todo.sr.ht'
206
206
  metadata['bug_tracker_uri'] = bt_uri.to_s
207
+ when /\.gitlab\.com/
208
+ bt_uri = source_uri.dup
209
+ bt_uri.path += '-/issues'
210
+ metadata['bug_tracker_uri'] = bt_uri.to_s
207
211
  else
208
212
  self.trace "No idea what bug tracker URIs for %s look like!" % [ source_uri.host ]
209
213
  end
@@ -54,11 +54,23 @@ module Rake::DevEiate::Generate
54
54
 
55
55
  # Abstract named tasks; mostly for invoking programmatically
56
56
  namespace :generate do
57
+
58
+ desc "Generate a Rakefile"
57
59
  task :rakefile => self.rakefile
60
+
61
+ desc "Generate a %s file" % [ self.readme_file ]
58
62
  task :readme => self.readme_file
63
+
64
+ desc "Generate a %s file" % [ self.history_file ]
59
65
  task :history_file => self.history_file
66
+
67
+ desc "Generate a %s file" % [ self.manifest_file ]
60
68
  task :manifest => self.manifest_file
69
+
70
+ desc "Generate a %s file" % [ RUBY_VERSION_FILE ]
61
71
  task :ruby_version_file => RUBY_VERSION_FILE
72
+
73
+ desc "Generate a %s file" % [ GEMSET_FILE ]
62
74
  task :gemset_file => GEMSET_FILE
63
75
  end
64
76
 
@@ -0,0 +1,28 @@
1
+ # -*- ruby -*-
2
+ # frozen_string_literal: true
3
+
4
+ require 'git'
5
+
6
+ require 'rake/deveiate' unless defined?( Rake::DevEiate )
7
+
8
+
9
+ # Monkeypatches to allow command options the `git` gem doesn't allow.
10
+ #
11
+ # Refs:
12
+ # - https://github.com/ruby-git/ruby-git/issues/394
13
+ module Rake::DevEiate::GitRefinements
14
+
15
+ refine Git::Base do
16
+ def cmd( cmd )
17
+ self.lib.cmd( cmd )
18
+ end
19
+ end
20
+
21
+ refine Git::Lib do
22
+ def cmd( cmd )
23
+ command( cmd )
24
+ end
25
+ end
26
+
27
+ end # module GitRefinements
28
+
@@ -0,0 +1,524 @@
1
+ # -*- ruby -*-
2
+ # frozen_string_literal: true
3
+
4
+ require 'tempfile'
5
+ require 'shellwords'
6
+ require 'git'
7
+ require 'tty/editor'
8
+
9
+ require 'rake/deveiate' unless defined?( Rake::DevEiate )
10
+ require 'rake/deveiate/git-refinements'
11
+
12
+ using Rake::DevEiate::GitRefinements
13
+
14
+
15
+ # Git version-control tasks
16
+ module Rake::DevEiate::Git
17
+
18
+ # The name of the file to edit for the commit message
19
+ COMMIT_MSG_FILE = Pathname( 'commit-msg.txt' )
20
+
21
+ # The name of the ignore file
22
+ IGNORE_FILE = Rake::DevEiate::PROJECT_DIR + '.gitignore'
23
+
24
+ # Colors for presenting file statuses
25
+ STATUS_COLORS = {
26
+ 'M' => [:blue], # modified
27
+ 'A' => [:bold, :green], # added
28
+ 'R' => [:bold, :black], # removed
29
+ 'C' => [:white], # clean
30
+ '!' => [:bold, :white, :on_red], # missing
31
+ '?' => [:yellow], # not tracked
32
+ 'I' => [:dim, :white], # ignored
33
+ }
34
+
35
+ # File indentation
36
+ FILE_INDENT = " • "
37
+
38
+
39
+ ### Define version-control tasks
40
+ def define_tasks
41
+ super if defined?( super )
42
+
43
+ return unless self.is_git_working_copy?
44
+
45
+ # :TODO: Should be refactored up with the same code in the hg lib.
46
+ file COMMIT_MSG_FILE.to_s do |task|
47
+ commit_log = Pathname( task.name )
48
+
49
+ edit_git_commit_log( commit_log )
50
+ unless commit_log.size?
51
+ self.prompt.error "Empty commit message; aborting."
52
+ commit_log.unlink if commit_log.exist?
53
+ abort
54
+ end
55
+ end
56
+
57
+ CLEAN.include( COMMIT_MSG_FILE.to_s )
58
+
59
+ namespace :git do
60
+
61
+ desc "Prepare for a new release"
62
+ task( :prerelease, &method(:do_git_prerelease) )
63
+
64
+ desc "Check for new files and offer to add/ignore/delete them."
65
+ task( :newfiles, &method(:do_git_newfiles) )
66
+ task :add => :newfiles
67
+
68
+ desc "Pull and update from the default repo"
69
+ task( :pull, &method(:do_git_pull) )
70
+
71
+ desc "Pull and update without confirmation"
72
+ task( :pull_without_confirmation, &method(:do_git_pull_without_confirmation) )
73
+
74
+ desc "Update to tip"
75
+ task( :update, &method(:do_git_update) )
76
+
77
+ desc "Clobber all changes (git up -C)"
78
+ task( :update_and_clobber, &method(:do_git_update_and_clobber) )
79
+
80
+ desc "Git-specific pre-checkin hook"
81
+ task :precheckin => [ :pull, :newfiles, :check_for_changes ]
82
+
83
+ desc "Check the current code in if tests pass"
84
+ task( :checkin => COMMIT_MSG_FILE.to_s, &method(:do_git_checkin) )
85
+
86
+ desc "Git-specific pre-release hook"
87
+ task :prerelease => 'git:check_history'
88
+
89
+ desc "Git-specific post-release hook"
90
+ task( :postrelease, &method(:do_git_postrelease) )
91
+
92
+ desc "Push to the default origin repo (if there is one)"
93
+ task( :push, &method(:do_git_push) )
94
+
95
+ desc "Push to the default repo without confirmation"
96
+ task :push_without_confirmation do |task, args|
97
+ self.git.push
98
+ end
99
+
100
+ desc "Check the history file to ensure it contains an entry for each release tag"
101
+ task( :check_history, &method(:do_git_check_history) )
102
+
103
+ desc "Generate and edit a new version entry in the history file"
104
+ task( :update_history, &method(:do_git_update_history) )
105
+
106
+ task( :check_for_changes, &method(:do_git_check_for_changes) )
107
+ task( :debug, &method(:do_git_debug) )
108
+ end
109
+
110
+
111
+ # Hook some generic tasks to the mercurial-specific ones
112
+ task :checkin => 'git:checkin'
113
+ task :precheckin => 'git:precheckin'
114
+
115
+ task :prerelease => 'git:prerelease'
116
+ task :postrelease => 'git:postrelease'
117
+
118
+ desc "Update the history file with the changes since the last version tag."
119
+ task :update_history => 'git:update_history'
120
+
121
+ task :debug => 'git:debug'
122
+ rescue ::Exception => err
123
+ $stderr.puts "%s while defining Git tasks: %s" % [ err.class.name, err.message ]
124
+ raise
125
+ end
126
+
127
+
128
+ ### Returns +true+ if the current directory looks like a Git working copy.
129
+ def is_git_working_copy?
130
+ return File.directory?( '.git' )
131
+ end
132
+
133
+
134
+ ### The body of the git:prerelease task.
135
+ def do_git_prerelease( task, args )
136
+ uncommitted_files = self.git.status( n: true )
137
+ unless uncommitted_files.empty?
138
+ self.show_git_file_statuses( uncommitted_files )
139
+
140
+ fail unless self.prompt.yes?( "Release anyway?" ) do |q|
141
+ q.default( false )
142
+ end
143
+
144
+ self.prompt.warn "Okay, releasing with uncommitted versions."
145
+ end
146
+
147
+ pkg_version_tag = self.current_git_version_tag
148
+ rev = self.git.identity.id
149
+
150
+ # Look for a tag for the current release version, and if it exists abort
151
+ if self.git.tags.find {|tag| tag.name == pkg_version_tag }
152
+ self.prompt.error "Version #{self.version} already has a tag."
153
+ fail
154
+ end
155
+
156
+ # Tag the current rev
157
+ self.prompt.ok "Tagging rev %s as %s" % [ rev, pkg_version_tag ]
158
+ self.git.tag( pkg_version_tag, rev: rev )
159
+
160
+ # Sign the tag
161
+ if self.git.extension_enabled?( :gpg )
162
+ if self.prompt.yes?( "Sign %s?" % [pkg_version_tag] )
163
+ self.git.sign( pkg_version_tag, message: "Signing %s" % [pkg_version_tag] )
164
+ end
165
+ end
166
+ end
167
+
168
+
169
+ ### The body of the git:postrelease task.
170
+ def do_git_postrelease( task, args )
171
+ if self.git.status( 'checksum', unknown: true ).any?
172
+ self.prompt.say "Adding release artifacts..."
173
+ self.git.add( 'checksum' )
174
+ self.git.commit( 'checksum', message: "Adding release checksum." )
175
+ end
176
+
177
+ if self.prompt.yes?( "Move released changesets to public phase?" )
178
+ self.prompt.say "Publicising changesets..."
179
+ self.git.phase( public: true )
180
+ end
181
+
182
+ if self.git.extension_enabled?( :topic )
183
+ current_topic = self.git.topic
184
+ if current_topic && self.prompt.yes?( "Clear the current topic (%s)?" %[current_topic] )
185
+ self.git.topic( clear: true )
186
+ end
187
+ end
188
+
189
+ Rake::Task['git:push'].invoke
190
+ end
191
+
192
+
193
+ ### The body of the git:newfiles task.
194
+ def do_git_newfiles( task, args )
195
+ self.prompt.say "Checking for new files..."
196
+ status = self.git.status
197
+
198
+ files_to_add = status.changed.keys
199
+ files_to_ignore = []
200
+ files_to_delete = []
201
+
202
+ status.untracked.each do |path, status_file|
203
+ description = " %s: untracked" % [ path ]
204
+ action = self.prompt.select( description ) do |menu|
205
+ menu.choice "add", :a
206
+ menu.choice "ignore", :i
207
+ menu.choice "skip", :s
208
+ menu.choice "delete", :d
209
+ end
210
+
211
+ case action
212
+ when :a
213
+ files_to_add << path
214
+ when :i
215
+ files_to_ignore << path
216
+ when :d
217
+ files_to_delete << path
218
+ end
219
+ end
220
+
221
+ unless files_to_add.empty?
222
+ $stderr.puts "Adding: %p" % [ files_to_add ]
223
+ self.git.add( files_to_add )
224
+ end
225
+
226
+ unless files_to_ignore.empty?
227
+ git_ignore_files( *files_to_ignore )
228
+ end
229
+
230
+ unless files_to_delete.empty?
231
+ delete_extra_files( *files_to_delete )
232
+ end
233
+ end
234
+
235
+
236
+ ### The body of the git:pull task.
237
+ def do_git_pull( task, args )
238
+ origin = self.git.remote
239
+
240
+ if ( origin_url = origin.url )
241
+ if self.prompt.yes?( "Pull and update from '#{origin_url}'?" )
242
+ self.prompt.say "Fetching..."
243
+ self.git.fetch( 'origin', prune: true )
244
+ self.prompt.say "Pulling..."
245
+ self.git.pull( 'origin', self.git.current_branch )
246
+ end
247
+ else
248
+ trace "Skipping pull: No 'origin' remote."
249
+ end
250
+ end
251
+
252
+
253
+ ### The body of the git:pull_without_confirmation task.
254
+ def do_git_pull_without_confirmation( task, args )
255
+ self.git.pull
256
+ end
257
+
258
+
259
+ ### The body of the git:update task.
260
+ def do_git_update( task, args )
261
+ self.git.pull_update
262
+ end
263
+
264
+
265
+ ### The body of the git:update_and_clobber task.
266
+ def do_git_update_and_clobber( task, args )
267
+ self.git.update( clean: true )
268
+ end
269
+
270
+
271
+ ### The body of the checkin task.
272
+ def do_git_checkin( task, args )
273
+ commit_msg = COMMIT_MSG_FILE.read.strip
274
+
275
+ self.prompt.say( "---", color: :cyan )
276
+ self.prompt.say( commit_msg )
277
+ self.prompt.say( "---", color: :cyan )
278
+
279
+ if self.prompt.yes?( "Continue with checkin?" )
280
+ self.git.commit( COMMIT_MSG_FILE.read )
281
+ rm_f COMMIT_MSG_FILE
282
+ else
283
+ abort
284
+ end
285
+ Rake::Task[ 'git:push' ].invoke
286
+ end
287
+
288
+
289
+ ### The body of the push task.
290
+ def do_git_push( task, args )
291
+ git = self.git
292
+ origin = git.remote
293
+
294
+ if (origin_url = origin.url)
295
+ if self.prompt.yes?( "Push to '#{origin_url}'?" ) {|q| q.default(false) }
296
+ unless git.is_remote_branch?( git.current_branch )
297
+ if self.prompt.yes?( "Create tracking branch?" ) {|q| q.default(true) }
298
+ tracking_branch = "origin/%s" % [ git.current_branch ]
299
+ git.cmd( 'branch', ['-u', tracking_branch] )
300
+ end
301
+ end
302
+
303
+ git.push( 'origin', git.current_branch )
304
+ self.prompt.ok "Done."
305
+ else
306
+ abort
307
+ end
308
+ else
309
+ trace "Skipping push: No 'default' path."
310
+ end
311
+ end
312
+
313
+
314
+ ### Check the history file against the list of release tags in the working copy
315
+ ### and ensure there's an entry for each tag.
316
+ def do_git_check_history( task, args )
317
+ unless self.history_file.readable?
318
+ self.prompt.error "History file is missing or unreadable."
319
+ abort
320
+ end
321
+
322
+ self.prompt.say "Checking history..."
323
+ missing_tags = self.get_git_unhistoried_version_tags
324
+
325
+ unless missing_tags.empty?
326
+ self.prompt.error "%s needs updating; missing entries for tags: %s" %
327
+ [ self.history_file, missing_tags.join(', ') ]
328
+ abort
329
+ end
330
+ end
331
+
332
+
333
+ ### Check the status of the repo and ensure there are outstanding changes. If there
334
+ ### are no changes, abort.
335
+ def do_git_check_for_changes( task, args )
336
+ # :FIXME: Figure out a better way to do this.
337
+ unless self.git.status.any?( &:type )
338
+ self.prompt.error "Working copy is clean."
339
+ abort
340
+ end
341
+ end
342
+
343
+
344
+ ### Generate a new history file entry for the current version.
345
+ def do_git_update_history( task, args ) # Needs refactoring
346
+ unless self.history_file.readable?
347
+ self.prompt.error "History file is missing or unreadable."
348
+ abort
349
+ end
350
+
351
+ version_tag = self.current_git_version_tag
352
+ previous_tag = self.previous_git_version_tag
353
+ self.prompt.say "Updating history for %s..." % [ version_tag ]
354
+
355
+ if self.get_history_file_versions.include?( version_tag )
356
+ self.trace "History file already includes a section for %s" % [ version_tag ]
357
+ abort
358
+ end
359
+
360
+ header, rest = self.history_file.read( encoding: 'utf-8' ).
361
+ split( /(?<=^---)/m, 2 )
362
+
363
+ self.trace "Rest is: %p" % [ rest ]
364
+ if !rest || rest.empty?
365
+ self.prompt.warn "History file needs a header with a `---` marker to support updating."
366
+ self.prompt.say "Adding an auto-generated one."
367
+ rest = header
368
+ header = self.load_and_render_template( 'History.erb', self.history_file )
369
+ end
370
+
371
+ header_char = self.header_char_for( self.history_file )
372
+ ext = self.history_file.extname
373
+ log_entries = if previous_tag
374
+ self.git.log( rev: "#{previous_tag}~-2::" )
375
+ else
376
+ self.git.log
377
+ end
378
+
379
+ Tempfile.create( ['History', ext], encoding: 'utf-8' ) do |tmp_copy|
380
+ tmp_copy.print( header )
381
+ tmp_copy.puts
382
+
383
+ tmp_copy.puts "%s %s [%s] %s" % [
384
+ header_char * 2,
385
+ version_tag,
386
+ Date.today.strftime( '%Y-%m-%d' ),
387
+ self.authors.first,
388
+ ]
389
+
390
+ tmp_copy.puts
391
+ log_entries.each do |entry|
392
+ tmp_copy.puts "- %s" % [ entry.message ]
393
+ end
394
+ tmp_copy.puts
395
+ tmp_copy.puts
396
+
397
+ tmp_copy.print( rest )
398
+ tmp_copy.close
399
+
400
+ TTY::Editor.open( tmp_copy.path )
401
+
402
+ if File.size?( tmp_copy.path )
403
+ cp( tmp_copy.path, self.history_file )
404
+ else
405
+ self.prompt.error "Empty file: aborting."
406
+ end
407
+ end
408
+
409
+ end
410
+
411
+
412
+ ### Show debugging information.
413
+ def do_git_debug( task, args )
414
+ self.prompt.say( "Git Info", color: :bright_green )
415
+
416
+ if self.is_git_working_copy?
417
+ self.prompt.say( "Release tag prefix: " )
418
+ self.prompt.say( self.release_tag_prefix, color: :bold )
419
+
420
+ self.prompt.say( "Version tags:" )
421
+ self.get_git_version_tag_names.each do |tag|
422
+ self.prompt.say( '- ' )
423
+ self.prompt.say( tag, color: :bold )
424
+ end
425
+
426
+ self.prompt.say( "History file versions:" )
427
+ self.get_history_file_versions.each do |tag|
428
+ self.prompt.say( '- ' )
429
+ self.prompt.say( tag, color: :bold )
430
+ end
431
+
432
+ self.prompt.say( "Unhistoried version tags:" )
433
+ self.get_git_unhistoried_version_tags.each do |tag|
434
+ self.prompt.say( '- ' )
435
+ self.prompt.say( tag, color: :bold )
436
+ end
437
+ else
438
+ self.prompt.say( "Doesn't appear to be a Git repository." )
439
+ end
440
+
441
+ self.prompt.say( "\n" )
442
+ end
443
+
444
+ #
445
+ # utility methods
446
+ #
447
+
448
+ ### Return a Git::Repo for the directory rake was invoked in, creating it if
449
+ ### necessary.
450
+ def git
451
+ @git ||= Git.open( Rake::DevEiate::PROJECT_DIR )
452
+ end
453
+
454
+
455
+ ### Given a +status_hash+ like that returned by Git::Repo.status, return a
456
+ ### string description of the files and their status.
457
+ def show_git_file_statuses( statuses )
458
+ lines = statuses.map do |entry|
459
+ status_color = STATUS_COLORS[ entry.status ]
460
+ " %s: %s" % [
461
+ self.pastel.white( entry.path.to_s ),
462
+ self.pastel.decorate( entry.status_description, *status_color ),
463
+ ]
464
+ end
465
+
466
+ self.prompt.say( self.pastel.headline "Uncommitted files:" )
467
+ self.prompt.say( lines.join("\n") )
468
+ end
469
+
470
+
471
+ ### Fetch the name of the current version's tag.
472
+ def current_git_version_tag
473
+ return [ self.release_tag_prefix, self.version ].join
474
+ end
475
+
476
+
477
+ ### Fetch the name of the tag for the previous version.
478
+ def previous_git_version_tag
479
+ return self.get_git_version_tag_names.first
480
+ end
481
+
482
+
483
+ ### Fetch the list of names of tags that match the versioning scheme of this
484
+ ### project.
485
+ def get_git_version_tag_names
486
+ tag_pattern = self.release_tag_pattern
487
+ return self.git.tags.map( &:name ).grep( tag_pattern )
488
+ end
489
+
490
+
491
+ ### Read the list of tags and return any that don't have a corresponding section
492
+ ### in the history file.
493
+ def get_git_unhistoried_version_tags( include_current_version: true )
494
+ release_tags = self.get_git_version_tag_names
495
+ release_tags.unshift( self.current_git_version_tag ) if include_current_version
496
+
497
+ self.get_history_file_versions.each do |tag|
498
+ release_tags.delete( tag )
499
+ end
500
+
501
+ return release_tags
502
+ end
503
+
504
+
505
+ ### Generate a commit log and invoke the user's editor on it.
506
+ def edit_git_commit_log( logfile )
507
+ diff = self.git.diff
508
+
509
+ TTY::Editor.open( logfile, text: diff )
510
+ end
511
+
512
+
513
+ ### Add the list of +pathnames+ to the .gitignore list.
514
+ def git_ignore_files( *pathnames )
515
+ self.trace "Ignoring %d files." % [ pathnames.length ]
516
+
517
+ IGNORE_FILE.open( File::CREAT|File::WRONLY|File::APPEND, 0644 ) do |fh|
518
+ fh.puts( pathnames )
519
+ end
520
+ end
521
+
522
+ end # module Rake::DevEiate::Git
523
+
524
+
@@ -9,7 +9,7 @@ require 'tty/editor'
9
9
  require 'rake/deveiate' unless defined?( Rake::DevEiate )
10
10
 
11
11
 
12
- # Version-control tasks
12
+ # Mercurial version-control tasks
13
13
  module Rake::DevEiate::Hg
14
14
 
15
15
  # The name of the file to edit for the commit message
@@ -18,9 +18,6 @@ module Rake::DevEiate::Hg
18
18
  # The name of the ignore file
19
19
  IGNORE_FILE = Rake::DevEiate::PROJECT_DIR + '.hgignore'
20
20
 
21
- # The prefix to use for release version tags by default
22
- DEFAULT_RELEASE_TAG_PREFIX = 'v'
23
-
24
21
  # Colors for presenting file statuses
25
22
  STATUS_COLORS = {
26
23
  'M' => [:blue], # modified
@@ -36,29 +33,16 @@ module Rake::DevEiate::Hg
36
33
  FILE_INDENT = " • "
37
34
 
38
35
 
39
- ### Set up defaults
40
- def setup( _name, **options )
41
- super if defined?( super )
42
-
43
- @release_tag_prefix = options[:release_tag_prefix] || DEFAULT_RELEASE_TAG_PREFIX
44
- end
45
-
46
-
47
- ##
48
- # The prefix to use for version tags
49
- attr_accessor :release_tag_prefix
50
-
51
-
52
36
  ### Define version-control tasks
53
37
  def define_tasks
54
38
  super if defined?( super )
55
39
 
56
- return unless File.directory?( '.hg' )
40
+ return unless self.is_hg_working_copy?
57
41
 
58
42
  file COMMIT_MSG_FILE.to_s do |task|
59
43
  commit_log = Pathname( task.name )
60
44
 
61
- edit_commit_log( commit_log )
45
+ hg_edit_commit_log( commit_log )
62
46
  unless commit_log.size?
63
47
  self.prompt.error "Empty commit message; aborting."
64
48
  commit_log.unlink if commit_log.exist?
@@ -137,11 +121,17 @@ module Rake::DevEiate::Hg
137
121
  end
138
122
 
139
123
 
124
+ ### Returns +true+ if the current directory looks like a Mercurial working copy.
125
+ def is_hg_working_copy?
126
+ return File.directory?( '.hg' )
127
+ end
128
+
129
+
140
130
  ### The body of the hg:prerelease task.
141
131
  def do_hg_prerelease( task, args )
142
132
  uncommitted_files = self.hg.status( n: true )
143
133
  unless uncommitted_files.empty?
144
- self.show_file_statuses( uncommitted_files )
134
+ self.show_hg_file_statuses( uncommitted_files )
145
135
 
146
136
  fail unless self.prompt.yes?( "Release anyway?" ) do |q|
147
137
  q.default( false )
@@ -150,7 +140,7 @@ module Rake::DevEiate::Hg
150
140
  self.prompt.warn "Okay, releasing with uncommitted versions."
151
141
  end
152
142
 
153
- pkg_version_tag = self.current_version_tag
143
+ pkg_version_tag = self.current_hg_version_tag
154
144
  rev = self.hg.identity.id
155
145
 
156
146
  # Look for a tag for the current release version, and if it exists abort
@@ -316,7 +306,7 @@ module Rake::DevEiate::Hg
316
306
  end
317
307
 
318
308
  self.prompt.say "Checking history..."
319
- missing_tags = self.get_unhistoried_version_tags
309
+ missing_tags = self.get_hg_unhistoried_version_tags
320
310
 
321
311
  unless missing_tags.empty?
322
312
  self.prompt.error "%s needs updating; missing entries for tags: %s" %
@@ -343,8 +333,8 @@ module Rake::DevEiate::Hg
343
333
  abort
344
334
  end
345
335
 
346
- version_tag = self.current_version_tag
347
- previous_tag = self.previous_version_tag
336
+ version_tag = self.current_hg_version_tag
337
+ previous_tag = self.previous_hg_version_tag
348
338
  self.prompt.say "Updating history for %s..." % [ version_tag ]
349
339
 
350
340
  if self.get_history_file_versions.include?( version_tag )
@@ -408,27 +398,31 @@ module Rake::DevEiate::Hg
408
398
  def do_hg_debug( task, args )
409
399
  self.prompt.say( "Hg Info", color: :bright_green )
410
400
 
411
- self.prompt.say( "Mercurial version: " )
412
- self.prompt.say( Hglib.version, color: :bold )
413
- self.prompt.say( "Release tag prefix: " )
414
- self.prompt.say( self.release_tag_prefix, color: :bold )
401
+ if self.is_hg_working_copy?
402
+ self.prompt.say( "Mercurial version: " )
403
+ self.prompt.say( Hglib.version, color: :bold )
404
+ self.prompt.say( "Release tag prefix: " )
405
+ self.prompt.say( self.release_tag_prefix, color: :bold )
415
406
 
416
- self.prompt.say( "Version tags:" )
417
- self.get_version_tag_names.each do |tag|
418
- self.prompt.say( '- ' )
419
- self.prompt.say( tag, color: :bold )
420
- end
407
+ self.prompt.say( "Version tags:" )
408
+ self.get_hg_version_tag_names.each do |tag|
409
+ self.prompt.say( '- ' )
410
+ self.prompt.say( tag, color: :bold )
411
+ end
421
412
 
422
- self.prompt.say( "History file versions:" )
423
- self.get_history_file_versions.each do |tag|
424
- self.prompt.say( '- ' )
425
- self.prompt.say( tag, color: :bold )
426
- end
413
+ self.prompt.say( "History file versions:" )
414
+ self.get_history_file_versions.each do |tag|
415
+ self.prompt.say( '- ' )
416
+ self.prompt.say( tag, color: :bold )
417
+ end
427
418
 
428
- self.prompt.say( "Unhistoried version tags:" )
429
- self.get_unhistoried_version_tags.each do |tag|
430
- self.prompt.say( '- ' )
431
- self.prompt.say( tag, color: :bold )
419
+ self.prompt.say( "Unhistoried version tags:" )
420
+ self.get_hg_unhistoried_version_tags.each do |tag|
421
+ self.prompt.say( '- ' )
422
+ self.prompt.say( tag, color: :bold )
423
+ end
424
+ else
425
+ self.prompt.say( "Doesn't appear to be a Mercurial repository." )
432
426
  end
433
427
 
434
428
  self.prompt.say( "\n" )
@@ -447,7 +441,7 @@ module Rake::DevEiate::Hg
447
441
 
448
442
  ### Given a +status_hash+ like that returned by Hglib::Repo.status, return a
449
443
  ### string description of the files and their status.
450
- def show_file_statuses( statuses )
444
+ def show_hg_file_statuses( statuses )
451
445
  lines = statuses.map do |entry|
452
446
  status_color = STATUS_COLORS[ entry.status ]
453
447
  " %s: %s" % [
@@ -462,48 +456,30 @@ module Rake::DevEiate::Hg
462
456
 
463
457
 
464
458
  ### Fetch the name of the current version's tag.
465
- def current_version_tag
459
+ def current_hg_version_tag
466
460
  return [ self.release_tag_prefix, self.version ].join
467
461
  end
468
462
 
469
463
 
470
464
  ### Fetch the name of the tag for the previous version.
471
- def previous_version_tag
472
- return self.get_version_tag_names.first
473
- end
474
-
475
-
476
- ### Return a Regexp that matches the project's convention for versions.
477
- def release_tag_pattern
478
- prefix = self.release_tag_prefix
479
- return /#{prefix}\d+(\.\d+)+/
465
+ def previous_hg_version_tag
466
+ return self.get_hg_version_tag_names.first
480
467
  end
481
468
 
482
469
 
483
470
  ### Fetch the list of names of tags that match the versioning scheme of this
484
471
  ### project.
485
- def get_version_tag_names
472
+ def get_hg_version_tag_names
486
473
  tag_pattern = self.release_tag_pattern
487
474
  return self.hg.tags.map( &:name ).grep( tag_pattern )
488
475
  end
489
476
 
490
477
 
491
- ### Fetch the list of the versions of releases that have entries in the history
492
- ### file.
493
- def get_history_file_versions
494
- tag_pattern = self.release_tag_pattern
495
-
496
- return IO.readlines( self.history_file ).grep( tag_pattern ).map do |line|
497
- line[ /^(?:h\d\.|#+|=+)\s+(#{tag_pattern})\s+/, 1 ]
498
- end.compact
499
- end
500
-
501
-
502
478
  ### Read the list of tags and return any that don't have a corresponding section
503
479
  ### in the history file.
504
- def get_unhistoried_version_tags( include_current_version: true )
505
- release_tags = self.get_version_tag_names
506
- release_tags.unshift( self.current_version_tag ) if include_current_version
480
+ def get_hg_unhistoried_version_tags( include_current_version: true )
481
+ release_tags = self.get_hg_version_tag_names
482
+ release_tags.unshift( self.current_hg_version_tag ) if include_current_version
507
483
 
508
484
  self.get_history_file_versions.each do |tag|
509
485
  release_tags.delete( tag )
@@ -514,7 +490,7 @@ module Rake::DevEiate::Hg
514
490
 
515
491
 
516
492
  ### Generate a commit log and invoke the user's editor on it.
517
- def edit_commit_log( logfile )
493
+ def hg_edit_commit_log( logfile )
518
494
  diff = self.hg.diff
519
495
 
520
496
  TTY::Editor.open( logfile, text: diff )
@@ -533,32 +509,6 @@ module Rake::DevEiate::Hg
533
509
  end
534
510
  end
535
511
 
536
-
537
- ### Delete the files in the given +filelist+ after confirming with the user.
538
- def delete_extra_files( *filelist )
539
- description = humanize_file_list( filelist, ' ' )
540
- self.prompt.say "Files to delete:"
541
- self.prompt.say( description )
542
-
543
- if self.prompt.yes?( "Really delete them?" ) {|q| q.default(false) }
544
- filelist.each do |f|
545
- rm_rf( f, verbose: true )
546
- end
547
- end
548
- end
549
-
550
-
551
- ### Returns a human-scannable file list by joining and truncating the list if it's too long.
552
- def humanize_file_list( list, indent=FILE_INDENT )
553
- listtext = list[0..5].join( "\n#{indent}" )
554
- if list.length > 5
555
- listtext << " (and %d other/s)" % [ list.length - 5 ]
556
- end
557
-
558
- return listtext
559
- end
560
-
561
-
562
512
  end # module Rake::DevEiate::Hg
563
513
 
564
514
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rake-deveiate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.1
4
+ version: 0.17.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Granger
@@ -10,9 +10,9 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIID+DCCAmCgAwIBAgIBAjANBgkqhkiG9w0BAQsFADAiMSAwHgYDVQQDDBdnZWQv
14
- REM9RmFlcmllTVVEL0RDPW9yZzAeFw0xOTEyMjQyMDE5NTFaFw0yMDEyMjMyMDE5
15
- NTFaMCIxIDAeBgNVBAMMF2dlZC9EQz1GYWVyaWVNVUQvREM9b3JnMIIBojANBgkq
13
+ MIID+DCCAmCgAwIBAgIBAzANBgkqhkiG9w0BAQsFADAiMSAwHgYDVQQDDBdnZWQv
14
+ REM9RmFlcmllTVVEL0RDPW9yZzAeFw0yMDEyMjQyMDU1MjlaFw0yMTEyMjQyMDU1
15
+ MjlaMCIxIDAeBgNVBAMMF2dlZC9EQz1GYWVyaWVNVUQvREM9b3JnMIIBojANBgkq
16
16
  hkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAvyVhkRzvlEs0fe7145BYLfN6njX9ih5H
17
17
  L60U0p0euIurpv84op9CNKF9tx+1WKwyQvQP7qFGuZxkSUuWcP/sFhDXL1lWUuIl
18
18
  M4uHbGCRmOshDrF4dgnBeOvkHr1fIhPlJm5FO+Vew8tSQmlDsosxLUx+VB7DrVFO
@@ -23,17 +23,17 @@ cert_chain:
23
23
  ozilJg4aar2okb/RA6VS87o+d7g6LpDDMMQjH4G9OPnJENLdhu8KnPw/ivSVvQw7
24
24
  N2I4L/ZOIe2DIVuYH7aLHfjZDQv/mNgpAgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYD
25
25
  VR0PBAQDAgSwMB0GA1UdDgQWBBRyjf55EbrHagiRLqt5YAd3yb8k4DANBgkqhkiG
26
- 9w0BAQsFAAOCAYEAifxlz7x0EfT3fjhM520ZEIrWa+tLMuLKNefkY18u8tZnx4EX
27
- Xxwh3tna3fvNfrOrdY5leIj1dbv4FTRg+gIBnIxAySqvpGvI/Axg5EdYbwninCLL
28
- LAKCmRo+5QwaPMYN2zdHIjGrp8jg1neCo5zy6tVvyTv0DMI6FLrydVJYduMMDFSy
29
- gQKR1rVOcCJtnBnLCF9+kKEUKohAHOmGsE7OBZFnjMIpH5yUDUVJKByv0gIipFt0
30
- 1T6zff6oVU0w8WBiNKR381+6sF3wIZVnVY0XeJg6hNL+YecE8ILxLhHTmtT/BO0S
31
- 3xPze9uXDR+iD6HYl8KU5QEg/dXFPhfQb512vVkTJDZvMcwu6PxDUjHFChLjAji/
32
- AZXjg1C5E9znTkeUR8ieU9F1MOKoiH57a5lYSTI8Ga8PpsNXTxNeXc16Ob26CqrJ
33
- 83uuAYSy65yXDGXXPVBeKPVnYrqp91pqpS5Nh7wfuiCrE8lgU8PATh7K4BV1UhAT
34
- 0MHbAT42wTYkfUj3
26
+ 9w0BAQsFAAOCAYEAMYegZanJi8zq7QKPT7wqXefX4C88I5JWeBHR3PvvWK0CwyMV
27
+ peyiu5I13w/lYX+HUZjE4qsSpJMJFXWl4WZCOo+AMprOcf0PxfuJpxCej5D4tavf
28
+ vRfhahSw7XJrcZih/3J+/UgoH7R05MJ+8LTcy3HGrB3a0vTafjm8OY7Xpa0LJDoN
29
+ JDqxK321VIHyTibbKeA1hWSE6ljlQDvFbTqiCj3Ulp1jTv3TOlvRl8fqcfhxUJI0
30
+ +5Q82jJODjEN+GaWs0V+NlrbU94cXwS2PH5dXogftB5YYA5Ex8A0ikZ73xns4Hdo
31
+ XxdLdd92F5ovxA23j/rKe/IDwqr6FpDkU3nPXH/Qp0TVGv9zZnVJc/Z6ChkuWj8z
32
+ pW7JAyyiiHZgKKDReDrA2LA7Zs3o/7KA6UtUH0FHf8LYhcK+pfHk6RtjRe65ffw+
33
+ MCh97sQ/Z/MOusb5+QddBmB+k8EicXyGNl4b5L4XpL7fIQu+Y96TB3JEJlShxFD9
34
+ k9FjI4d9EP54gS/4
35
35
  -----END CERTIFICATE-----
36
- date: 2020-10-29 00:00:00.000000000 Z
36
+ date: 2020-12-28 00:00:00.000000000 Z
37
37
  dependencies:
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: rake
@@ -97,20 +97,14 @@ dependencies:
97
97
  requirements:
98
98
  - - "~>"
99
99
  - !ruby/object:Gem::Version
100
- version: '0.10'
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: 0.10.1
100
+ version: '0.11'
104
101
  type: :runtime
105
102
  prerelease: false
106
103
  version_requirements: !ruby/object:Gem::Requirement
107
104
  requirements:
108
105
  - - "~>"
109
106
  - !ruby/object:Gem::Version
110
- version: '0.10'
111
- - - ">="
112
- - !ruby/object:Gem::Version
113
- version: 0.10.1
107
+ version: '0.11'
114
108
  - !ruby/object:Gem::Dependency
115
109
  name: tty-prompt
116
110
  requirement: !ruby/object:Gem::Requirement
@@ -167,6 +161,20 @@ dependencies:
167
161
  - - "~>"
168
162
  - !ruby/object:Gem::Version
169
163
  version: '0.7'
164
+ - !ruby/object:Gem::Dependency
165
+ name: git
166
+ requirement: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - "~>"
169
+ - !ruby/object:Gem::Version
170
+ version: '1.7'
171
+ type: :runtime
172
+ prerelease: false
173
+ version_requirements: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - "~>"
176
+ - !ruby/object:Gem::Version
177
+ version: '1.7'
170
178
  - !ruby/object:Gem::Dependency
171
179
  name: rdoc-generator-fivefish
172
180
  requirement: !ruby/object:Gem::Requirement
@@ -205,6 +213,8 @@ files:
205
213
  - lib/rake/deveiate/gem_dep_finder.rb
206
214
  - lib/rake/deveiate/gemspec.rb
207
215
  - lib/rake/deveiate/generate.rb
216
+ - lib/rake/deveiate/git-refinements.rb
217
+ - lib/rake/deveiate/git.rb
208
218
  - lib/rake/deveiate/hg.rb
209
219
  - lib/rake/deveiate/packaging.rb
210
220
  - lib/rake/deveiate/releases.rb
@@ -233,7 +243,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
233
243
  - !ruby/object:Gem::Version
234
244
  version: '0'
235
245
  requirements: []
236
- rubygems_version: 3.1.2
246
+ rubygems_version: 3.2.3
237
247
  signing_key:
238
248
  specification_version: 4
239
249
  summary: This is a collection of Rake tasks I use for development.
metadata.gz.sig CHANGED
Binary file