avm-tools 0.64.1 → 0.68.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/lib/avm/data/package/dump.rb +1 -0
  3. data/lib/avm/instances/configuration/_locale.rb +16 -0
  4. data/lib/avm/local_projects/instance.rb +28 -1
  5. data/lib/avm/patches/i18n.rb +22 -0
  6. data/lib/avm/patches/object/i18n.rb +17 -0
  7. data/lib/avm/patches/object/template.rb +3 -3
  8. data/lib/avm/projects/stereotype.rb +3 -2
  9. data/lib/avm/projects/stereotypes/git_subrepo/warp.rb +2 -2
  10. data/lib/avm/projects/stereotypes/rails_application.rb +2 -0
  11. data/lib/avm/projects/stereotypes/rails_application/local_project_mixin.rb +18 -0
  12. data/lib/avm/projects/stereotypes/rails_application/update.rb +14 -0
  13. data/lib/avm/projects/stereotypes/ruby_gem/local_project_mixin.rb +9 -0
  14. data/lib/avm/projects/stereotypes/ruby_gem/version_bump.rb +61 -0
  15. data/lib/avm/self.rb +5 -1
  16. data/lib/avm/tools/runner/local_project.rb +5 -0
  17. data/lib/avm/tools/runner/local_project/ruby.rb +24 -0
  18. data/lib/avm/tools/runner/local_project/ruby/bundler.rb +25 -0
  19. data/lib/avm/tools/runner/local_project/ruby/bundler/gemfile_lock.rb +138 -0
  20. data/lib/avm/tools/runner/local_project/test.rb +34 -0
  21. data/lib/avm/tools/runner/local_project/update.rb +1 -2
  22. data/lib/avm/tools/runner/local_project/version_bump.rb +89 -0
  23. data/lib/avm/tools/version.rb +1 -1
  24. data/lib/avm/version.rb +45 -0
  25. data/lib/eac_launcher/git/sub_warp_base.rb +1 -1
  26. data/lib/eac_launcher/publish/base.rb +1 -1
  27. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/gem.rb +5 -1
  28. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/gem/version_file.rb +40 -0
  29. data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/version.rb +1 -1
  30. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_respond.rb +22 -0
  31. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  32. metadata +16 -3
  33. data/lib/avm/local_projects/jobs/update.rb +0 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4e6a74ca2abee19a57dbb17f1857ede525b0386297e58a036ab98d15e601a9d5
4
- data.tar.gz: e94fe357e1fd4ba8a0acd651fdef3e1f60f67465a6758a1ddc899b6aebb87197
3
+ metadata.gz: 804e613bfa303949fb0ed952f999d5815b6de62aea34e9c03c0e87ecf65f35b4
4
+ data.tar.gz: a86f89745be17ae8bc039beb9d0e28680481e30069975c809a9083e42ef17589
5
5
  SHA512:
6
- metadata.gz: 2b59f21007fd2c766ee0b5f8b0cf24da986a036bcafc4fddfd0b5ef26910e1605c541e37a580f7e933d1d7174a25f5465a59c572c6a1d89f085498caf0793f7c
7
- data.tar.gz: a6db12617e9f12a9aaf3d031b1c586ec36e7ac45fc7fa18310f4ddabc1ebc51654e44ed108d23532807e6b6cea3f94c93ee9cdee83d923740d4566e24535e8a1
6
+ metadata.gz: fcd4890d0c29dc11ddd5c1cbce9c5d767900e5e9be10d763afcb91fd73cfdd715c0f6ae217c64fc82f5e87128dbad619500e2ee3a33c4500a29c49739b5a93dc
7
+ data.tar.gz: 89a8e507755008a2f7a18c0ee84ed2572588aff5ab12e0e9d5ec7e897a7c397f4cc6e1d2e7d83595d46fd3b835fcd3104dbb5cfebb38ae837113f25091169a85
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'avm/files/rotate'
3
4
  require 'eac_ruby_utils/core_ext'
4
5
  require 'minitar'
5
6
 
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/patches/eac_ruby_gems_utils/gem'
4
+ require 'i18n'
5
+
6
+ module Avm
7
+ module Instances
8
+ class Configuration < ::EacRubyUtils::Configs
9
+ LOCALE_KEY = :locale
10
+
11
+ def locale
12
+ read_entry(LOCALE_KEY) || ::I18n.default_locale
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,8 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'avm/instances/configuration'
3
4
  require 'eac_launcher/paths/real'
