gem_toys 0.5.0 → 0.8.0

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: 48cef709e2407ff05f6d4b10a262ef20bd399f14aed89ec446f5a57790d86460
4
- data.tar.gz: 2a1386e9f03dd8d818e2dd7e6ec402d502424a913f2f86e251af6a9a0f3bf151
3
+ metadata.gz: 9c89427d93a3acd0536e28862539e50772f24059fec9253777560e9eba89cf03
4
+ data.tar.gz: 88dffcbdad90618b055900461bb2b37b946acf518570e584126bfb6ce2619b49
5
5
  SHA512:
6
- metadata.gz: b4113d09e6f299ccc60c2880b3aeece288b9c018c9a41d3f805d080480017c56ddbeb7e5a1c85b9c0a8533b2a19dc62b2ea892a5b10d2d0917505624ba4ad573
7
- data.tar.gz: bfcf1cd7c55c5aab00d9831f7f6ba587a588d4082af9a36d4e4d82191418a09e2f3bcfeaacf1c777c6699599a1cd052bc333648f98dd0a1f660d83cd82dd8121
6
+ metadata.gz: bba6338814ad5bb019833a4c1acb9441a6307e555edbe73f96326bcf3f0d156ead648bdd5eef444fedad74cecc15a6e940b60fc98ee7326de8b0c04d145751b0
7
+ data.tar.gz: 18d291e6dd2cd6dd3b94b4cd05295274d88accf9698d5b2827d369c08e49552f82275ca27d2f2d36b6c544c4a2882ac3e37d5c42b3e4c20b17f04ba4b1a4713f
data/CHANGELOG.md CHANGED
@@ -2,6 +2,36 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 0.8.0 (2021-04-16)
6
+
7
+ * Add `refresh` answer for release confirmation.
8
+
9
+ ## 0.7.1 (2021-03-04)
10
+
11
+ * Fix error about non-renamed `version` in one of aborts.
12
+ * Improve Regexp for date of existing release.
13
+ Catch only content inside the last parentheses.
14
+
15
+ ## 0.7.0 (2021-03-04)
16
+
17
+ * Add `:changelog_file_name` option.
18
+ * Add `:version_tag_prefix` option.
19
+ * Change date format for `versions` tool.
20
+ * Add documentation about `:version_file_path` option.
21
+ * Split `release` tool into modules for RuboCop satisfaction.
22
+
23
+ ## 0.6.1 (2021-02-10)
24
+
25
+ * Gently abort when `unreleased_title` not found.
26
+ * Improve documentation about `:unreleased_title` option.
27
+
28
+ ## 0.6.0 (2021-02-10)
29
+
30
+ * Support Ruby 3.
31
+ * Fix error with undefined `FileUtils`.
32
+ * Fix error with `release` tool via updating `alt_memery` to a fixed version.
33
+ * Update development dependencies.
34
+
5
35
  ## 0.5.0 (2020-11-29)
6
36
 
7
37
  * Add `versions` tool with `releases` alias.
data/README.md CHANGED
@@ -35,7 +35,15 @@ gem install gem_toys
35
35
  ```ruby
36
36
  # .toys.rb
37
37
  require 'gem_toys'
38
- expand GemToys::Template
38
+ expand GemToys::Template,
39
+ ## default is `CHANGELOG.md`
40
+ changelog_file_name: 'ChangeLog.md',
41
+ ## default is `## master (unreleased)`
42
+ unreleased_title: '## Unreleased',
43
+ ## default is `"lib/#{project_name_with_slashes_instead_dashes}/version.rb"`
44
+ version_file_path: 'lib/my-awesome_gem.rb',
45
+ ## default is `v`, so tags are like `v4.1.0`
46
+ version_tag_prefix: ''
39
47
 
40
48
  # `gem` namespace created, aliases are optional, but handful
41
49
  alias_tool :g, :gem
@@ -9,10 +9,17 @@ module GemToys
9
9
  class Template
10
10
  include Toys::Template
11
11
 
12
- attr_reader :version_file_path, :unreleased_title
13
-
14
- def initialize(version_file_path: nil, unreleased_title: '## master (unreleased)')
12
+ attr_reader :changelog_file_name, :version_file_path, :version_tag_prefix, :unreleased_title
13
+
14
+ def initialize(
15
+ changelog_file_name: 'CHANGELOG.md',
16
+ version_file_path: nil,
17
+ version_tag_prefix: 'v',
18
+ unreleased_title: '## master (unreleased)'
19
+ )
20
+ @changelog_file_name = changelog_file_name
15
21
  @version_file_path = version_file_path
22
+ @version_tag_prefix = version_tag_prefix
16
23
  @unreleased_title = unreleased_title
17
24
  end
18
25
 
@@ -31,6 +38,8 @@ module GemToys
31
38
  @template = template
32
39
 
33
40
  sh 'gem build'
41
+
42
+ require 'fileutils'
34
43
  FileUtils.mkdir_p pkg_directory
35
44
  FileUtils.mv "#{context_directory}/#{gem_file_name}", current_gem_file
