gem_toys 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/lib/gem_toys/template.rb +12 -84
- data/lib/gem_toys/template/common_code.rb +49 -13
- data/lib/gem_toys/template/release.rb +147 -0
- data/lib/gem_toys/template/versions.rb +31 -0
- data/lib/gem_toys/version.rb +1 -1
- metadata +52 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48cef709e2407ff05f6d4b10a262ef20bd399f14aed89ec446f5a57790d86460
|
4
|
+
data.tar.gz: 2a1386e9f03dd8d818e2dd7e6ec402d502424a913f2f86e251af6a9a0f3bf151
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4113d09e6f299ccc60c2880b3aeece288b9c018c9a41d3f805d080480017c56ddbeb7e5a1c85b9c0a8533b2a19dc62b2ea892a5b10d2d0917505624ba4ad573
|
7
|
+
data.tar.gz: bfcf1cd7c55c5aab00d9831f7f6ba587a588d4082af9a36d4e4d82191418a09e2f3bcfeaacf1c777c6699599a1cd052bc333648f98dd0a1f660d83cd82dd8121
|
data/CHANGELOG.md
CHANGED
@@ -2,8 +2,23 @@
|
|
2
2
|
|
3
3
|
## master (unreleased)
|
4
4
|
|
5
|
+
## 0.5.0 (2020-11-29)
|
6
|
+
|
7
|
+
* Add `versions` tool with `releases` alias.
|
8
|
+
* Add `version` tool.
|
9
|
+
* Add an ability to release new `major`, `minor` or `patch` version.
|
10
|
+
Just specify keyword instead of number and it'll increase correctly.
|
11
|
+
* Print `git diff` for files which will be commited on `release`.
|
12
|
+
* Drop Ruby 2.4 support.
|
13
|
+
[Support of Ruby 2.4 has ended](https://www.ruby-lang.org/en/news/2020/04/05/support-of-ruby-2-4-has-ended/).
|
14
|
+
* Add and use `memery` dependency.
|
15
|
+
* Update `rubocop`, `remark`.
|
16
|
+
|
5
17
|
## 0.4.0 (2020-09-21)
|
6
18
|
|
19
|
+
* Improve version update script, support files with other String constants.
|
20
|
+
* Update bundle.
|
21
|
+
|
7
22
|
## 0.3.0 (2020-07-11)
|
8
23
|
|
9
24
|
* Add support for Ruby 2.4
|
data/lib/gem_toys/template.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'date'
|
4
3
|
require 'toys-core'
|
5
4
|
|
6
5
|
require_relative 'template/common_code'
|
@@ -46,97 +45,26 @@ module GemToys
|
|
46
45
|
end
|
47
46
|
end
|
48
47
|
|
49
|
-
tool :
|
50
|
-
required_arg :version
|
51
|
-
|
48
|
+
tool :version do
|
52
49
|
to_run do
|
53
50
|
@template = template
|
54
51
|
|
55
|
-
|
56
|
-
|
57
|
-
update_version_file
|
58
|
-
|
59
|
-
## Update CHANGELOG
|
60
|
-
update_changelog_file
|
61
|
-
|
62
|
-
## Build new gem file
|
63
|
-
exec_tool 'gem build'
|
64
|
-
|
65
|
-
wait_for_manual_check
|
66
|
-
|
67
|
-
## Checkout to a new git branch, required for protected `master` with CI
|
68
|
-
# sh "git switch -c v#{version}"
|
69
|
-
|
70
|
-
commit_changes
|
71
|
-
|
72
|
-
## Tag commit
|
73
|
-
puts 'Tagging the commit...'
|
74
|
-
sh "git tag -a v#{version} -m 'Version #{version}'"
|
75
|
-
|
76
|
-
## Push commit
|
77
|
-
puts 'Pushing commit...'
|
78
|
-
sh 'git push'
|
79
|
-
|
80
|
-
## Push tags
|
81
|
-
puts 'Pushing tags...'
|
82
|
-
sh 'git push --tags'
|
83
|
-
|
84
|
-
puts 'Pushing gem...'
|
85
|
-
sh "gem push #{current_gem_file}"
|
86
|
-
end
|
87
|
-
|
88
|
-
private
|
89
|
-
|
90
|
-
def update_version_file
|
91
|
-
puts 'Updating version file...'
|
92
|
-
|
93
|
-
File.write(
|
94
|
-
version_file_path,
|
95
|
-
version_file_content.sub(/(VERSION = )'.+'/, "\\1'#{version}'")
|
96
|
-
)
|
97
|
-
end
|
98
|
-
|
99
|
-
def update_changelog_file
|
100
|
-
puts 'Updating changelog file...'
|
101
|
-
|
102
|
-
@changelog_lines = File.readlines(changelog_file_path)
|
103
|
-
|
104
|
-
existing_line = find_version_line_in_changelog_file
|
105
|
-
|
106
|
-
if existing_line
|
107
|
-
return if (existing_date = existing_line.match(/\((.*)\)/)[1]) == @today
|
108
|
-
|
109
|
-
abort "There is already #{version} version with date #{existing_date}"
|
52
|
+
version = rubygems_versions.find(-> { current_version_hash }) do |rubygems_version|
|
53
|
+
rubygems_version[:number] == current_version
|
110
54
|
end
|
111
55
|
|
112
|
-
|
113
|
-
end
|
114
|
-
|
115
|
-
def find_version_line_in_changelog_file
|
116
|
-
@changelog_lines.find { |line| line.start_with? "## #{version} " }
|
56
|
+
puts_versions [version]
|
117
57
|
end
|
58
|
+
end
|
118
59
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
@changelog_lines.index("#{unreleased_title}\n") + 2,
|
123
|
-
'#' * unreleased_title.scan(/^#+/).first.size + " #{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 #{version}'"
|
133
|
-
end
|
60
|
+
require_relative 'template/versions'
|
61
|
+
expand Template::Versions,
|
62
|
+
version_file_path: template.version_file_path
|
134
63
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
end
|
64
|
+
require_relative 'template/release'
|
65
|
+
expand Template::Release,
|
66
|
+
version_file_path: template.version_file_path,
|
67
|
+
unreleased_title: template.unreleased_title
|
140
68
|
end
|
141
69
|
end
|
142
70
|
end
|
@@ -1,19 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'memery'
|
4
|
+
|
3
5
|
module GemToys
|
4
6
|
## Template with gem tools, should be expanded in toys file
|
5
7
|
class Template
|
6
8
|
## Module for common code between nested tools
|
7
9
|
module CommonCode
|
10
|
+
include Memery
|
11
|
+
|
8
12
|
private
|
9
13
|
|
10
|
-
def project_name
|
11
|
-
|
14
|
+
memoize def project_name
|
15
|
+
File.basename context_directory
|
12
16
|
end
|
13
17
|
|
14
|
-
def version_file_path
|
15
|
-
@version_file_path
|
16
|
-
@template.version_file_path ||
|
18
|
+
memoize def version_file_path
|
19
|
+
@template.version_file_path ||
|
17
20
|
begin
|
18
21
|
project_path = project_name.tr '-', '/'
|
19
22
|
File.join context_directory, 'lib', project_path, 'version.rb'
|
@@ -24,25 +27,58 @@ module GemToys
|
|
24
27
|
File.read version_file_path
|
25
28
|
end
|
26
29
|
|
27
|
-
def current_version
|
28
|
-
|
30
|
+
memoize def current_version
|
31
|
+
version_file_content.match(/VERSION = '(.+)'/)[1]
|
29
32
|
end
|
30
33
|
|
31
|
-
def changelog_file_path
|
32
|
-
|
34
|
+
memoize def changelog_file_path
|
35
|
+
File.join context_directory, 'CHANGELOG.md'
|
33
36
|
end
|
34
37
|
|
35
|
-
def gem_file_name
|
36
|
-
|
38
|
+
memoize def gem_file_name
|
39
|
+
"#{project_name}-#{current_version}.gem"
|
37
40
|
end
|
38
41
|
|
39
|
-
def pkg_directory
|
40
|
-
|
42
|
+
memoize def pkg_directory
|
43
|
+
"#{context_directory}/pkg"
|
41
44
|
end
|
42
45
|
|
43
46
|
def current_gem_file
|
44
47
|
"#{pkg_directory}/#{gem_file_name}"
|
45
48
|
end
|
49
|
+
|
50
|
+
memoize def rubygems_connection
|
51
|
+
require 'faraday'
|
52
|
+
require 'faraday_middleware'
|
53
|
+
|
54
|
+
Faraday.new 'https://rubygems.org/api/v1' do |conn|
|
55
|
+
conn.response :json, parser_options: { symbolize_names: true }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
memoize def rubygems_versions
|
60
|
+
rubygems_connection.get("versions/#{project_name}.json").body
|
61
|
+
end
|
62
|
+
|
63
|
+
def current_version_hash
|
64
|
+
{ number: current_version, created_at: 'unreleased' }
|
65
|
+
end
|
66
|
+
|
67
|
+
def puts_versions(versions)
|
68
|
+
require 'date'
|
69
|
+
|
70
|
+
longest_version_number = versions.map { |version| version[:number].length }.max
|
71
|
+
|
72
|
+
versions.each do |version|
|
73
|
+
created_at = begin
|
74
|
+
DateTime.parse(version[:created_at]).strftime('%b %e %Y %R')
|
75
|
+
rescue Date::Error
|
76
|
+
version[:created_at]
|
77
|
+
end
|
78
|
+
|
79
|
+
puts "#{version[:number].ljust(longest_version_number)} (#{created_at})"
|
80
|
+
end
|
81
|
+
end
|
46
82
|
end
|
47
83
|
end
|
48
84
|
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GemToys
|
4
|
+
class Template
|
5
|
+
## Template with gem release tool, expanding internally
|
6
|
+
class Release
|
7
|
+
include Toys::Template
|
8
|
+
|
9
|
+
attr_reader :version_file_path, :unreleased_title
|
10
|
+
|
11
|
+
def initialize(version_file_path:, unreleased_title:)
|
12
|
+
@version_file_path = version_file_path
|
13
|
+
@unreleased_title = unreleased_title
|
14
|
+
end
|
15
|
+
|
16
|
+
on_expand do |template|
|
17
|
+
tool :release do
|
18
|
+
required_arg :new_version
|
19
|
+
|
20
|
+
to_run do
|
21
|
+
require 'date'
|
22
|
+
|
23
|
+
@template = template
|
24
|
+
|
25
|
+
@today = Date.today.to_s
|
26
|
+
|
27
|
+
handle_new_version
|
28
|
+
|
29
|
+
update_version_file
|
30
|
+
|
31
|
+
## Update CHANGELOG
|
32
|
+
update_changelog_file
|
33
|
+
|
34
|
+
## Build new gem file
|
35
|
+
exec_tool 'gem build'
|
36
|
+
|
37
|
+
wait_for_manual_check
|
38
|
+
|
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'
|
55
|
+
|
56
|
+
puts 'Pushing gem...'
|
57
|
+
sh "gem push #{current_gem_file}"
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
self::VERSION_TYPES = %w[
|
63
|
+
major
|
64
|
+
minor
|
65
|
+
patch
|
66
|
+
].freeze
|
67
|
+
|
68
|
+
def handle_new_version
|
69
|
+
## https://github.com/dazuma/toys/issues/103
|
70
|
+
@new_version =
|
71
|
+
if (version_index = self.class::VERSION_TYPES.index(new_version))
|
72
|
+
current_version_parts =
|
73
|
+
current_version.split('.')[0..(self.class::VERSION_TYPES.count - 1)]
|
74
|
+
handle_keyword_in_new_version current_version_parts, version_index
|
75
|
+
else
|
76
|
+
new_version
|
77
|
+
end
|
78
|
+
|
79
|
+
clear_memery_cache! :current_version
|
80
|
+
end
|
81
|
+
|
82
|
+
def handle_keyword_in_new_version(current_version_parts, version_index)
|
83
|
+
current_version_parts.map.with_index do |version_part, index|
|
84
|
+
if index < version_index
|
85
|
+
version_part
|
86
|
+
elsif index == version_index
|
87
|
+
Integer(version_part) + 1
|
88
|
+
else
|
89
|
+
0
|
90
|
+
end
|
91
|
+
end.join('.')
|
92
|
+
end
|
93
|
+
|
94
|
+
def update_version_file
|
95
|
+
puts 'Updating version file...'
|
96
|
+
|
97
|
+
File.write(
|
98
|
+
version_file_path,
|
99
|
+
version_file_content.sub(/(VERSION = )'.+'/, "\\1'#{@new_version}'")
|
100
|
+
)
|
101
|
+
end
|
102
|
+
|
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
|
+
def wait_for_manual_check
|
136
|
+
$stdout.puts
|
137
|
+
sh "git diff #{version_file_path} #{changelog_file_path}"
|
138
|
+
$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
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GemToys
|
4
|
+
class Template
|
5
|
+
## Template with gem versions tool, expanding internally
|
6
|
+
class Versions
|
7
|
+
include Toys::Template
|
8
|
+
|
9
|
+
attr_reader :version_file_path
|
10
|
+
|
11
|
+
def initialize(version_file_path:)
|
12
|
+
@version_file_path = version_file_path
|
13
|
+
end
|
14
|
+
|
15
|
+
on_expand do |template|
|
16
|
+
tool :versions do
|
17
|
+
to_run do
|
18
|
+
@template = template
|
19
|
+
|
20
|
+
versions = rubygems_versions
|
21
|
+
|
22
|
+
versions.unshift current_version_hash if current_version != versions.first[:number]
|
23
|
+
|
24
|
+
puts_versions versions
|
25
|
+
end
|
26
|
+
end
|
27
|
+
alias_tool :releases, :versions
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/gem_toys/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gem_toys
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.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
|
+
date: 2020-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: alt_memery
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faraday_middleware
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
13
55
|
- !ruby/object:Gem::Dependency
|
14
56
|
name: pry-byebug
|
15
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,14 +142,14 @@ dependencies:
|
|
100
142
|
requirements:
|
101
143
|
- - "~>"
|
102
144
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
145
|
+
version: '1.2'
|
104
146
|
type: :development
|
105
147
|
prerelease: false
|
106
148
|
version_requirements: !ruby/object:Gem::Requirement
|
107
149
|
requirements:
|
108
150
|
- - "~>"
|
109
151
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
152
|
+
version: '1.2'
|
111
153
|
- !ruby/object:Gem::Dependency
|
112
154
|
name: rubocop-performance
|
113
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,14 +170,14 @@ dependencies:
|
|
128
170
|
requirements:
|
129
171
|
- - "~>"
|
130
172
|
- !ruby/object:Gem::Version
|
131
|
-
version: '
|
173
|
+
version: '2.0'
|
132
174
|
type: :development
|
133
175
|
prerelease: false
|
134
176
|
version_requirements: !ruby/object:Gem::Requirement
|
135
177
|
requirements:
|
136
178
|
- - "~>"
|
137
179
|
- !ruby/object:Gem::Version
|
138
|
-
version: '
|
180
|
+
version: '2.0'
|
139
181
|
description: 'Toys template for gems, like building, releasing, etc.
|
140
182
|
|
141
183
|
'
|
@@ -151,6 +193,8 @@ files:
|
|
151
193
|
- lib/gem_toys.rb
|
152
194
|
- lib/gem_toys/template.rb
|
153
195
|
- lib/gem_toys/template/common_code.rb
|
196
|
+
- lib/gem_toys/template/release.rb
|
197
|
+
- lib/gem_toys/template/versions.rb
|
154
198
|
- lib/gem_toys/version.rb
|
155
199
|
homepage: https://github.com/AlexWayfer/gem_toys
|
156
200
|
licenses:
|
@@ -167,14 +211,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
167
211
|
requirements:
|
168
212
|
- - ">="
|
169
213
|
- !ruby/object:Gem::Version
|
170
|
-
version: '2.
|
214
|
+
version: '2.5'
|
171
215
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
172
216
|
requirements:
|
173
217
|
- - ">="
|
174
218
|
- !ruby/object:Gem::Version
|
175
219
|
version: '0'
|
176
220
|
requirements: []
|
177
|
-
rubygems_version: 3.1.
|
221
|
+
rubygems_version: 3.1.4
|
178
222
|
signing_key:
|
179
223
|
specification_version: 4
|
180
224
|
summary: Toys template for gems
|