4
5
  require 'eac_ruby_utils/core_ext'
5
6
  require 'avm/projects/stereotypes'
7
+ require 'i18n'
6
8
 
7
9
  module Avm
8
10
  module LocalProjects
@@ -13,21 +15,46 @@ module Avm
13
15
  source_stereotypes_mixins
14
16
  end
15
17
 
18
+ delegate :to_s, to: :path
19
+
20
+ def locale
21
+ configuration.if_present(&:locale) || ::I18n.default_locale
22
+ end
23
+
16
24
  # Backward compatibility with [EacLauncher::Paths::Logical].
17
25
  # @return [EacLauncher::Paths::Real].
18
26
  def real
19
27
  ::EacLauncher::Paths::Real.new(path.to_path)
20
28
  end
21
29
 
30
+ def run_job(job, job_args = [])
31
+ stereotypes.each { |stereotype| run_stereotype_job(stereotype, job, job_args) }
32
+ end
33
+
22
34
  private
23
35
 
36
+ # @return [Avm::Instances::Configuration]
37
+ def configuration_uncached
38
+ ::Avm::Instances::Configuration.find_in_path(path)
39
+ end
40
+
41
+ def run_stereotype_job(stereotype, job, job_args)
42
+ job_class_method = "#{job}_class"
43
+ if stereotype.send(job_class_method).present?
44
+ puts stereotype.label + ": #{job} class found. Running..."
45
+ stereotype.send(job_class_method).new(self, *job_args).run
46
+ else
47
+ puts stereotype.label + ": #{job} class not found"
48
+ end
49
+ end
50
+
24
51
  def stereotypes_uncached
25
52
  ::Avm::Projects::Stereotypes.list.select { |s| s.match?(self) }
26
53
  end
27
54
 
28
55
  def source_stereotypes_mixins
29
56
  stereotypes.each do |s|
30
- s.local_project_mixin_module.if_present { |v| extend(v) }
57
+ s.local_project_mixin_module.if_present { |v| singleton_class.include(v) }
31
58
  end
32
59
  end
33
60
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/self'
4
+ require 'i18n'
5
+
6
+ module Avm
7
+ module Patches
8
+ module I18n
9
+ class << self
10
+ def setup_i18n
11
+ ::I18n.load_path += locale_files_paths.map(&:to_path)
12
+ end
13
+
14
+ def locale_files_paths
15
+ ::Avm::Self.root.join('locale').glob('*.yml')
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ ::Avm::Patches::I18n.setup_i18n
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/patches/i18n'
4
+
5
+ class Object
6
+ def translate(entry_suffix, values = {})
7
+ ::I18n.translate(translate_entry_full(entry_suffix), values)
8
+ end
9
+
10
+ def translate_entry_full(entry_suffix)
11
+ "#{translate_entry_self_prefix}.#{entry_suffix}"
12
+ end
13
+
14
+ def translate_entry_self_prefix
15
+ self.class.name.underscore.gsub('/', '.')
16
+ end
17
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'avm/self'
3
4
  require 'eac_ruby_utils/patches/object/template'
4
5
 
5
- ::EacRubyUtils::Templates::Searcher.default.included_paths << ::File.expand_path(
6
- ('../' * 4) + 'template', __dir__
7
- )
6
+ ::EacRubyUtils::Templates::Searcher.default.included_paths <<
7
+ ::Avm::Self.root.join('template').to_path
@@ -37,6 +37,7 @@ module Avm
37
37
  local_project_mixin: ::Module,
38
38
  publish: ::Class,
39
39
  update: ::Class,
40
+ version_bump: ::Class,
40
41
  warp: ::Class
41
42
  }.each do |name, is_a|
42
43
  define_method "#{name}_#{is_a.name.underscore}" do
@@ -47,14 +48,14 @@ module Avm
47
48
  private
48
49
 
49
50
  def sub_constant(constant_name, is_a)
51
+ return nil unless const_defined?(constant_name)
52
+
50
53
  constant = const_get(constant_name)