36
45
  end
@@ -63,7 +72,9 @@ module GemToys
63
72
 
64
73
  require_relative 'template/release'
65
74
  expand Template::Release,
75
+ changelog_file_name: template.changelog_file_name,
66
76
  version_file_path: template.version_file_path,
77
+ version_tag_prefix: template.version_tag_prefix,
67
78
  unreleased_title: template.unreleased_title
68
79
  end
69
80
  end
@@ -32,7 +32,7 @@ module GemToys
32
32
  end
33
33
 
34
34
  memoize def changelog_file_path
35
- File.join context_directory, 'CHANGELOG.md'
35
+ File.join context_directory, @template.changelog_file_name
36
36
  end
37
37
 
38
38
  memoize def gem_file_name
@@ -71,7 +71,7 @@ module GemToys
71
71
 
72
72
  versions.each do |version|
73
73
  created_at = begin
74
- DateTime.parse(version[:created_at]).strftime('%b %e %Y %R')
74
+ DateTime.parse(version[:created_at]).strftime('%F %R')
75
75
  rescue Date::Error
76
76
  version[:created_at]
77
77
  end
@@ -1,20 +1,35 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'highline'
4
+
5
+ require_relative 'release/changelog'
6
+ require_relative 'release/git'
7
+
3
8
  module GemToys
4
9
  class Template
5
10
  ## Template with gem release tool, expanding internally
6
11
  class Release
7
12
  include Toys::Template
8
13
 
9
- attr_reader :version_file_path, :unreleased_title
14
+ attr_reader :changelog_file_name, :version_file_path, :version_tag_prefix, :unreleased_title
10
15
 
11
- def initialize(version_file_path:, unreleased_title:)
16
+ def initialize(
17
+ changelog_file_name:,
18
+ version_file_path:,
19
+ version_tag_prefix:,
20
+ unreleased_title:
21
+ )
22
+ @changelog_file_name = changelog_file_name
12
23
  @version_file_path = version_file_path
24
+ @version_tag_prefix = version_tag_prefix
13
25
  @unreleased_title = unreleased_title
14
26
  end
15
27
 
16
28
  on_expand do |template|
17
29
  tool :release do
30
+ include Release::Changelog
31
+ include Release::Git
32
+
18
33
  required_arg :new_version
19
34
 
20
35
  to_run do
@@ -36,22 +51,8 @@ module GemToys
36
51
 
37
52
  wait_for_manual_check
38
53
 
39
- ## Checkout to a new git branch, required for protected `master` with CI
40
- # sh "git switch -c v#{@new_version}"
41
-
42
- commit_changes
43
-
44
- ## Tag commit
45
- puts 'Tagging the commit...'
46
- sh "git tag -a v#{@new_version} -m 'Version #{@new_version}'"
47
-
48
- ## Push commit
49
- puts 'Pushing commit...'
50
- sh 'git push'
51
-
52
- ## Push tags
53
- puts 'Pushing tags...'
54
- sh 'git push --tags'
54
+ ## Commit, tag, push
55
+ process_git
55
56
 
56
57
  puts 'Pushing gem...'
57
58
  sh "gem push #{current_gem_file}"
@@ -100,45 +101,20 @@ module GemToys
100
101
  )
101
102
  end
102
103
 
