foobar_templates 2.0.1.rc4 → 2.0.1.rc5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c933bd134506713bc01168f73ba617aeb22f7d3dc10a472455da258189136528
4
- data.tar.gz: 0a5bcd41cff0ef149b6950e5a6868e444eaff671e7eef5043cf89ea5f24f917c
3
+ metadata.gz: 2de721ac516850803ef2197289a766487833355196ecc4c613642edc6a1761e6
4
+ data.tar.gz: 5c8f819dce4a1af6a442f85577f31f3a01d342245a3a7172de25d96185ae87ce
5
5
  SHA512:
6
- metadata.gz: a036cca148228d0cd1b6d7f1f8d0d81249108dd1aa4b029d146838b64b26ea018857a9f4a175f3e8c9bbc229f77035a68c4bc7dadbacae0e0a8b2ffaf38c3143
7
- data.tar.gz: fa889a9eb2be2514d2b1347458b624491a460e1f7bc7faf25e7577a62da623e85ca29ec31b4ecb6633a4042d5ba75b66e37c72a21b2b3c67a88ef1a9c77ba3b9
6
+ metadata.gz: 2339d804f08da3320e3a981b89c6193a5f41942358e71bdd9ba523ea7c750436d027e0080352f8b70705ed17e6f17a38ecfb00761f8e71ed316b629c440d6818
7
+ data.tar.gz: 0be856b92d4ec8e243e42c9d2f9adf1404bd53e11b77a54d57102bafce844189ea53168d7d4dbd8812876d4bc7380a4ca33dfe7abb623555462a3c5d8cd7536e
data/README.md CHANGED
@@ -153,3 +153,20 @@ If you would find additional variables handy, set me up with a PR and assuming i
153
153
  - Use `FOO_` prefixed placeholders for non-name variables: `FOO_AUTHOR`, `FOO_EMAIL`, `FOO_GIT_REPO_URL`, etc.
154
154
  - Running `foobar_templates --cheat-sheet` will list off available template variables
155
155
  - File **names** containing `foo-bar` or `foo_bar` will have those replaced by the project name
156
+
157
+
158
+ ## Release Process
159
+
160
+ Cut a pre-release with:
161
+
162
+ ```
163
+ rake release
164
+ ```
165
+
166
+ Days or months later, promote it to a release:
167
+
168
+ ```
169
+ git checkout OLD_RELEASE
170
+ rake promote
171
+ ```
172
+
data/Rakefile CHANGED
@@ -19,12 +19,26 @@ module ReleaseHelper
19
19
  end
20
20
 
21
21
  def current_version
22
+ return ENV['GEM_VERSION'] if ENV['GEM_VERSION']
23
+
22
24
  src = File.read(VERSION_FILE)
23
- m = src.match(/VERSION\s*=\s*"([^"]+)"/)
25
+ m = src.match(/VERSION\s*=\s*["']([^"']+)["']/)
24
26
  abort "Could not parse VERSION from #{VERSION_FILE}" unless m
25
27
  m[1]
26
28
  end
27
29
 
30
+ def strip_rc(version)
31
+ m = version.match(RC_RE)
32
+ return nil unless m
33
+ maj, min, pat, _rc = m.captures
34
+ "#{maj}.#{min}.#{pat}"
35
+ end
36
+
37
+ def rc_tag_on_head
38
+ tags = `git tag --points-at HEAD`.strip.split("\n")
39
+ tags.find { |t| t.match?(/\Av\d+\.\d+\.\d+\.rc\d+\z/) }
40
+ end
41
+
28
42
  def next_version(v)
29
43
  if (m = v.match(RC_RE))
30
44
  maj, min, pat, rc = m.captures.map(&:to_i)
@@ -168,6 +182,49 @@ task :release do
168
182
  puts "=" * 60
169
183
  end
170
184
 