51
54
  unless is_a.if_present(true) { |v| constant.is_a?(v) }
52
55
  raise("#{constant} is not a #{is_a}")
53
56
  end
54
57
 
55
58
  constant
56
- rescue NameError
57
- nil
58
59
  end
59
60
  end
60
61
  end
@@ -32,7 +32,7 @@ module Avm
32
32
  return if parent_git_warped.rev_parse(subrepo_parent_hash) &&
33
33
  parent_git_warped.descendant?('HEAD', subrepo_parent_hash)
34
34
 
35
- raise EacLauncher::Instances::Errors::Base,
35
+ raise Avm::Launcher::Errors::Base,
36
36
  "Subrepo parent hash \"#{subrepo_parent_hash}\"" \
37
37
  " not found in \"#{parent_git_warped}\""
38
38
  end
@@ -42,7 +42,7 @@ module Avm
42
42
  h = data['Pull Parent']
43
43
  return h if h.present?
44
44
 
45
- raise EacLauncher::Instances::Errors::Base, "Subrepo parent hash is blank: #{data}"
45
+ raise Avm::Launcher::Errors::Base, "Subrepo parent hash is blank: #{data}"
46
46
  end
47
47
 
48
48
  def init_aux
@@ -1,11 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'avm/projects/stereotype'
4
+ require 'eac_ruby_utils/core_ext'
4
5
 
5
6
  module Avm
6
7
  module Projects
7
8
  module Stereotypes
8
9
  class RailsApplication
10
+ require_sub __FILE__
9
11
  include Avm::Projects::Stereotype
10
12
 
11
13
  class << self
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/projects/stereotypes/ruby_gem/local_project_mixin'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Projects
8
+ module Stereotypes
9
+ class RailsApplication
10
+ module LocalProjectMixin
11
+ common_concern do
12
+ include ::Avm::Projects::Stereotypes::RubyGem::LocalProjectMixin
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/projects/stereotypes/ruby_gem/update'
4
+
5
+ module Avm
6
+ module Projects
7
+ module Stereotypes
8
+ class RailsApplication
9
+ class Update < ::Avm::Projects::Stereotypes::RubyGem::Update
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'avm/patches/eac_ruby_gems_utils/gem'
4
+ require 'avm/version'
4
5
  require 'eac_ruby_utils/core_ext'
5
6
 
6
7
  module Avm
@@ -12,6 +13,14 @@ module Avm
12
13
  def ruby_gem
13
14
  @ruby_gem ||= ::EacRubyGemsUtils::Gem.new(path)
14
15
  end
16
+
17
+ def version
18
+ ruby_gem.version.if_present { |v| ::Avm::Version.new(v) }
19
+ end
20
+
21
+ def version=(value)
22
+ ruby_gem.version_file.value = value
23
+ end
15
24
  end
16
25
  end
17
26
  end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/patches/object/i18n'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Projects
8
+ module Stereotypes
9
+ class RubyGem
10
+ class VersionBump
11
+ enable_console_speaker
12
+ common_constructor :instance, :target_version
13
+
14
+ def run
15
+ git_checkout
16
+ change_version
17
+ bundle_run
18
+ git_commit
19
+ end
20
+
21
+ private
22
+
23
+ def bundle_run
24
+ infom 'Running "bundle install"...'
25
+ instance.ruby_gem.bundle('install').execute!
26
+ end
27
+
28
+ def change_version
29
+ infom 'Setting project version...'
30
+ instance.version = target_version
31
+ end
32
+
33
+ def git_checkout
34
+ return unless instance.respond_to?(:git_repo)
35
+
36
+ infom "Checkouting #{changing_files.map(&:to_path).join(', ')}..."
37
+ instance.git_repo.command('checkout', '--',
38
+ *changing_files.map(&:to_path)).execute!
39
+ end
40
+
41
+ def git_commit
42
+ return unless instance.respond_to?(:git_repo)
43
+
44
+ infom "Commiting #{changing_files.map(&:to_path).join(', ')}..."
45
+ instance.git_repo.command('commit', '-m', git_commit_message, '--',
46
+ *changing_files.map(&:to_path)).execute!
47
+ end
48
+
49
+ def git_commit_message
50
+ ::I18n.default_locale = instance.locale
51
+ translate(__method__, version: target_version)
52
+ end
53
+
54
+ def changing_files
55
+ [instance.ruby_gem.gemfile_lock_path, instance.ruby_gem.version_file_path]
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -10,12 +10,16 @@ module Avm
10
10
 
