verto 0.7.0 → 0.10.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +51 -0
- data/.rubocop.yml +23 -0
- data/.rubocop_todo.yml +50 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +18 -0
- data/Gemfile +3 -1
- data/Gemfile.lock +47 -24
- data/README.md +31 -25
- data/Rakefile +7 -5
- data/Vertofile +5 -19
- data/bin/console +4 -3
- data/djin.yml +37 -0
- data/exe/verto +6 -4
- data/lib/verto.rb +55 -23
- data/lib/verto/commands/base_command.rb +7 -2
- data/lib/verto/commands/main_command.rb +10 -6
- data/lib/verto/commands/tag_command.rb +38 -24
- data/lib/verto/dsl.rb +2 -0
- data/lib/verto/dsl/built_in_hooks.rb +3 -1
- data/lib/verto/dsl/file.rb +4 -2
- data/lib/verto/dsl/hook.rb +2 -0
- data/lib/verto/dsl/interpreter.rb +8 -7
- data/lib/verto/dsl/syntax.rb +18 -7
- data/lib/verto/dsl/update_changelog.rb +60 -0
- data/lib/verto/repositories/tag_repository.rb +2 -0
- data/lib/verto/utils/cli_helpers.rb +15 -0
- data/lib/verto/utils/command_options.rb +4 -2
- data/lib/verto/utils/semantic_version.rb +2 -0
- data/lib/verto/utils/strict_hash.rb +9 -0
- data/lib/verto/utils/system_command_executor.rb +4 -2
- data/lib/verto/utils/tag_filter.rb +7 -5
- data/lib/verto/utils/template.rb +2 -0
- data/lib/verto/utils/templates/Vertofile +25 -28
- data/lib/verto/version.rb +3 -1
- data/verto.gemspec +29 -25
- metadata +55 -21
- data/.travis.yml +0 -13
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'verto'
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +11,5 @@ require "verto"
|
|
10
11
|
# require "pry"
|
11
12
|
# Pry.start
|
12
13
|
|
13
|
-
require
|
14
|
+
require 'irb'
|
14
15
|
IRB.start(__FILE__)
|
data/djin.yml
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
djin_version: '0.10.0'
|
2
|
+
|
3
|
+
tasks:
|
4
|
+
run:
|
5
|
+
local:
|
6
|
+
run:
|
7
|
+
- {{args}}
|
8
|
+
|
9
|
+
set_verto_version:
|
10
|
+
local:
|
11
|
+
run:
|
12
|
+
- VERTO_BUILD_VERSION=$(cat lib/verto/version.rb | grep -ohE '\d+\.\d+\.\d+')
|
13
|
+
|
14
|
+
tag_up:
|
15
|
+
docker:
|
16
|
+
image: "catks/verto:0.10.0"
|
17
|
+
run:
|
18
|
+
commands:
|
19
|
+
- "verto tag up {{args}}"
|
20
|
+
options: |
|
21
|
+
-v ~/.gitconfig:/etc/gitconfig -v $(pwd):/usr/src/project \
|
22
|
+
-v $HOME/.ssh/known_hosts:/root/.ssh/known_hosts -v $HOME/.ssh/id_rsa:/root/.ssh/id_rsa \
|
23
|
+
-e SSH_PRIVATE_KEY=/root/.ssh/id_rsa \
|
24
|
+
--entrypoint='' \
|
25
|
+
depends_on:
|
26
|
+
- set_verto_version
|
27
|
+
|
28
|
+
release:
|
29
|
+
local:
|
30
|
+
run:
|
31
|
+
- bundle exec rake release
|
32
|
+
- docker build . -t verto
|
33
|
+
- docker tag verto catks/verto:$VERTO_BUILD_VERSION
|
34
|
+
- docker push catks/verto:$VERTO_BUILD_VERSION
|
35
|
+
depends_on:
|
36
|
+
- set_verto_version
|
37
|
+
- tag_up
|
data/exe/verto
CHANGED
@@ -1,17 +1,19 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
Signal.trap('INT') { exit 2 }
|
2
5
|
|
3
6
|
require_relative '../lib/verto'
|
4
7
|
|
5
8
|
vertofile_path = ENV['VERTOFILE_PATH'] || Pathname.new(Dir.pwd).join('Vertofile').to_s
|
6
|
-
|
7
9
|
begin
|
8
|
-
Verto::DSL.load_file(vertofile_path) if File.
|
10
|
+
Verto::DSL.load_file(vertofile_path) if File.exist?(vertofile_path)
|
9
11
|
|
10
12
|
Verto::MainCommand.start(ARGV)
|
11
13
|
|
12
14
|
# TODO: Improve error Message Handling
|
13
|
-
rescue Verto::ExitError =>
|
14
|
-
Verto.stderr.puts
|
15
|
+
rescue Verto::ExitError => e
|
16
|
+
Verto.stderr.puts e.message
|
15
17
|
Verto.stderr.puts 'Exiting Verto...'
|
16
18
|
exit 1
|
17
19
|
end
|
data/lib/verto.rb
CHANGED
@@ -1,18 +1,22 @@
|
|
1
|
-
|
2
|
-
require "dry-container"
|
3
|
-
require "dry-configurable"
|
4
|
-
require "dry-auto_inject"
|
5
|
-
require "vseries"
|
6
|
-
require "pathname"
|
1
|
+
# frozen_string_literal: true
|
7
2
|
|
8
|
-
require
|
9
|
-
require
|
3
|
+
require 'thor'
|
4
|
+
require 'dry-container'
|
5
|
+
require 'dry-configurable'
|
6
|
+
require 'dry-auto_inject'
|
7
|
+
require 'vseries'
|
8
|
+
require 'mustache'
|
9
|
+
require 'pathname'
|
10
|
+
|
11
|
+
require 'verto/version'
|
12
|
+
require 'verto/utils/command_options'
|
10
13
|
|
11
14
|
module Verto
|
12
15
|
extend Dry::Configurable
|
13
16
|
|
14
17
|
setting :pre_release do
|
15
18
|
setting :initial_number, 1
|
19
|
+
setting :default_identifier, 'rc'
|
16
20
|
end
|
17
21
|
|
18
22
|
setting :project do
|
@@ -36,6 +40,16 @@ module Verto
|
|
36
40
|
setting :push_after_tag_creation, false
|
37
41
|
end
|
38
42
|
|
43
|
+
setting :changelog do
|
44
|
+
setting :format,
|
45
|
+
<<~CHANGELOG
|
46
|
+
## {{new_version}} - #{Time.now.strftime('%d/%m/%Y')}
|
47
|
+
{{#version_changes}}
|
48
|
+
* {{.}}
|
49
|
+
{{/version_changes}}
|
50
|
+
CHANGELOG
|
51
|
+
end
|
52
|
+
|
39
53
|
setting :hooks, []
|
40
54
|
setting :command_options, CommandOptions.new
|
41
55
|
|
@@ -53,7 +67,10 @@ module Verto
|
|
53
67
|
def self.container
|
54
68
|
@container ||= Dry::Container.new.tap do |container|
|
55
69
|
container.register('system_command_executor') { SystemCommandExecutor.new }
|
56
|
-
container.register('system_command_executor_without_output')
|
70
|
+
container.register('system_command_executor_without_output') do
|
71
|
+
SystemCommandExecutor.new(stdout: nil, stderr: nil)
|
72
|
+
end
|
73
|
+
container.register('cli_helpers') { CliHelpers }
|
57
74
|
|
58
75
|
container.register('tag_repository') { TagRepository.new }
|
59
76
|
|
@@ -71,6 +88,10 @@ module Verto
|
|
71
88
|
container.namespace('project') do
|
72
89
|
register('path') { Verto.config.project.path }
|
73
90
|
end
|
91
|
+
|
92
|
+
container.namespace('changelog') do
|
93
|
+
register('format') { Verto.config.changelog.format }
|
94
|
+
end
|
74
95
|
end
|
75
96
|
end
|
76
97
|
|
@@ -85,19 +106,30 @@ module Verto
|
|
85
106
|
def self.stderr
|
86
107
|
Verto.container.resolve('stderr')
|
87
108
|
end
|
109
|
+
|
110
|
+
def self.current_moment
|
111
|
+
@current_moment
|
112
|
+
end
|
113
|
+
|
114
|
+
def self.current_moment=(moment)
|
115
|
+
@current_moment = moment
|
116
|
+
end
|
88
117
|
end
|
89
118
|
|
90
|
-
require
|
91
|
-
require
|
92
|
-
require
|
93
|
-
require
|
94
|
-
require
|
95
|
-
require
|
96
|
-
require
|
97
|
-
require
|
98
|
-
require
|
99
|
-
require
|
100
|
-
require
|
101
|
-
require
|
102
|
-
require
|
103
|
-
require
|
119
|
+
require 'verto/utils/semantic_version.rb'
|
120
|
+
require 'verto/utils/system_command_executor'
|
121
|
+
require 'verto/utils/tag_filter'
|
122
|
+
require 'verto/utils/template'
|
123
|
+
require 'verto/utils/cli_helpers'
|
124
|
+
require 'verto/utils/strict_hash'
|
125
|
+
require 'verto/dsl'
|
126
|
+
require 'verto/dsl/syntax'
|
127
|
+
require 'verto/dsl/interpreter'
|
128
|
+
require 'verto/dsl/hook'
|
129
|
+
require 'verto/dsl/file'
|
130
|
+
require 'verto/dsl/update_changelog'
|
131
|
+
require 'verto/dsl/built_in_hooks'
|
132
|
+
require 'verto/commands/base_command'
|
133
|
+
require 'verto/commands/tag_command'
|
134
|
+
require 'verto/commands/main_command'
|
135
|
+
require 'verto/repositories/tag_repository'
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Verto
|
2
4
|
class BaseCommand < Thor
|
3
5
|
def self.exit_on_failure?
|
@@ -23,8 +25,11 @@ module Verto
|
|
23
25
|
|
24
26
|
moments_to_call.each do |moment|
|
25
27
|
Verto.config.hooks
|
26
|
-
|
27
|
-
|
28
|
+
.select { |hook| hook.moment == moment.to_sym }
|
29
|
+
.each do |hook|
|
30
|
+
Verto.current_moment = hook.moment
|
31
|
+
hook.call(with_attributes: with_attributes)
|
32
|
+
end
|
28
33
|
end
|
29
34
|
end
|
30
35
|
end
|
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Verto
|
2
4
|
class MainCommand < BaseCommand
|
3
|
-
desc
|
5
|
+
desc 'tag SUBCOMMAND ...ARGS', 'manage the repository tags'
|
4
6
|
subcommand 'tag', Verto::TagCommand
|
5
7
|
|
6
|
-
desc
|
8
|
+
desc 'init', 'Initialize a Vertofile in your repository'
|
7
9
|
|
8
10
|
option :path, type: :string, default: nil
|
9
11
|
def init
|
@@ -14,7 +16,7 @@ module Verto
|
|
14
16
|
Template.render('Vertofile', to: path)
|
15
17
|
end
|
16
18
|
|
17
|
-
desc
|
19
|
+
desc 'version', 'Shows Verto version'
|
18
20
|
|
19
21
|
def version
|
20
22
|
Verto.stdout.puts Verto::VERSION
|
@@ -23,12 +25,14 @@ module Verto
|
|
23
25
|
private
|
24
26
|
|
25
27
|
def validate_current_vertofile!(path)
|
28
|
+
return unless Pathname.new(path).join('Vertofile').exist?
|
29
|
+
|
26
30
|
command_error!(
|
27
31
|
<<~ERROR
|
28
|
-
|
29
|
-
|
32
|
+
Project already have a Vertofile.
|
33
|
+
If you want to generate a new with verto init, delete the current one with: `rm Vertofile`
|
30
34
|
ERROR
|
31
|
-
)
|
35
|
+
)
|
32
36
|
end
|
33
37
|
end
|
34
38
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Verto
|
2
4
|
class TagCommand < BaseCommand
|
3
|
-
desc
|
5
|
+
desc 'up', "Create's a new tag"
|
4
6
|
|
5
7
|
option :major, type: :boolean, default: false
|
6
8
|
option :minor, type: :boolean, default: false
|
@@ -13,7 +15,7 @@ module Verto
|
|
13
15
|
def up
|
14
16
|
load_config_hooks!
|
15
17
|
|
16
|
-
call_hooks(%i[before before_tag_up], with_attributes: { command_options: options}
|
18
|
+
call_hooks(%i[before before_tag_up], with_attributes: { command_options: options })
|
17
19
|
|
18
20
|
validate_version_option_presence!
|
19
21
|
|
@@ -27,7 +29,7 @@ module Verto
|
|
27
29
|
|
28
30
|
validate_new_version!(new_version, latest_version)
|
29
31
|
|
30
|
-
call_hooks(:before_tag_creation, with_attributes: { new_version: new_version }
|
32
|
+
call_hooks(:before_tag_creation, with_attributes: { new_version: new_version })
|
31
33
|
|
32
34
|
stderr.puts "Creating Tag #{version_prefix}#{new_version}..."
|
33
35
|
tag_repository.create!("#{version_prefix}#{new_version}")
|
@@ -42,20 +44,20 @@ module Verto
|
|
42
44
|
include Verto.import['tag_repository']
|
43
45
|
|
44
46
|
def up_version(version, options)
|
45
|
-
up_options = options.select { |
|
46
|
-
up_option = up_options.
|
47
|
+
up_options = options.select { |_, value| value == true }.keys.map(&:to_sym) & %i[major minor patch]
|
48
|
+
up_option = up_options.min
|
47
49
|
|
48
50
|
new_version = version.up(up_option)
|
49
51
|
|
50
52
|
if options[:pre_release]
|
51
|
-
identifier = pre_release_configured? ? options[:pre_release] : version.pre_release.name
|
53
|
+
identifier = pre_release_configured? ? options[:pre_release] : version.pre_release.name || default_identifier
|
52
54
|
new_version = new_version.with_pre_release(identifier)
|
53
|
-
|
55
|
+
if new_version.pre_release.name == version.pre_release.name && new_version == version
|
56
|
+
new_version = new_version.up(:pre_release)
|
57
|
+
end
|
54
58
|
end
|
55
59
|
|
56
|
-
if options[:release]
|
57
|
-
new_version = new_version.release_version
|
58
|
-
end
|
60
|
+
new_version = new_version.release_version if options[:release]
|
59
61
|
|
60
62
|
new_version
|
61
63
|
end
|
@@ -65,38 +67,44 @@ module Verto
|
|
65
67
|
end
|
66
68
|
|
67
69
|
def validate_latest_tag!(latest_tag)
|
70
|
+
return if latest_tag
|
71
|
+
|
68
72
|
command_error!(
|
69
73
|
<<~TEXT
|
70
74
|
Project doesn't have a previous tag version, create a new tag with git.
|
71
75
|
eg: `git tag #{version_prefix}0.1.0`
|
72
76
|
TEXT
|
73
|
-
)
|
77
|
+
)
|
74
78
|
end
|
75
79
|
|
76
80
|
def validate_new_version!(new_version, latest_version)
|
81
|
+
return unless new_version < latest_version && Verto.config.version.validations.new_version_must_be_bigger
|
82
|
+
|
77
83
|
command_error!(
|
78
84
|
<<~TEXT
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
85
|
+
New version(#{new_version}) can't be equal or lower than latest version(#{latest_version})
|
86
|
+
run up --pre-release with --patch, --minor or --major (eg: verto tag up --patch --pre-release=rc),
|
87
|
+
add filters (eg: verto tag up --pre-release --filter=pre_release_only)
|
88
|
+
or disable tag validation in Vertofile with config.version.validations.new_version_must_be_bigger = false
|
83
89
|
TEXT
|
84
|
-
)
|
90
|
+
)
|
85
91
|
end
|
86
92
|
|
87
93
|
def validate_version_option_presence!
|
94
|
+
return if options[:major] || options[:minor] || options[:patch] || options[:pre_release] || options[:release]
|
95
|
+
|
88
96
|
command_error!(
|
89
97
|
<<~TEXT
|
90
|
-
|
91
|
-
|
98
|
+
You must specify the version number to be increased, use the some of the options(eg: --major, --minor, --patch, --pre_release=rc)
|
99
|
+
or configure a Vertofile to specify a default option for current context, eg:
|
92
100
|
|
93
|
-
|
94
|
-
|
95
|
-
|
101
|
+
context('qa') {
|
102
|
+
before_command('tag_up') {
|
103
|
+
command_options.add(pre_release: 'rc')
|
104
|
+
}
|
96
105
|
}
|
97
|
-
}
|
98
106
|
TEXT
|
99
|
-
)
|
107
|
+
)
|
100
108
|
end
|
101
109
|
|
102
110
|
def load_filter
|
@@ -108,8 +116,14 @@ module Verto
|
|
108
116
|
end
|
109
117
|
|
110
118
|
def load_config_hooks!
|
111
|
-
|
119
|
+
if Verto.config.git.pull_before_tag_creation
|
120
|
+
Verto.config.hooks.prepend Verto::DSL::BuiltInHooks::GitPullCurrentBranch
|
121
|
+
end
|
112
122
|
Verto.config.hooks << Verto::DSL::BuiltInHooks::GitPushCurrentBranch if Verto.config.git.push_after_tag_creation
|
113
123
|
end
|
124
|
+
|
125
|
+
def default_identifier
|
126
|
+
Verto.config.pre_release.default_identifier
|
127
|
+
end
|
114
128
|
end
|
115
129
|
end
|
data/lib/verto/dsl.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Verto
|
2
4
|
module DSL
|
3
5
|
module BuiltInHooks
|
@@ -6,7 +8,7 @@ module Verto
|
|
6
8
|
end
|
7
9
|
|
8
10
|
GitPushTags = DSL::Hook.new(moment: :after) do
|
9
|
-
git!(
|
11
|
+
git!('push --tags')
|
10
12
|
end
|
11
13
|
|
12
14
|
GitPushCurrentBranchCommits = DSL::Hook.new(moment: :after) do
|
data/lib/verto/dsl/file.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Verto
|
2
4
|
module DSL
|
3
5
|
class File
|
@@ -36,8 +38,8 @@ module Verto
|
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
+
alias gsub replace_all
|
42
|
+
alias sub replace
|
41
43
|
|
42
44
|
private
|
43
45
|
|
data/lib/verto/dsl/hook.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Verto
|
2
4
|
module DSL
|
3
5
|
class Interpreter
|
@@ -6,15 +8,14 @@ module Verto
|
|
6
8
|
# TODO: Wrap stacktrace
|
7
9
|
Error = Class.new(Verto::ExitError)
|
8
10
|
|
9
|
-
def evaluate(vertofile_content=nil, attributes: {}, &block)
|
11
|
+
def evaluate(vertofile_content = nil, attributes: {}, &block)
|
10
12
|
with_attributes(attributes) do
|
11
|
-
vertofile_content ? instance_eval(vertofile_content)
|
13
|
+
vertofile_content ? instance_eval(vertofile_content) : instance_eval(&block)
|
12
14
|
end
|
15
|
+
rescue StandardError => e
|
16
|
+
raise e if e.is_a?(Verto::ExitError)
|
13
17
|
|
14
|
-
|
15
|
-
raise error if error.is_a?(Verto::ExitError)
|
16
|
-
|
17
|
-
raise Error, error.message
|
18
|
+
raise Error, e.message
|
18
19
|
end
|
19
20
|
|
20
21
|
private
|
@@ -27,7 +28,7 @@ module Verto
|
|
27
28
|
|
28
29
|
block.call
|
29
30
|
|
30
|
-
attributes.each do |key,
|
31
|
+
attributes.each do |key, _value|
|
31
32
|
instance_variable_set("@#{key}", nil)
|
32
33
|
singleton_class.remove_method(key)
|
33
34
|
end
|