185
+ desc "Promote a pre-release commit to a final release (no new commit needed)"
186
+ task :promote, [:version] do |_t, args|
187
+ include_helper = ReleaseHelper
188
+
189
+ include_helper.preflight!
190
+
191
+ # Determine the RC tag on HEAD
192
+ rc_tag = include_helper.rc_tag_on_head
193
+ abort "No pre-release tag (vX.Y.Z.rcN) found on HEAD. Checkout a tagged RC commit first." unless rc_tag
194
+ rc_version = rc_tag.sub(/\Av/, '')
195
+
196
+ # Determine target release version
197
+ release_version = args[:version] || include_helper.strip_rc(rc_version)
198
+ abort "Could not derive release version from #{rc_version}" unless release_version
199
+ abort "Target version #{release_version} is not a release format (expected MAJOR.MINOR.PATCH)" unless release_version.match?(ReleaseHelper::REL_RE)
200
+
201
+ sha = `git rev-parse --short HEAD`.strip
202
+ puts "Promoting commit #{sha} (tagged #{rc_tag}) \u2192 v#{release_version}"
203
+ unless include_helper.confirm!("Continue?", default: false)
204
+ puts "Aborted."
205
+ exit 0
206
+ end
207
+
208
+ # Build gem with the release version (override via ENV, no file edit)
209
+ ENV['GEM_VERSION'] = release_version
210
+ Rake::Task[:build].invoke
211
+
212
+ gem_file = "pkg/#{GEM_NAME}-#{release_version}.gem"
213
+ abort "Built gem not found at #{gem_file}" unless File.exist?(gem_file)
214
+
215
+ # Tag and push
216
+ tag = "v#{release_version}"
217
+ include_helper.sh! %(git tag -a #{tag} -m "Release #{tag}")
218
+ include_helper.push! "git push origin #{tag}"
219
+ include_helper.push! "gem push #{gem_file}"
220
+
221
+ puts ""
222
+ puts "=" * 60
223
+ puts "Promoted: #{rc_tag} \u2192 #{tag}"
224
+ puts "Tag: https://github.com/TheNotary/#{GEM_NAME}/releases/tag/#{tag}"
225
+ puts "=" * 60
226
+ end
227
+
171
228
  desc "Run unit specs"
172
229
  RSpec::Core::RakeTask.new(:unit) do |t|
173
230
  t.rspec_opts = %w(-fd -c)
@@ -1,3 +1,4 @@
1
1
  require 'foobar_templates/cli/dir_to_template'
2
2
  require 'foobar_templates/cli/cheat_sheet'
3
3
  require 'foobar_templates/cli/setup_personal_templates_repo'
4
+ require 'foobar_templates/cli/template_generator'
@@ -77,7 +77,7 @@ module FoobarTemplates::CLI
77
77
  puts cmd
78
78
  time_it("bootstrap_command") do
79
79
  Dir.chdir(target) do
80
- `#{cmd}`
80
+ puts `#{cmd}`
81
81
  end
82
82
  end
83
83
  end
@@ -178,8 +178,9 @@ module FoobarTemplates::CLI
178
178
 
179
179
  reserved = Array(rules[:reserved_names]).map(&:to_s)
180
180
  if reserved.include?(name)
181
- $stderr.puts "Invalid project name '#{name}': reserved by template '#{@options[:template]}'. Please choose another name."
182
- raise
181
+ raise FoobarTemplates::CLIError, <<~HEREDOC
182
+ Invalid project name '#{name}': reserved by template '#{@options[:template]}'. Please choose another name.
183
+ HEREDOC
183
184
  end
184
185
 
185
186
  pattern = rules[:regex_validator]
@@ -187,13 +188,15 @@ module FoobarTemplates::CLI
187
188
  begin
188
189
  regex = Regexp.new(pattern.to_s)
189
190
  rescue RegexpError => e
190
- $stderr.puts "Template '#{@options[:template]}' has an invalid name_validation.regex_validator: #{e.message}"
191
- raise "invalid name_validation.regex_validator"
191
+ raise FoobarTemplates::CLIError, <<~HEREDOC
192
+ Template '#{@options[:template]}' has an invalid name_validation.regex_validator: #{e.message}
193
+ HEREDOC
192
194
  end
193
195
 
194
196
  unless regex.match?(name)
195
- $stderr.puts "Invalid project name '#{name}': does not match #{regex.inspect} required by template '#{@options[:template]}'."
196
- raise
197
+ raise FoobarTemplates::CLIError, <<~HEREDOC
198
+ Invalid project name '#{name}': does not match #{regex.inspect} required by template '#{@options[:template]}'.
199
+ HEREDOC
197
200
  end
198
201
  end
199
202
  end
@@ -463,31 +466,28 @@ module FoobarTemplates::CLI
463
466
  end
464
467
 
465
468
  def raise_no_files_in_template_error!
466
- err_no_files_in_template = <<-HEREDOC
467
- Ooops, the template was found for '#{@options[:template]}' in ~/.foobar/templates,
468
- but no files were found within it.
469
+ raise FoobarTemplates::CLIError, <<~HEREDOC
470
+ The template was found for '#{@options[:template]}' in ~/.foobar/templates,
471
+ but no files were found within it.
469
472
 
470
- Exiting...
473
+ Exiting...
471
474
  HEREDOC
472
- puts err_no_files_in_template
473
- raise
474
475
  end
475
476
 
476
477
  def raise_project_with_that_name_already_exists!
477
- err_project_with_that_name_exists = <<-HEREDOC
478
- Ooops, a project with the name #{target} already exists.
479
- Can't make project. Either delete that folder or choose a new project name
478
+ raise FoobarTemplates::CLIError, <<~HEREDOC
479
+ A project with the name #{target} already exists.
480
+ Can't make project. Either delete that folder or choose a new project name
480
481
 
481
- Exiting...
482
+ Exiting...
482
483
  HEREDOC
483
- puts err_project_with_that_name_exists
484
- raise
485
484
  end
486
485
 
487
486
  def raise_template_not_found!
488
- err_missing_template = "Could not find template folder '#{@options[:template]}' in `~/.foobar/templates/`. Please check to make sure your desired template exists."
489
- $stderr.puts err_missing_template
490
- raise
487
+ raise FoobarTemplates::CLIError, <<~HEREDOC
488
+ Template not found for '#{@options[:template]}' in `~/.foobar/templates/`.
489
+ Please check to make sure your desired template exists.
490
+ HEREDOC
491
491
  end
492
492
 
493
493
  def time_it(label = nil)
@@ -509,8 +509,9 @@ Exiting...
509
509
  # and won't overlap with a foobar_templates constant apparently...
510
510
  def ensure_safe_project_name(name, constant_array)
511
511
  if name =~ /^\d/
512
- $stderr.puts "Invalid gem name #{name} Please give a name which does not start with numbers."
513
- raise
512
+ raise FoobarTemplates::CLIError, <<~HEREDOC
513
+ Invalid gem name #{name}. Please give a name which does not start with numbers.
514
+ HEREDOC
514
515
  end
515
516
  end
516
517
 
@@ -1,3 +1,5 @@
1
+ VERSION = "2.0.1.rc5"
2
+
1
3
  module FoobarTemplates
2
- VERSION = "2.0.1.rc4"
4
+ VERSION = ENV.fetch("GEM_VERSION", VERSION)
3
5
  end
@@ -80,9 +80,7 @@ module FoobarTemplates
80
80
  end
81
81
 
82
82
  def generate_template(options, gem_name)
83
- require 'foobar_templates/cli/template_generator'
84
-
85
- template_generator = CLI::TemplateGenerator.new(options, gem_name).run
83
+ CLI::TemplateGenerator.new(options, gem_name).run
86
84
  rescue FoobarTemplates::CLIError => e
87
85
  msg = e.message
88
86
  $stderr.puts msg if msg && !msg.empty? && msg != e.class.name
@@ -9,6 +9,7 @@ describe FoobarTemplates do
9
9
 
10
10
  reset_test_env
11
11
  FileUtils.chdir(@dst_dir)
12
+ @dst_dir = FileUtils.pwd # We need to resolve the /tmp dir incase it's a mac with /private/tmp
12
13
  end
13
14
 
14
15
  it 'has a version number' do
@@ -205,7 +206,7 @@ describe FoobarTemplates do
205
206
  5000.times { |i| File.write("#{template_dir}/node_modules/file_#{i}.rb", "ignored #{i}") }
206
207
  `git init #{template_dir}`
207
208
 
208
- capture_stdout do
209
+ capture_stdout do
209
210
  FoobarTemplates.generate_template(options, gem_name)
210
211
  end
211
212
 
@@ -242,6 +243,36 @@ describe FoobarTemplates do
242
243
  expect(output).to include "echo #{gem_name}"
243
244
  end
244
245
 
246
+ it "prints stdout of a multi-line bootstrap_command" do
247
+ # this is quite pointless, we're literally allowing the user to execute a command on their shell...
248
+ template_dir = create_user_defined_template("testing", "template-user-supplied")
249
+ options = { bin: false, ext: false, coc: false, template: "template-user-supplied" }
250
+ gem_name = "good-dog"
251
+
252
+ yaml_content = <<~YAML
253
+ bootstrap_command: |
254
+ echo 'foo-bar'
255
+ pwd
256
+ cd ..
257
+ pwd
258
+ YAML
259
+
260
+ File.write("#{template_dir}/foobar.yml", yaml_content)
261
+ File.write("#{template_dir}/README.md", "# Readme...")
262
+ `git init #{template_dir}`
263
+
264
+ output = capture_stdout { FoobarTemplates.generate_template(options, gem_name) }
265
+
266
+ expect(output).to end_with <<~OUTPUT
267
+ pwd
268
+ good-dog
269
+ #{@dst_dir}/good-dog
270
+ #{@dst_dir}
271
+
272
+ Complete.
273
+ OUTPUT
274
+ end
275
+
245
276
  describe "name_validation" do
246
277
  it "rejects names listed in reserved_names and skips bootstrap_command" do
247
278
  template_dir = create_user_defined_template("testing", "template-user-supplied")
@@ -255,9 +286,7 @@ describe FoobarTemplates do
255
286
  File.write("#{template_dir}/README.md", "# Readme")
256
287
  `git init #{template_dir}`
257
288
 
258
- expect {
259
- capture_stdout { capture_stderr { FoobarTemplates.generate_template(options, gem_name) } }
260
- }.to raise_error(RuntimeError)
289
+ capture_stdout { capture_stderr { FoobarTemplates.generate_template(options, gem_name) } }
261
290
 
262
291
  expect($captured_stderr).to include "reserved by template"
263
292
  expect(File).not_to exist("#{@dst_dir}/#{gem_name}")
@@ -292,9 +321,7 @@ describe FoobarTemplates do
292
321
  File.write("#{template_dir}/README.md", "# Readme")
293
322
  `git init #{template_dir}`
294
323
 
295
- expect {
296
- capture_stdout { capture_stderr { FoobarTemplates.generate_template(options, gem_name) } }
297
- }.to raise_error(RuntimeError)
324
+ capture_stdout { capture_stderr { FoobarTemplates.generate_template(options, gem_name) } }
298
325
 
299
326
  expect($captured_stderr).to include "does not match"
300
327
  expect(File).not_to exist("#{@dst_dir}/#{gem_name}")
@@ -329,9 +356,7 @@ describe FoobarTemplates do
329
356
  File.write("#{template_dir}/README.md", "# Readme")
330
357
  `git init #{template_dir}`
331
358
 
332
- expect {
333
- capture_stdout { capture_stderr { FoobarTemplates.generate_template(options, gem_name) } }
334
- }.to raise_error(RuntimeError)
359
+ capture_stdout { capture_stderr { FoobarTemplates.generate_template(options, gem_name) } }
335
360
 
336
361
  expect($captured_stderr).to include "reserved"
337
362
  end
@@ -348,9 +373,7 @@ describe FoobarTemplates do
348
373
  File.write("#{template_dir}/README.md", "# Readme")
349
374
  `git init #{template_dir}`
350
375
 
351
- expect {
352
- capture_stdout { capture_stderr { FoobarTemplates.generate_template(options, gem_name) } }
353
- }.to raise_error(RuntimeError)
376
+ capture_stdout { capture_stderr { FoobarTemplates.generate_template(options, gem_name) } }
354
377
 
355
378
  expect($captured_stderr).to include "invalid name_validation.regex_validator"
356
379
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobar_templates
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1.rc4
4
+ version: 2.0.1.rc5
5
5
  platform: ruby
6
6
  authors:
7
7
  - TheNotary
@@ -130,9 +130,9 @@ licenses:
130
130
  - MIT
131
131
  metadata:
132
132
  bug_tracker_uri: https://github.com/TheNotary/foobar_templates/issues
133
- changelog_uri: https://github.com/TheNotary/foobar_templates/releases/tag/v2.0.1.rc4
133
+ changelog_uri: https://github.com/TheNotary/foobar_templates/releases/tag/v2.0.1.rc5
134
134
  documentation_uri: https://github.com/TheNotary/foobar_templates
135
- source_code_uri: https://github.com/TheNotary/foobar_templates/tree/v2.0.1.rc4
135
+ source_code_uri: https://github.com/TheNotary/foobar_templates/tree/v2.0.1.rc5
136
136
  rdoc_options: []
137
137
  require_paths:
138
138
  - lib