11
11
  class << self
12
12
  def application
13
- @application ||= ::EacRubyBase0::Application.new(::File.expand_path('../..', __dir__))
13
+ @application ||= ::EacRubyBase0::Application.new(root.to_path)
14
14
  end
15
15
 
16
16
  def instance
17
17
  @instance ||= ::Avm::Self::Instance.by_id('avm-tools_self')
18
18
  end
19
+
20
+ def root
21
+ ::Pathname.new('../..').expand_path(__dir__)
22
+ end
19
23
  end
20
24
  end
21
25
  end
@@ -17,6 +17,11 @@ module Avm
17
17
  subcommands
18
18
  end
19
19
 
20
+ def instance_banner
21
+ infov 'Instance', instance
22
+ infov 'Stereotypes', instance.stereotypes.map(&:label).join(', ')
23
+ end
24
+
20
25
  private
21
26
 
22
27
  def instance_uncached
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/patches/eac_ruby_gems_utils/gem'
4
+ require 'eac_cli/default_runner'
5
+ require 'eac_ruby_utils/console/docopt_runner'
6
+ require 'eac_ruby_utils/core_ext'
7
+
8
+ module Avm
9
+ module Tools
10
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
11
+ class LocalProject < ::EacRubyUtils::Console::DocoptRunner
12
+ class Ruby < ::EacRubyUtils::Console::DocoptRunner
13
+ require_sub __FILE__
14
+ include ::EacCli::DefaultRunner
15
+
16
+ runner_definition do
17
+ desc 'Ruby utitilies for local projects.'
18
+ subcommands
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/default_runner'
4
+ require 'eac_ruby_utils/console/docopt_runner'
5
+ require 'eac_ruby_utils/core_ext'
6
+
7
+ module Avm
8
+ module Tools
9
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
10
+ class LocalProject < ::EacRubyUtils::Console::DocoptRunner
11
+ class Ruby < ::EacRubyUtils::Console::DocoptRunner
12
+ class Bundler < ::EacRubyUtils::Console::DocoptRunner
13
+ require_sub __FILE__
14
+ include ::EacCli::DefaultRunner
15
+
16
+ runner_definition do
17
+ desc 'Ruby\'s bundler utitilies for local projects.'
18
+ subcommands
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,138 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/default_runner'
4
+ require 'eac_ruby_utils/console/docopt_runner'
5
+
6
+ module Avm
7
+ module Tools
8
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
9
+ class LocalProject < ::EacRubyUtils::Console::DocoptRunner
10
+ class Ruby < ::EacRubyUtils::Console::DocoptRunner
11
+ class Bundler < ::EacRubyUtils::Console::DocoptRunner
12
+ class GemfileLock < ::EacRubyUtils::Console::DocoptRunner
13
+ include ::EacCli::DefaultRunner
14
+
15
+ runner_definition do
16
+ desc 'Manipulage a "Gemfile.lock" file.'
17
+ bool_opt '-c', '--continue', 'Continue Git rebase/cherry-pick.'
18
+ bool_opt '-i', '--install', 'Run "bundle install".'
19
+ bool_opt '-u', '--update', 'Run "bundle update".'
20
+ bool_opt '-r', '--recursive', 'Run until Git rebase/cherry-pick is finished.'
21
+ bool_opt '-a', '--all', 'Same as "-ciru".'
22
+ end
23
+
24
+ def run
25
+ loop do
26
+ git_reset_checkout
27
+ bundle_update
28
+ bundle_install
29
+ git_continue
30
+ break if complete?
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def complete?
37
+ !option_or_all?('--recursive') || !conflict?
38
+ end
39
+
40
+ def rebasing?
41
+ instance.git_repo.root_path.join('.git', 'rebase-merge').exist?
42
+ end
43
+
44
+ def git_reset_checkout
45
+ return unless check_capability(__method__, :git_repo, nil)
46
+
47
+ infom 'Reseting...'
48
+ instance.git_repo.command('reset', gemfile_lock).system!
49
+ infom 'Checkouting...'
50
+ instance.git_repo.command('checkout', '--', gemfile_lock).system!
51
+ end
52
+
53
+ def bundle_install
54
+ return unless check_capability(__method__, :ruby_gem, '--install')
55
+
56
+ infom '"bundle install"...'
57
+ bundle_run('install')
58
+ end
59
+
60
+ def bundle_update
61
+ return unless check_capability(__method__, :ruby_gem, '--update')
62
+
63
+ infom '"bundle update"...'
64
+ bundle_run('update')
65
+ end
66
+
67
+ def git_continue
68
+ return unless check_capability(__method__, :git_repo, '--continue')
69
+
70
+ infom "Adding \"#{gemfile_lock}\"..."
71
+ instance.git_repo.command('add', gemfile_lock).execute!
72
+ if rebase_conflict?
73
+ git_continue_run('rebase')
74
+ elsif cherry_conflict?
75
+ git_continue_run('cherry-pick')
76
+ else
77
+ raise 'Unknown how to continue'
78
+ end
79
+ end
80
+
81
+ def git_continue_run(command)
82
+ infom "\"#{command}\" --continue..."
83
+ cmd = instance.git_repo.command(command, '--continue').envvar('GIT_EDITOR', 'true')
84
+ return unless !cmd.system && !conflict?
85
+
86
+ fatal_error "\"#{cmd}\" failed and there is no conflict"
87
+ end
88
+
89
+ def gemfile_lock
90
+ 'Gemfile.lock'
91
+ end
92
+
93
+ def git_uncached
94
+ ::EacGit::Local.new(git_path)
95
+ end
96
+
97
+ def bundle_run(*args)
98
+ instance.ruby_gem.bundle(*args).system!
99
+ end
100
+
101
+ def git_path
102
+ '.'
103
+ end
104
+
105
+ def conflict?
106
+ rebase_conflict? || cherry_conflict?
107
+ end
108
+
109
+ def rebase_conflict?
110
+ instance.git_repo.root_path.join('.git', 'REBASE_HEAD').exist?
111
+ end
112
+
113
+ def cherry_conflict?
114
+ instance.git_repo.root_path.join('.git', 'CHERRY_PICK_HEAD').exist?
115
+ end
116
+
117
+ def option_or_all?(option)
118
+ options.fetch(option) || options.fetch('--all')
119
+ end
120
+
121
+ def instance
122
+ context(:instance)
123
+ end
124
+
125
+ def check_capability(caller, capability, option)
126
+ return false unless option.blank? || option_or_all?(option)
127
+ return true if instance.respond_to?(capability)
128
+
129
+ warn "Cannot run #{caller}: instance has no capability \"#{capability}\""
130
+ false
131
+ end
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/console/docopt_runner'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Tools
8
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
9
+ class LocalProject < ::EacRubyUtils::Console::DocoptRunner
10
+ class Test < ::EacRubyUtils::Console::DocoptRunner
11
+ include ::EacCli::DefaultRunner
12
+
13
+ runner_definition do
14
+ desc 'Test local project.'
15
+ end
16
+
17
+ def run
18
+ context(:instance_banner)
19
+ infov 'Test command', test_command
20
+ if test_command.present?
21
+ test_command.system!
22
+ else
23
+ fatal_error 'No test command found'
24
+ end
25
+ end
26
+
27
+ def test_command
28
+ context(:instance).configuration.if_present(&:any_test_command)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'avm/local_projects/jobs/update'
4
3
  require 'eac_ruby_utils/console/docopt_runner'
