gem_toys 0.6.1 → 0.9.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: 4618c51d0060981f796f40c91b6e746f6cc9860adcdbae6b291e9740b4f617df
4
- data.tar.gz: 42efd278a9c5821c85eb776dae8f1dde46ac957d1c98842c716f5f769de313f0
3
+ metadata.gz: 0b023bf7a74055e177396b6f315eda52ed9737d2d18de86c0213d7a740c5089f
4
+ data.tar.gz: c2ae112eca387b13cead398223022eb219e2900ae4ce3ef2b7c8b9116ef78728
5
5
  SHA512:
6
- metadata.gz: 1a8a580cb0ec036fcd80c6c27ef1ecf289c9d87e5696d044b585bcf2ffe05c6ef22c96fee1f2836aa0f9e9f875545b2b3cb501b5d1d3b75fd4bca4edf78b5ac9
7
- data.tar.gz: 0ae8062f7f01ed27afdf635dbc06a25495a6d6039470a469e6ea5213eecaa66301afce1a9561bc87bd3401822f98e5c6b2443a249926ca8d0eecf0bcf18f70cf
6
+ metadata.gz: 73979e0c344259f99b1605680e9369121bd7fbbb740ba1af6019e2b48d56596b76691d096ec3a7433de04bd60aea9c9769fe74c9059b8a10bb650d92bb0d513a
7
+ data.tar.gz: bf1432b40babf5b2c8c2d21a3d2e4689327545a3589435a818fcef98c81c037e1a9f76a5f5b5d03cd196b09e5c0fc14b8b6284d15d8435e837b2ced68e086ceb
data/CHANGELOG.md CHANGED
@@ -2,8 +2,36 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 0.9.0 (2021-08-26)
6
+
7
+ * Fix built gem version after `refresh` answer.
8
+ * Update development dependencies.
9
+ * Lock RuboCop version better.
10
+ * Resolve new RuboCop offenses.
11
+
12
+ ## 0.8.0 (2021-04-16)
13
+
14
+ * Add `refresh` answer for release confirmation.
15
+
16
+ ## 0.7.1 (2021-03-04)
17
+
18
+ * Fix error about non-renamed `version` in one of aborts.
19
+ * Improve Regexp for date of existing release.
20
+ Catch only content inside the last parentheses.
21
+
22
+ ## 0.7.0 (2021-03-04)
23
+
24
+ * Add `:changelog_file_name` option.
25
+ * Add `:version_tag_prefix` option.
26
+ * Change date format for `versions` tool.
27
+ * Add documentation about `:version_file_path` option.
28
+ * Split `release` tool into modules for RuboCop satisfaction.
29
+
5
30
  ## 0.6.1 (2021-02-10)
6
31
 
32
+ * Gently abort when `unreleased_title` not found.
33
+ * Improve documentation about `:unreleased_title` option.
34
+
7
35
  ## 0.6.0 (2021-02-10)
8
36
 
9
37
  * Support Ruby 3.
data/README.md CHANGED
@@ -36,7 +36,14 @@ gem install gem_toys
36
36
  # .toys.rb
37
37
  require 'gem_toys'
38
38
  expand GemToys::Template,
39
- unreleased_title: '## Unreleased' ## default is `## master (unreleased)`
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: ''
40
47
 
41
48
  # `gem` namespace created, aliases are optional, but handful
42
49
  alias_tool :g, :gem
@@ -31,12 +31,8 @@ module GemToys
31
31
  version_file_content.match(/VERSION = '(.+)'/)[1]
32
32
  end
33
33
 
34
- memoize def changelog_file_name
35
- 'CHANGELOG.md'
36
- end
37
-
38
34
  memoize def changelog_file_path
39
- File.join context_directory, changelog_file_name
35
+ File.join context_directory, @template.changelog_file_name
40
36
  end
41
37
 
42
38
  memoize def gem_file_name
@@ -75,7 +71,7 @@ module GemToys
75
71
 
76
72
  versions.each do |version|
77
73
  created_at = begin
78
- DateTime.parse(version[:created_at]).strftime('%b %e %Y %R')
74
+ DateTime.parse(version[:created_at]).strftime('%F %R')
79
75
  rescue Date::Error
