gem_toys 0.6.1 → 0.7.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 +5 -0
- data/README.md +8 -1
- data/lib/gem_toys/template.rb +12 -3
- data/lib/gem_toys/template/common_code.rb +2 -6
- data/lib/gem_toys/template/release.rb +17 -62
- data/lib/gem_toys/template/release/changelog.rb +48 -0
- data/lib/gem_toys/template/release/git.rb +41 -0
- data/lib/gem_toys/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b8a68d7567f6698b428f46a2f69694259e066412bedb21b55eda4585b76c70b
|
4
|
+
data.tar.gz: 74cfd96138c6e0a10eacec2235500f775d5f02b0f3ab215f88b0c911a8cf33a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98da90d85c1cb6f361bdef8d7a0ec42d5c0ba500121f3fc9655dacb24f160f9a9c21599afb01bf9ed3672a954c9ef27df384e988b8ad382e505cb1bedb1e1cab
|
7
|
+
data.tar.gz: d236a46c35fcedeb008aafbb4f1836e497c39d2b001b125634a60b114b555fd567b4236aa2294b50f708869a80dd416bf1998a585494c3854ba545128a0729a4
|
data/CHANGELOG.md
CHANGED
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
|
-
|
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
|
data/lib/gem_toys/template.rb
CHANGED
@@ -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(
|
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
|
@@ -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('%
|
74
|
+
DateTime.parse(version[:created_at]).strftime('%F %R')
|
79
75
|
rescue Date::Error
|
80
76
|
version[:created_at]
|
81
77
|
end
|
@@ -1,20 +1,33 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'release/changelog'
|
4
|
+
require_relative 'release/git'
|
5
|
+
|
3
6
|
module GemToys
|
4
7
|
class Template
|
5
8
|
## Template with gem release tool, expanding internally
|
6
9
|
class Release
|
7
10
|
include Toys::Template
|
8
11
|
|
9
|
-
attr_reader :version_file_path, :unreleased_title
|
12
|
+
attr_reader :changelog_file_name, :version_file_path, :version_tag_prefix, :unreleased_title
|
10
13
|
|
11
|
-
def initialize(
|
14
|
+
def initialize(
|
15
|
+
changelog_file_name:,
|
16
|
+
version_file_path:,
|
17
|
+
version_tag_prefix:,
|
18
|
+
unreleased_title:
|
19
|
+
)
|
20
|
+
@changelog_file_name = changelog_file_name
|
12
21
|
@version_file_path = version_file_path
|
22
|
+
@version_tag_prefix = version_tag_prefix
|
13
23
|
@unreleased_title = unreleased_title
|
14
24
|
end
|
15
25
|
|
16
26
|
on_expand do |template|
|
17
27
|
tool :release do
|
28
|
+
include Release::Changelog
|
29
|
+
include Release::Git
|
30
|
+
|
18
31
|
required_arg :new_version
|
19
32
|
|
20
33
|
to_run do
|
@@ -36,22 +49,8 @@ module GemToys
|
|
36
49
|
|
37
50
|
wait_for_manual_check
|
38
51
|
|
39
|
-
##
|
40
|
-
|
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'
|
52
|
+
## Commit, tag, push
|
53
|
+
process_git
|
55
54
|
|
56
55
|
puts 'Pushing gem...'
|
57
56
|
sh "gem push #{current_gem_file}"
|
@@ -100,50 +99,6 @@ module GemToys
|
|
100
99
|
)
|
101
100
|
end
|
102
101
|
|
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
|
125
|
-
|
126
|
-
@changelog_lines.insert(
|
127
|
-
unreleased_title_index + 2,
|
128
|
-
'#' * unreleased_title.scan(/^#+/).first.size + " #{@new_version} (#{@today})\n\n"
|
129
|
-
).join
|
130
|
-
end
|
131
|
-
|
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
|
137
|
-
end
|
138
|
-
|
139
|
-
def commit_changes
|
140
|
-
puts 'Committing changes...'
|
141
|
-
|
142
|
-
sh "git add #{version_file_path} #{changelog_file_path}"
|
143
|
-
|
144
|
-
sh "git commit -m 'Update version to #{@new_version}'"
|
145
|
-
end
|
146
|
-
|
147
102
|
def wait_for_manual_check
|
148
103
|
$stdout.puts
|
149
104
|
sh "git diff #{version_file_path} #{changelog_file_path}"
|
@@ -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.match(/\((.*)\)/)[1]) == @today
|
19
|
+
|
20
|
+
abort "There is already #{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
|
data/lib/gem_toys/version.rb
CHANGED
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.
|
4
|
+
version: 0.7.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-
|
11
|
+
date: 2021-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: alt_memery
|
@@ -194,6 +194,8 @@ files:
|
|
194
194
|
- lib/gem_toys/template.rb
|
195
195
|
- lib/gem_toys/template/common_code.rb
|
196
196
|
- lib/gem_toys/template/release.rb
|
197
|
+
- lib/gem_toys/template/release/changelog.rb
|
198
|
+
- lib/gem_toys/template/release/git.rb
|
197
199
|
- lib/gem_toys/template/versions.rb
|
198
200
|
- lib/gem_toys/version.rb
|
199
201
|
homepage: https://github.com/AlexWayfer/gem_toys
|