5
4
  require 'eac_ruby_utils/core_ext'
6
5
 
@@ -17,7 +16,7 @@ module Avm
17
16
 
18
17
  def run
19
18
  infov 'Path', context(:instance).path
20
- ::Avm::LocalProjects::Jobs::Update.new(context(:instance)).run
19
+ context(:instance).run_job(:update)
21
20
  end
22
21
  end
23
22
  end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/version'
4
+ require 'eac_ruby_utils/console/docopt_runner'
5
+ require 'eac_ruby_utils/core_ext'
6
+
7
+ module Avm
8
+ module Tools
9
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
10
+ class LocalProject < ::EacRubyUtils::Console::DocoptRunner
11
+ class VersionBump < ::EacRubyUtils::Console::DocoptRunner
12
+ include ::EacCli::DefaultRunner
13
+
14
+ runner_definition do
15
+ desc 'Bump version of a local project.'
16
+ arg_opt '-n', '--new', 'Set new version.'
17
+ arg_opt '-s', '--segment', 'Increment de <segment>-th segment (Left-most is 0)'
18
+ bool_opt '-M', '--major', 'Same as --segment=0.'
19
+ bool_opt '-m', '--minor', 'Same as --segment=1.'
20
+ bool_opt '-p', '--patch', 'Same as --segment=2.'
21
+ bool_opt '-y', '--yes', 'Bump without confirmation.'
22
+ end
23
+
24
+ def run
25
+ start_banner
26
+ version_changed? ? run_version_changed : run_version_unchanged
27
+ end
28
+
29
+ def run_version_changed
30
+ infom 'Version changed'
31
+ if confirm?
32
+ context(:instance).run_job(:version_bump, target_version)
33
+ success 'Bumped'
34
+ else
35
+ fatal_error 'Bump unconfirmed'
36
+ end
37
+ end
38
+
39
+ def run_version_unchanged
40
+ success 'Version unchanged'
41
+ end
42
+
43
+ def start_banner
44
+ context(:instance_banner)
45
+ infov 'Current version', current_version.if_present('-')
46
+ infov 'Target version', target_version.if_present('-')
47
+ end
48
+
49
+ def confirm?
50
+ options.fetch('--yes') || request_input('Confirm version bump?', bool: true)
51
+ end
52
+
53
+ def current_version_uncached
54
+ context(:instance).if_respond('version')
55
+ end
56
+
57
+ def target_version_uncached
58
+ r = current_version
59
+ %w[new segment major minor patch].each do |option|
60
+ option_value = options.fetch("--#{option}")
61
+ next if option_value.blank?
62
+
63
+ r = send("target_version_from_#{option}", r, option_value)
64
+ end
65
+ r
66
+ end
67
+
68
+ def target_version_from_new(_current, option_value)
69
+ ::Avm::Version.new(option_value)
70
+ end
71
+
72
+ def target_version_from_segment(current, option_value)
73
+ current.increment_segment(option_value.to_i)
74
+ end
75
+
76
+ %w[major minor patch].each_with_index do |segment, segment_index|
77
+ define_method "target_version_from_#{segment}" do |current, _option_value|
78
+ target_version_from_segment(current, segment_index)
79
+ end
80
+ end
81
+
82
+ def version_changed?
83
+ target_version != current_version
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module Tools
5
- VERSION = '0.64.1'
5
+ VERSION = '0.68.0'
6
6
  end