80
76
  version[:created_at]
81
77
  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,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
@@ -31,27 +46,13 @@ module GemToys
31
46
  ## Update CHANGELOG
32
47
  update_changelog_file
33
48
 
34
- ## Build new gem file
35
- exec_tool 'gem build'
36
-
37
49
  wait_for_manual_check
38
50
 
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
+ ## Build new gem file
52
+ exec_tool 'gem build'
51
53
 
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,57 +101,31 @@ 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
-
122
- unreleased_title_index = @changelog_lines.index("#{unreleased_title}\n")
123
-
124
- abort_without_unreleased_title unless unreleased_title_index
104
+ def wait_for_manual_check
105
+ print_files_diff
125
106
 
126
- @changelog_lines.insert(
127
- unreleased_title_index + 2,
128
- '#' * unreleased_title.scan(/^#+/).first.size + " #{@new_version} (#{@today})\n\n"
129
- ).join
107
+ manual_check_menu
130
108
  end
131
109
 
132
- def abort_without_unreleased_title
133
- abort <<~TEXT
134
- `#{@template.unreleased_title}` not found in the `#{changelog_file_name}` as the title for unreleased changes.
135
- Please, use `:unreleased_title` option if you have non-default one.
136
- TEXT
110
+ def print_files_diff
111
+ $stdout.puts
112
+ sh "git diff #{version_file_path} #{changelog_file_path}"
113
+ $stdout.puts
137
114
  end
138
115
 
139
- def commit_changes
140
- puts 'Committing changes...'
116
+ def manual_check_menu
117
+ HighLine.new.choose do |menu|
118
+ menu.layout = :one_line
141
119
 
142
- sh "git add #{version_file_path} #{changelog_file_path}"
120
+ menu.prompt = 'Are these changes correct? '
143
121
 
144
- sh "git commit -m 'Update version to #{@new_version}'"
145
- end
146
-
147
- def wait_for_manual_check
148
- $stdout.puts
149
- sh "git diff #{version_file_path} #{changelog_file_path}"
150
- $stdout.puts
151
- $stdout.puts 'Please, validate files before committing and pushing!'
152
- $stdout.puts 'Press anything to continue, Ctrl+C to cancel.'
153
- $stdin.gets
122
+ menu.choice(:yes)
123
+ menu.choice(:no) { abort }
124
+ menu.choice(:refresh) do
125
+ handle_new_version
126
+ wait_for_manual_check
127
+ end
128
+ end
154
129
  end
155
130
  end
156
131
  end
@@ -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
 
@@ -65,7 +72,9 @@ module GemToys
65
72
 
66
73
  require_relative 'template/release'
67
74
  expand Template::Release,
75
+ changelog_file_name: template.changelog_file_name,
68
76
  version_file_path: template.version_file_path,
77
+ version_tag_prefix: template.version_tag_prefix,
69
78
  unreleased_title: template.unreleased_title
70
79
  end
71
80
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GemToys
4
- VERSION = '0.6.1'
4
+ VERSION = '0.9.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.6.1
4
+ version: 0.9.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: 2021-02-09 00:00:00.000000000 Z
11
+ date: 2021-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: alt_memery
@@ -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
@@ -86,28 +100,28 @@ dependencies:
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: 0.11.0
103
+ version: 0.12.0
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: 0.11.0
110
+ version: 0.12.0
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: codecov
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: 0.4.2
117
+ version: 0.6.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.4.2
124
+ version: 0.6.0
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: rspec
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -142,14 +156,14 @@ dependencies:
142
156
  requirements:
143
157
  - - "~>"
144
158
  - !ruby/object:Gem::Version
145
- version: '1.2'
159
+ version: 1.19.0
146
160
  type: :development
147
161
  prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
164
  - - "~>"
151
165
  - !ruby/object:Gem::Version
152
- version: '1.2'
166
+ version: 1.19.0
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: rubocop-performance
155
169
  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
@@ -221,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
221
237
  - !ruby/object:Gem::Version
222
238
  version: '0'
223
239
  requirements: []
224
- rubygems_version: 3.2.3
240
+ rubygems_version: 3.2.22
225
241
  signing_key:
226
242
  specification_version: 4
227
243
  summary: Toys template for gems