verto 0.7.0 → 0.10.2

Sign up to get free protection for your applications and to get access to all the features.
data/bin/console CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "verto"
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 "irb"
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.exists?(vertofile_path)
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 => ex
14
- Verto.stderr.puts ex.message
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
- require "thor"
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 "verto/version"
9
- require "verto/utils/command_options"
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') { SystemCommandExecutor.new(stdout: nil, stderr: nil) }
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 "verto/utils/semantic_version.rb"
91
- require "verto/utils/system_command_executor"
92
- require "verto/utils/tag_filter"
93
- require "verto/utils/template"
94
- require "verto/dsl"
95
- require "verto/dsl/syntax"
96
- require "verto/dsl/interpreter"
97
- require "verto/dsl/hook"
98
- require "verto/dsl/file"
99
- require "verto/dsl/built_in_hooks"
100
- require "verto/commands/base_command"
101
- require "verto/commands/tag_command"
102
- require "verto/commands/main_command"
103
- require "verto/repositories/tag_repository"
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
- .select { |hook| hook.moment == moment.to_sym }
27
- .each { |hook| hook.call(with_attributes: with_attributes) }
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 "tag SUBCOMMAND ...ARGS", "manage the repository tags"
5
+ desc 'tag SUBCOMMAND ...ARGS', 'manage the repository tags'
4
6
  subcommand 'tag', Verto::TagCommand
5
7
 
6
- desc "init", "Initialize a Vertofile in your repository"
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 "version", "Shows Verto version"
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
- Project already have a Vertofile.
29
- If you want to generate a new with verto init, delete the current one with: `rm Vertofile`
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
- ) if Pathname.new(path).join('Vertofile').exist?
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 "up", "Create's a new tag"
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 { |key,value| value == true }.keys.map(&:to_sym) & [:major, :minor, :patch]
46
- up_option = up_options.sort.first
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
- new_version = new_version.up(:pre_release) if new_version.pre_release.name == version.pre_release.name && new_version == version
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
- ) unless latest_tag
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
- New version(#{new_version}) can't be equal or lower than latest version(#{latest_version})
80
- run up --pre-release with --patch, --minor or --major (eg: verto tag up --pre-release --patch),
81
- add filters (eg: verto tag up --pre-release --filter=pre_release_only)
82
- or disable tag validation in Vertofile with config.version.validations.new_version_must_be_bigger = false
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
- ) if new_version < latest_version && Verto.config.version.validations.new_version_must_be_bigger
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
- You must specify the version number to be increased, use the some of the options(eg: --major, --minor, --patch, --pre_release=rc)
91
- or configure a Vertofile to specify a default option for current context, eg:
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
- context('qa') {
94
- before_command('tag_up') {
95
- command_options.add(pre_release: 'rc')
101
+ context('qa') {
102
+ before_command('tag_up') {
103
+ command_options.add(pre_release: 'rc')
104
+ }
96
105
  }
97
- }
98
106
  TEXT
99
- ) unless options[:major] || options[:minor] || options[:patch] || options[:pre_release] || options[:release]
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
- Verto.config.hooks.prepend Verto::DSL::BuiltInHooks::GitPullCurrentBranch if Verto.config.git.pull_before_tag_creation
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
  def self.load_file(filepath)
@@ -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!("push --tags")
11
+ git!('push --tags')
10
12
  end
11
13
 
12
14
  GitPushCurrentBranchCommits = DSL::Hook.new(moment: :after) do
@@ -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
- alias_method :gsub, :replace_all
40
- alias_method :sub, :replace
41
+ alias gsub replace_all
42
+ alias sub replace
41
43
 
42
44
  private
43
45
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Verto
2
4
  module DSL
3
5
  class Hook
@@ -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) : instance_eval(&block)
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
- rescue StandardError => error
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, value|
31
+ attributes.each do |key, _value|
31
32
  instance_variable_set("@#{key}", nil)
32
33
  singleton_class.remove_method(key)
33
34
  end