7
7
  end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ # A sequence of segments of integer versions (Ex.: 2, 1.0.1, 3.0.0.0.0).
5
+ class Version
6
+ include ::Comparable
7
+
8
+ SEGMENT_SEPARATOR = '.'
9
+
10
+ class << self
11
+ def segments_from_mixed(segments)
12
+ (segments.is_a?(::Enumerable) ? segments.to_a : segments.to_s.split(SEGMENT_SEPARATOR))
13
+ .map(&:to_i)
14
+ end
15
+ end
16
+
17
+ attr_reader :segments
18
+
19
+ def initialize(segments)
20
+ @segments = self.class.segments_from_mixed(segments).freeze
21
+ end
22
+
23
+ delegate :[], to: :segments
24
+
25
+ def <=>(other)
26
+ segments <=> other.segments
27
+ end
28
+
29
+ def to_s
30
+ segments.join(SEGMENT_SEPARATOR)
31
+ end
32
+
33
+ # @return [Avm::Version]
34
+ def increment_segment(segment_index)
35
+ x = [segments.count, segment_index + 1].max.times.map do |index|
36
+ value = index < segments.count ? segments[index] : 0
37
+ next value if index < segment_index
38
+ next value + 1 if index == segment_index
39
+
40
+ 0
41
+ end
42
+ self.class.new x
43
+ end
44
+ end
45
+ end
@@ -12,7 +12,7 @@ module EacLauncher
12
12
  r = find_parent_instance(instance.parent)
