avm-tools 0.140.0 → 0.142.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/lib/avm/projects/stereotypes.rb +4 -0
  3. data/lib/avm/tools/runner/files/format.rb +2 -2
  4. data/lib/avm/tools/runner/git/commit.rb +2 -2
  5. data/lib/avm/tools/runner/git/deploy.rb +2 -2
  6. data/lib/avm/tools/runner/git.rb +2 -2
  7. data/lib/avm/tools/runner/launcher_stereotypes/list.rb +42 -0
  8. data/lib/avm/tools/runner/launcher_stereotypes.rb +16 -0
  9. data/lib/avm/tools/version.rb +1 -1
  10. metadata +10 -39
  11. data/lib/avm/launcher/git/base/class_methods.rb +0 -28
  12. data/lib/avm/launcher/git/base/dirty_files.rb +0 -23
  13. data/lib/avm/launcher/git/base/remotes.rb +0 -40
  14. data/lib/avm/launcher/git/base/subrepo.rb +0 -44
  15. data/lib/avm/launcher/git/base/underlying.rb +0 -63
  16. data/lib/avm/launcher/git/base.rb +0 -86
  17. data/lib/avm/launcher/git/error.rb +0 -13
  18. data/lib/avm/launcher/git/mirror_update.rb +0 -38
  19. data/lib/avm/launcher/git/publish_base.rb +0 -125
  20. data/lib/avm/launcher/git/remote.rb +0 -55
  21. data/lib/avm/launcher/git/sub_warp_base.rb +0 -33
  22. data/lib/avm/launcher/git/warp_base.rb +0 -67
  23. data/lib/avm/launcher/git.rb +0 -7
  24. data/lib/avm/launcher/ruby/gem/build.rb +0 -125
  25. data/lib/avm/launcher/ruby/gem/specification.rb +0 -63
  26. data/lib/avm/launcher/ruby/gem.rb +0 -4
  27. data/lib/avm/launcher/ruby.rb +0 -3
  28. data/lib/avm/projects/stereotype.rb +0 -63
  29. data/lib/avm/projects/stereotypes/git/local_project_mixin.rb +0 -19
  30. data/lib/avm/projects/stereotypes/git/publish.rb +0 -15
  31. data/lib/avm/projects/stereotypes/git/warp.rb +0 -27
  32. data/lib/avm/projects/stereotypes/git.rb +0 -25
  33. data/lib/avm/projects/stereotypes/git_subrepo/publish.rb +0 -14
  34. data/lib/avm/projects/stereotypes/git_subrepo/warp.rb +0 -88
  35. data/lib/avm/projects/stereotypes/git_subrepo.rb +0 -34
  36. data/lib/avm/projects/stereotypes/git_subtree/publish.rb +0 -14
  37. data/lib/avm/projects/stereotypes/git_subtree/warp.rb +0 -32
  38. data/lib/avm/projects/stereotypes/git_subtree.rb +0 -51
  39. data/lib/avm/projects/stereotypes/ruby_gem/local_project_mixin.rb +0 -28
  40. data/lib/avm/projects/stereotypes/ruby_gem/publish.rb +0 -129
  41. data/lib/avm/projects/stereotypes/ruby_gem.rb +0 -30