103
- def update_changelog_file
104
- puts 'Updating changelog file...'
105
-
106
- @changelog_lines = File.readlines(changelog_file_path)
107
-
108
- existing_line = @changelog_lines.find { |line| line.start_with? "## #{@new_version} " }
109
-
110
- if existing_line
111
- return if (existing_date = existing_line.match(/\((.*)\)/)[1]) == @today
112
-
113
- abort "There is already #{version} version with date #{existing_date}"
114
- end
115
-
116
- File.write changelog_file_path, new_changelog_content
117
- end
118
-
119
- def new_changelog_content
120
- unreleased_title = @template.unreleased_title
121
- @changelog_lines.insert(
122
- @changelog_lines.index("#{unreleased_title}\n") + 2,
123
- '#' * unreleased_title.scan(/^#+/).first.size + " #{@new_version} (#{@today})\n\n"
124
- ).join
125
- end
126
-
127
- def commit_changes
128
- puts 'Committing changes...'
129
-
130
- sh "git add #{version_file_path} #{changelog_file_path}"
131
-
132
- sh "git commit -m 'Update version to #{@new_version}'"
133
- end
134
-
135
104
  def wait_for_manual_check
136
105
  $stdout.puts
137
106
  sh "git diff #{version_file_path} #{changelog_file_path}"
138
107
  $stdout.puts
139
- $stdout.puts 'Please, validate files before committing and pushing!'
140
- $stdout.puts 'Press anything to continue, Ctrl+C to cancel.'
141
- $stdin.gets
108
+
109
+ HighLine.new.choose do |menu|
110
+ menu.layout = :one_line
111
+
112
+ menu.prompt = 'Are these changes correct? '
113
+
114
+ menu.choice(:yes)
115
+ menu.choice(:no) { abort }
116
+ menu.choice(:refresh) { send(__method__) }
117
+ end
142
118
  end
143
119
  end
144
120
  end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GemToys
4
+ class Template
5
+ class Release
6
+ ## Helper module with methods about CHANGELOG file for `release` tool
7
+ module Changelog
8
+ private
9
+
10
+ def update_changelog_file
11
+ puts 'Updating changelog file...'
12
+
13
+ @changelog_lines = File.readlines(changelog_file_path)
14
+
15
+ existing_line = @changelog_lines.find { |line| line.start_with? "## #{@new_version} " }
16
+
17
+ if existing_line
18
+ return if (existing_date = existing_line.scan(/\(([^()]+)\)/).last.first) == @today
19
+
20
+ abort "There is already #{new_version} version with date #{existing_date}"
21
+ end
22
+
23
+ File.write changelog_file_path, new_changelog_content
24
+ end
25
+
26
+ def new_changelog_content
27
+ unreleased_title = @template.unreleased_title
28
+
29
+ unreleased_title_index = @changelog_lines.index("#{unreleased_title}\n")
30
+
31
+ abort_without_unreleased_title unless unreleased_title_index
32
+
33
+ @changelog_lines.insert(
34
+ unreleased_title_index + 2,
35
+ '#' * unreleased_title.scan(/^#+/).first.size + " #{@new_version} (#{@today})\n\n"
36
+ ).join
37
+ end
38
+
39
+ def abort_without_unreleased_title
40
+ abort <<~TEXT
41
+ `#{@template.unreleased_title}` not found in the `#{@template.changelog_file_name}` as the title for unreleased changes.
42
+ Please, use `:unreleased_title` option if you have non-default one.
43
+ TEXT
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GemToys
4
+ class Template
5
+ class Release
6
+ ## Helper module with methods about `git` for `release` tool
7
+ module Git
8
+ private
9
+
10
+ def process_git
11
+ new_version_git_tag = "#{@template.version_tag_prefix}#{@new_version}"
12
+
13
+ ## Checkout to a new git branch, required for protected `master` with CI
14
+ # sh "git switch -c #{new_version_git_tag}"
15
+
16
+ commit_changes
17
+
18
+ ## Tag commit
19
+ puts 'Tagging the commit...'
20
+ sh "git tag -a #{new_version_git_tag} -m 'Version #{@new_version}'"
21
+
22
+ ## Push commit
23
+ puts 'Pushing commit...'
24
+ sh 'git push'
25
+
26
+ ## Push tags
27
+ puts 'Pushing tags...'
28
+ sh 'git push --tags'
29
+ end
30
+
31
+ def commit_changes
32
+ puts 'Committing changes...'
33
+
34
+ sh "git add #{version_file_path} #{changelog_file_path}"
35
+
36
+ sh "git commit -m 'Update version to #{@new_version}'"
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GemToys
4
- VERSION = '0.5.0'
4
+ VERSION = '0.8.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gem_toys
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Popov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-29 00:00:00.000000000 Z
11
+ date: 2021-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: alt_memery
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.0'
19
+ version: '2.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.0'
26
+ version: '2.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: faraday
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: highline
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: pry-byebug
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +114,14 @@ dependencies:
100
114
  requirements:
101
115
  - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: 0.2.0
117
+ version: 0.5.0
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - "~>"
109
123
  - !ruby/object:Gem::Version
110
- version: 0.2.0
124
+ version: 0.5.0
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: rspec
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -128,14 +142,14 @@ dependencies:
128
142
  requirements:
129
143
  - - "~>"
130
144
  - !ruby/object:Gem::Version
131
- version: 0.19.0
145
+ version: 0.21.2
132
146
  type: :development
133
147
  prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
150
  - - "~>"
137
151
  - !ruby/object:Gem::Version
138
- version: 0.19.0
152
+ version: 0.21.2
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: rubocop
141
155
  requirement: !ruby/object:Gem::Requirement
@@ -194,6 +208,8 @@ files:
194
208
  - lib/gem_toys/template.rb
195
209
  - lib/gem_toys/template/common_code.rb
196
210
  - lib/gem_toys/template/release.rb
211
+ - lib/gem_toys/template/release/changelog.rb
212
+ - lib/gem_toys/template/release/git.rb
197
213
  - lib/gem_toys/template/versions.rb
198
214
  - lib/gem_toys/version.rb
199
215
  homepage: https://github.com/AlexWayfer/gem_toys
@@ -212,13 +228,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
212
228
  - - ">="
213
229
  - !ruby/object:Gem::Version
214
230
  version: '2.5'
231
+ - - "<"
232
+ - !ruby/object:Gem::Version
233
+ version: '4'
215
234
  required_rubygems_version: !ruby/object:Gem::Requirement
216
235
  requirements:
217
236
  - - ">="
218
237
  - !ruby/object:Gem::Version
219
238
  version: '0'
220
239
  requirements: []
221
- rubygems_version: 3.1.4
240
+ rubygems_version: 3.2.15
222
241
  signing_key:
223
242
  specification_version: 4
224
243
  summary: Toys template for gems