13
13
  return r if r
14
14
 
15
- ::EacLauncher::Instances::Errors::Base.new('Git parent not found')
15
+ ::Avm::Launcher::Errors::Base.new('Git parent not found')
16
16
  end
17
17
 
18
18
  def find_parent_instance(current)
@@ -35,7 +35,7 @@ module EacLauncher
35
35
 
36
36
  def check_with_rescue
37
37
  internal_check
38
- rescue ::EacLauncher::Instances::Errors::Base => e
38
+ rescue ::Avm::Launcher::Errors::Base => e
39
39
  ::EacLauncher::Publish::CheckResult.blocked("Error: #{e}")
40
40
  rescue ::EacLauncher::Git::Error => e
41
41
  ::EacLauncher::Publish::CheckResult.blocked("Git error: #{e}")
@@ -54,7 +54,7 @@ module EacRubyGemsUtils
54
54
  end
55
55
 
56
56
  def version
57
- /VERSION\s*=\s*[\'\"]([^\'\"]+)[\'\"]/.if_match(version_file.read) { |m| m[1] }
57
+ version_file.value
58
58
  end
59
59
 
60
60
  private
@@ -76,6 +76,10 @@ module EacRubyGemsUtils
76
76
  end
77
77
 
78
78
  def version_file_uncached
79
+ ::EacRubyGemsUtils::Gem::VersionFile.new(version_file_path)
80
+ end
81
+
82
+ def version_file_path_uncached
79
83
  root.join('lib', *namespace_parts, 'version.rb')
80
84
  end
81
85
  end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacRubyGemsUtils
6
+ class Gem
7
+ class VersionFile
8
+ common_constructor :path
9
+
10
+ VERSION_LINE_PATTERN = /\A(\s*)VERSION\s*=\s*[\'\"]([^\'\"]+)[\'\"](\s*)\z/.freeze
11
+
12
+ def value
13
+ path.read.each_line do |line|
14
+ VERSION_LINE_PATTERN.if_match(line.rstrip, false) do |m|
15
+ ::Gem::Version.new(m[2])
16
+ end
17
+ end
18
+ end
19
+
20
+ def value=(new_value)
21
+ path.write(new_value_content(new_value))
22
+ end
23
+
24
+ private
25
+
26
+ def new_value_content(new_value)
27
+ path.read.each_line
28
+ .map { |line| new_value_line(line, new_value) }
29
+ .join
30
+ end
31
+
32
+ def new_value_line(line, new_value)
33
+ m = VERSION_LINE_PATTERN.match(line)
34
+ return line unless m
35
+
36
+ "#{m[1]}VERSION = '#{new_value}'#{m[3]}"
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyGemsUtils
4
- VERSION = '0.6.2'
4
+ VERSION = '0.7.0'
5
5
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/object/blank'
4
+
5
+ class Object
6
+ # @return +block.call(self.method_name)+ if +self+ responds to +method_name+, +default_value+
7
+ # otherwise.
8
+ def if_respond(method_name, default_value = nil)
9
+ return default_value unless respond_to?(method_name)
10
+
11
+ value = send(method_name)
12
+
13
+ block_given? ? yield(value) : value
14
+ end
15
+
16
+ # @return +yield+ if +self+ is blank.
17
+ def if_blank
18
+ return yield if blank? && block_given?
19
+
20
+ self
21
+ end
22
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.43.0'
4
+ VERSION = '0.44.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avm-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.64.1
4
+ version: 0.68.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esquilo Azul Company
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-25 00:00:00.000000000 Z
11
+ date: 2020-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aranha-parsers
@@ -361,6 +361,7 @@ files:
361
361
  - lib/avm/instances/base/auto_values/web.rb
362
362
  - lib/avm/instances/base/dockerizable.rb
363
363
  - lib/avm/instances/configuration.rb
364
+ - lib/avm/instances/configuration/_locale.rb
364
365
  - lib/avm/instances/configuration/_rubocop.rb
365
366
  - lib/avm/instances/configuration/_tests.rb
366
367
  - lib/avm/instances/entries.rb
@@ -376,9 +377,10 @@ files:
376
377
  - lib/avm/launcher/instances/settings.rb
377
378
  - lib/avm/local_projects.rb
378
379
  - lib/avm/local_projects/instance.rb
379
- - lib/avm/local_projects/jobs/update.rb
380
380
  - lib/avm/patches.rb
381
381
  - lib/avm/patches/eac_ruby_gems_utils/gem.rb
382
+ - lib/avm/patches/i18n.rb
383
+ - lib/avm/patches/object/i18n.rb
382
384
  - lib/avm/patches/object/template.rb
383
385
  - lib/avm/path_string.rb
384
386
  - lib/avm/projects.rb
@@ -395,11 +397,14 @@ files:
395
397
  - lib/avm/projects/stereotypes/git_subtree/publish.rb
396
398
  - lib/avm/projects/stereotypes/git_subtree/warp.rb
397
399
  - lib/avm/projects/stereotypes/rails_application.rb
400
+ - lib/avm/projects/stereotypes/rails_application/local_project_mixin.rb
401
+ - lib/avm/projects/stereotypes/rails_application/update.rb
398
402
  - lib/avm/projects/stereotypes/redmine_plugin.rb
399
403
  - lib/avm/projects/stereotypes/ruby_gem.rb
400
404
  - lib/avm/projects/stereotypes/ruby_gem/local_project_mixin.rb
401
405
  - lib/avm/projects/stereotypes/ruby_gem/publish.rb
402
406
  - lib/avm/projects/stereotypes/ruby_gem/update.rb
407
+ - lib/avm/projects/stereotypes/ruby_gem/version_bump.rb
403
408
  - lib/avm/rails.rb
404
409
  - lib/avm/rails/runners.rb
405
410
  - lib/avm/rails/runners/bundle.rb
@@ -489,7 +494,12 @@ files:
489
494
  - lib/avm/tools/runner/launcher/publish.rb
490
495
  - lib/avm/tools/runner/local_project.rb
491
496
  - lib/avm/tools/runner/local_project/info.rb
497
+ - lib/avm/tools/runner/local_project/ruby.rb
498
+ - lib/avm/tools/runner/local_project/ruby/bundler.rb
499
+ - lib/avm/tools/runner/local_project/ruby/bundler/gemfile_lock.rb
500
+ - lib/avm/tools/runner/local_project/test.rb
492
501
  - lib/avm/tools/runner/local_project/update.rb
502
+ - lib/avm/tools/runner/local_project/version_bump.rb
493
503
  - lib/avm/tools/runner/ruby.rb
494
504
  - lib/avm/tools/runner/ruby/gems.rb
495
505
  - lib/avm/tools/runner/ruby/gems/generate.rb
@@ -497,6 +507,7 @@ files:
497
507
  - lib/avm/tools/runner/self.rb
498
508
  - lib/avm/tools/runner/self/docker.rb
499
509
  - lib/avm/tools/version.rb
510
+ - lib/avm/version.rb
500
511
  - lib/eac_launcher.rb
501
512
  - lib/eac_launcher/context.rb
502
513
  - lib/eac_launcher/context/instance_discovery.rb
@@ -781,6 +792,7 @@ files:
781
792
  - vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils.rb
782
793
  - vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/gem.rb
783
794
  - vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/gem/command.rb
795
+ - vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/gem/version_file.rb
784
796
  - vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests.rb
785
797
  - vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/base.rb
786
798
  - vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/minitest.rb
@@ -886,6 +898,7 @@ files:
886
898
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object.rb
887
899
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/asserts.rb
888
900
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_present.rb
901
+ - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_respond.rb
889
902
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/template.rb
890
903
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/to_pathname.rb
891
904
  - vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/pathname.rb
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/core_ext'
4
-
5
- module Avm
6
- module LocalProjects
7
- module Jobs
8
- class Update
9
- enable_console_speaker
10
- common_constructor :instance
11
-
12
- def run
13
- instance.stereotypes.each { |stereotype| run_stereotype(stereotype) }
14
- end
15
-
16
- private
17
-
18
- def run_stereotype(stereotype)
19
- if stereotype.update_class.present?
20
- puts stereotype.label + ': update class found. Running...'
21
- stereotype.update_class.new(instance).run
22
- else
23
- puts stereotype.label + ': update class not found'
24
- end
25
- end
26
- end
27
- end
28
- end
29
- end