@@ -1,125 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/simple_cache'
4
- require 'eac_ruby_utils/simple_cache'
5
- require 'avm/launcher/publish/base'
6
- require 'avm/launcher/publish/check_result'
7
-
8
- module Avm
9
- module Launcher
10
- module Git
11
- class PublishBase < ::Avm::Launcher::Publish::Base
12
- include ::EacRubyUtils::SimpleCache
13
- enable_speaker
14
-
15
- CHECKERS = %w[remote_url remote_fetch publish_remote_no_exist remote_equal remote_following
16
- local_following].freeze
17
-
18
- REMOTE_UNAVAILABLE_MESSAGES = ['could not resolve host', 'connection timed out',
19
- 'no route to host'].map(&:downcase).freeze
20
-
21
- protected
22
-
23
- def internal_check
24
- CHECKERS.each do |checker|
25
- result = send("#{checker}_check_result")
26
- return result if result
27
- end
28
- divergent_result_check_result
29
- rescue ::Avm::Launcher::Instances::Error => e
30
- ::Avm::Launcher::Publish::CheckResult.blocked(e.message)
31
- rescue ::StandardError => e
32
- raise e unless remote_unavailable_error?(e)
33
-
34
- ::Avm::Launcher::Publish::CheckResult.blocked(e.message)
35
- end
36
-
37
- private
38
-
39
- def remote_url_check_result
40
- remote = sgit.remote(remote_name)
41
- return if remote.exist? && remote.url.present?
42
-
43
- ::Avm::Launcher::Publish::CheckResult.blocked("Remote \"#{remote_name}\" has blank path")
44
- end
45
-
46
- def remote_fetch_check_result
47
- remote_fetch
48
- nil
49
- end
50
-
51
- def remote_unavailable_error?(error)
52
- error_message = error.message.downcase
53
- REMOTE_UNAVAILABLE_MESSAGES.any? do |message|
54
- error_message.include?(message)
55
- end
56
- end
57
-
58
- def publish_remote_no_exist_check_result
59
- return nil if sgit.remote_exist?(remote_name)
60
-
61
- ::Avm::Launcher::Publish::CheckResult.blocked('Remote does not exist')
62
- end
63
-
64
- def remote_equal_check_result
65
- return nil unless remote_sha.present? && remote_sha == local_sha
66
-
67
- ::Avm::Launcher::Publish::CheckResult.updated('Remote equal')
68
- end
69
-
70
- def remote_following_check_result
71
- return nil unless remote_sha.present? && sgit.descendant?(remote_sha, local_sha)
72
-
73
- ::Avm::Launcher::Publish::CheckResult.outdated('Remote following')
74
- end
75
-
76
- def divergent_result_check_result
77
- ::Avm::Launcher::Publish::CheckResult.blocked(
78
- "Divergent (L: #{local_sha}, R: #{remote_sha})"
79
- )
80
- end
81
-
82
- def local_following?
83
- return true if remote_sha.blank?
84
-
85
- sgit.descendant?(local_sha, remote_sha)
86
- end
87
-
88
- def local_following_check_result
89
- return nil unless local_following?
90
-
91
- ::Avm::Launcher::Publish::CheckResult.pending('Local following')
92
- end
93
-
94
- def sgit_uncached
95
- ::Avm::Launcher::Git::Base.new(instance.warped)
96
- end
97
-
98
- def publish
99
- info 'Pushing...'
100
- sgit.push(remote_name, 'HEAD:master',
101
- dryrun: !::Avm::Launcher::Context.current.publish_options[:confirm])
102
- info 'Pushed!'
103
- end
104
-
105
- def local_sha
106
- sgit.git.object('HEAD').sha
107
- end
108
-
109
- def remote_sha_uncached
110
- remote_fetch
111
- b = sgit.git.branches["#{remote_name}/master"]
112
- b ? b.gcommit.sha : nil
113
- end
114
-
115
- def remote_fetch_uncached
116
- sgit.fetch(remote_name)
117
- end
118
-
119
- def remote_name
120
- ::Avm::Launcher::Git::WarpBase::TARGET_REMOTE
121
- end
122
- end
123
- end
124
- end
125
- end
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/core_ext'
4
-
5
- module Avm
6
- module Launcher
7
- module Git
8
- class Remote
9
- common_constructor :git, :name
10
-
11
- def exist?
12
- git.execute!('remote').each_line.any? { |line| line.strip == name }
13
- end
14
-
15
- def ls
16
- git.execute!(['ls-remote', name]).each_line.map do |line|
17
- x = line.strip.split(/\s+/)
18
- [x[1], x[0]]
19
- end.to_h
20
- end
21
-
22
- # +git remote add ...+
23
- def add(url)
24
- git.execute!('remote', 'add', name, url)
25
- end
26
-
27
- # +git remote rm ...+
28
- def remove
29
- git.execute!('remote', 'rm', name)
30
- end
31
-
32
- # +git remote get-url ...+
33
- def url
34
- git.execute!('remote', 'get-url', name).strip.if_present(nil)
35
- end
36
-
37
- # git remote set-url ...
38
- def url_set(url)
39
- git.execute!('remote', 'set-url', name, url)
40
- end
41
-
42
- # Add or set URL if +url+ is present, remove remote if is blank.
43
- def url=(url)
44
- if exist? && url.blank?
45
- remove
46
- elsif exist? && self.url != url
47
- url_set(url)
48
- elsif !exist?
49
- add(url)
50
- end
51
- end
52
- end
53
- end
54
- end
55
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'avm/projects/stereotype'
4
- require 'avm/launcher/errors/base'
5
-
6
- module Avm
7
- module Launcher
8
- module Git
9
- module SubWarpBase
10
- private
11
-
12
- def parent_instance_uncached
13
- r = find_parent_instance(instance.parent)
14
- return r if r
15
-
16
- ::Avm::Launcher::Errors::Base.new('Git parent not found')
17
- end
18
-
19
- def find_parent_instance(current)
20
- if ::Avm::Projects::Stereotype.git_stereotypes.any? { |s| current.stereotype?(s) }
21
- return current
22
- end
23
-
24
- current.parent ? find_parent_instance(current.parent) : nil
25
- end
26
-
27
- def to_parent_git_path
28
- instance.logical.gsub(%r{\A#{Regexp.quote(parent_instance.logical)}/}, '')
29
- end
30
- end
31
- end
32
- end
33
- end
@@ -1,67 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'avm/launcher/git/mirror_update'
4
- require 'avm/launcher/instances/error'
5
- require 'avm/git/vendor/github'
6
- require 'avm/projects/stereotypes/git/publish'
7
-
8
- module Avm
9
- module Launcher
10
- module Git
11
- # Métodos abstratos:
12
- # * source_instance
13
- # * source_remote_name
14
- # * current_ref
15
- class WarpBase < ::Avm::Launcher::Paths::Real
16
- include ::EacRubyUtils::SimpleCache
17
-
18
- TARGET_REMOTE = ::Avm::Projects::Stereotypes::Git::Publish::PUBLISH_GIT_REMOTE_NAME
19
-
20
- def initialize(instance)
21
- @instance = instance
22
- cache_git.git.reset_hard(current_ref)
23
- cache_git.remote(TARGET_REMOTE).url = target_remote_url
24
- super(path)
25
- end
26
-
27
- protected
28
-
29
- attr_reader :instance
30
-
31
- def validate_source_current_revision
32
- if source_git.rev_parse(source_instance.options.git_current_revision, false).present?
33
- return
34
- end
35
-
36
- raise ::Avm::Launcher::Instances::Error, 'Refspec ' \
37
- "\"#{source_instance.options.git_current_revision}\" not found in \"#{source_git}\""
38
- end
39
-
40
- def update
41
- validate_source_current_revision
42
- ::Avm::Launcher::Git::MirrorUpdate.new(
43
- path,
44
- source_instance.real,
45
- source_instance.options.git_current_revision
46
- )
47
- end
48
-
49
- def path
50
- instance.cache_path('git_repository')
51
- end
52
-
53
- def source_git_uncached
54
- ::Avm::Launcher::Git::Base.new(source_instance.real)
55
- end
56
-
57
- def cache_git_uncached
58
- ::Avm::Launcher::Git::Base.new(update)
59
- end
60
-
61
- def target_remote_url
62
- ::Avm::Git::Vendor::Github.to_ssh_url(source_git.git.remote(source_remote_name).url)
63
- end
64
- end
65
- end
66
- end
67
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'avm/launcher/git/base'
4
- require 'avm/launcher/git/error'
5
- require 'avm/launcher/git/mirror_update'
6
- require 'avm/launcher/git/publish_base'
7
- require 'avm/launcher/git/warp_base'
@@ -1,125 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'tmpdir'
4
- require 'eac_cli/speaker'
5
- require 'eac_ruby_utils/envs'
6
- require 'avm/launcher/ruby/gem/specification'
7
-
8
- module Avm
9
- module Launcher
10
- module Ruby
11
- module Gem
12
- class Build
13
- enable_speaker
14
-
15
- def initialize(original_gem_root)
16
- @original_gem_root = original_gem_root
17
- end
18
-
19
- def output_file
20
- return nil unless @gem_root
21
-
22
- @gem_root.find_files_with_extension('.gem').first
23
- end
24
-
25
- def builded?
26
- output_file.present? && ::File.exist?(output_file)
27
- end
28
-
29
- def build
30
- return if builded?
31
-
32
- copy_gem_files
33
- build_gem
34
- check_gem_empty_size
35
- check_gem_version
36
- end
37
-
38
- def close
39
- ::FileUtils.remove_entry(@gem_root) if @gem_root && ::File.directory?(@gem_root)
40
- @gem_root = nil
41
- end
42
-
43
- private
44
-
45
- def copy_gem_files
46
- @gem_root = ::Avm::Launcher::Paths::Real.new(::Dir.mktmpdir)
47
- FileUtils.cp_r "#{@original_gem_root}/.", @gem_root
48
- end
49
-
50
- def build_gem
51
- info("Building gemspec #{gemspec_file}...")
52
- clear_gems
53
- Dir.chdir @gem_root do
54
- isolated_build_gem
55
- end
56
- end
57
-
58
- def isolated_build_gem
59
- on_clean_ruby do
60
- EacRubyUtils::Envs.local.command('gem', 'build', gemspec_file).execute!
61
- end
62
- end
63
-
64
- def check_gem_empty_size
65
- Dir.mktmpdir do |dir|
66
- Dir.chdir dir do
67
- EacRubyUtils::Envs.local.command('gem', 'unpack', gem).system
68
- gs = File.join(dir, File.basename(gem, '.gem'))
69
- if (Dir.entries(gs) - %w[. ..]).empty?
70
- raise "\"#{dir}\" (Unpacked from #{gem}) has no source code"
71
- end
72
- end
73
- end
74
- end
75
-
76
- def clear_gems
77
- @gem_root.find_files_with_extension('.gem').each do |f|
78
- FileUtils.rm_rf(f)
79
- end
80
- end
81
-
82
- def gemspec_file
83
- @gem_root.find_file_with_extension('.gemspec')
84
- end
85
-
86
- def gem
87
- @gem_root.find_file_with_extension('.gem')
88
- end
89
-
90
- def check_gem_version
91
- spec = ::Avm::Launcher::Ruby::Gem::Specification.new(gemspec_file)
92
- return if ::File.basename(output_file, '.gem') == spec.full_name
93
-
94
- raise("Builded gem is not the same version of gemspec (#{spec}, #{output_file})")
95
- end
96
-
97
- def bundle_dependencies
98
- gemfile = @gem_root.subpath('Gemfile')
99
- return unless ::File.exist?(gemfile)
100
-
101
- Dir.chdir(@gem_root) do
102
- EacRubyUtils::Envs.local.command('bundle', 'install').execute!
103
- end
104
- end
105
-
106
- def on_clean_ruby
107
- on_clear_envvars('BUNDLE', 'RUBY') { yield }
108
- end
109
-
110
- def on_clear_envvars(*start_with_vars)
111
- old_values = envvars_starting_with(start_with_vars)
112
- old_values.each_key { |k| ENV.delete(k) }
113
- yield
114
- ensure
115
- old_values&.each { |k, v| ENV[k] = v }
116
- end
117
-
118
- def envvars_starting_with(start_with_vars)
119
- ENV.select { |k, _v| start_with_vars.any? { |var| k.start_with?(var) } }
120
- end
121
- end
122
- end
123
- end
124
- end
125
- end
@@ -1,63 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'active_support/core_ext/object'
4
-
5
- module Avm
6
- module Launcher
7
- module Ruby
8
- module Gem
9
- class Specification
10
- class << self
11
- def parse_version_file(file)
12
- s = ::File.read(file)
13
- m = /VERSION\s*=\s*[\'\"]([^\'\"]+)[\'\"]/.match(s)
14
- m ? m[1] : nil
15
- end
16
- end
17
-
18
- attr_reader :gemspec_file
19
-
20
- def initialize(gemspec_file)
21
- @gemspec_file = gemspec_file
22
- end
23
-
24
- def version
25
- v = self.class.parse_version_file(version_file)
26
- return v if v.present?
27
-
28
- raise "Version not found on file \"#{version_file}\""
29
- end
30
-
31
- def name
32
- ::File.basename(gemspec_file).gsub(/\.gemspec\z/, '')
33
- end
34
-
35
- def full_name
36
- "#{name}-#{version}"
37
- end
38
-
39
- def to_s
40
- full_name
41
- end
42
-
43
- private
44
-
45
- def gem_root
46
- ::File.dirname(gemspec_file)
47
- end
48
-
49
- def version_file
50
- f = ::File.join(gem_root, 'lib', *namespace_parts, 'version.rb')
51
- return f if ::File.exist?(f)
52
-
53
- raise "Version file \"#{f}\" does not exist"
54
- end
55
-
56
- def namespace_parts
57
- name.split('-')
58
- end
59
- end
60
- end
61
- end
62
- end
63
- end
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'avm/launcher/ruby/gem/build'
4
- require 'avm/launcher/ruby/gem/specification'
@@ -1,3 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'avm/launcher/ruby/gem'
@@ -1,63 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'active_support/core_ext/string/inflections'
4
- require 'colorized_string'
5
-
6
- module Avm
7
- module Projects
8
- module Stereotype
9
- class << self
10
- attr_reader :stereotypes
11
-
12
- def included(base)
13
- @stereotypes ||= []
14
- @stereotypes << base
15
- base.extend(ClassMethods)
16
- end
17
-
18
- def git_stereotypes
19
- stereotypes.select { |c| c.name.demodulize.downcase.match('git') }
20
- end
21
-
22
- def nogit_stereotypes
23
- stereotypes - git_stereotypes
24
- end
25
- end
26
-
27
- module ClassMethods
28
- def label
29
- ::ColorizedString.new(stereotype_name).send(color)
30
- end
31
-
32
- def stereotype_name
33
- name.demodulize
34
- end
35
-
36
- {
37
- local_project_mixin: ::Module,
38
- publish: ::Class,
39
- update: ::Class,
40
- version_bump: ::Class,
41
- warp: ::Class
42
- }.each do |name, is_a|
43
- define_method "#{name}_#{is_a.name.underscore}" do
44
- sub_constant(name.to_s.camelcase, is_a)
45
- end
46
- end
47
-
48
- private
49
-
50
- def sub_constant(constant_name, is_a)
51
- return nil unless const_defined?(constant_name)
52
-
53
- constant = const_get(constant_name)
54
- unless is_a.if_present(true) { |v| constant.is_a?(v) }
55
- raise("#{constant} is not a #{is_a}")
56
- end
57
-
58
- constant
59
- end
60
- end
61
- end
62
- end
63
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_git/local'
4
- require 'eac_ruby_utils/core_ext'
5
-
6
- module Avm
7
- module Projects
8
- module Stereotypes
9
- class Git
10
- module LocalProjectMixin
11
- # @return [EacGit::Local]
12
- def git_repo
13
- @git_repo ||= ::EacGit::Local.new(path)
14
- end
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'avm/launcher/git/publish_base'
4
-
5
- module Avm
6
- module Projects
7
- module Stereotypes
8
- class Git
9
- class Publish < ::Avm::Launcher::Git::PublishBase
10
- PUBLISH_GIT_REMOTE_NAME = 'publish'
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'avm/launcher/git/warp_base'
4
-
5
- module Avm
6
- module Projects
7
- module Stereotypes
8
- class Git
9
- class Warp < ::Avm::Launcher::Git::WarpBase
10
- private
11
-
12
- def current_ref
13
- 'HEAD'
14
- end
15
-
16
- def source_instance
17
- instance
18
- end
19
-
20
- def source_remote_name
21
- ::Avm::Projects::Stereotypes::Git::Publish::PUBLISH_GIT_REMOTE_NAME
22
- end
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'avm/projects/stereotype'
4
- require 'eac_ruby_utils/core_ext'
5
-
6
- module Avm
7
- module Projects
8
- module Stereotypes
9
- class Git
10
- require_sub __FILE__
11
- include Avm::Projects::Stereotype
12
-
13
- class << self
14
- def match?(path)
15
- File.directory?(path.real.subpath('.git'))
16
- end
17
-
18
- def color
19
- :white
20
- end
21
- end
22
- end
23
- end
24
- end
25
- end
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'avm/launcher/git/publish_base'
4
-
5
- module Avm
6
- module Projects
7
- module Stereotypes
8
- class GitSubrepo
9
- class Publish < ::Avm::Launcher::Git::PublishBase
10
- end
11
- end
12
- end
13
- end
14
- end