avm-tools 0.140.0 → 0.141.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/lib/avm/projects/stereotypes/git/publish.rb +2 -2
  3. data/lib/avm/projects/stereotypes/git/warp.rb +2 -2
  4. data/lib/avm/projects/stereotypes/git.rb +2 -2
  5. data/lib/avm/projects/stereotypes/git_subrepo/publish.rb +2 -2
  6. data/lib/avm/projects/stereotypes/git_subrepo/warp.rb +7 -7
  7. data/lib/avm/projects/stereotypes/git_subrepo.rb +4 -4
  8. data/lib/avm/projects/stereotypes/git_subtree/publish.rb +2 -2
  9. data/lib/avm/projects/stereotypes/git_subtree/warp.rb +4 -4
  10. data/lib/avm/projects/stereotypes/git_subtree.rb +3 -3
  11. data/lib/avm/projects/stereotypes/ruby_gem/publish.rb +2 -2
  12. data/lib/avm/projects/stereotypes/ruby_gem.rb +4 -4
  13. data/lib/avm/tools/runner/files/format.rb +2 -2
  14. data/lib/avm/tools/runner/git/commit.rb +2 -2
  15. data/lib/avm/tools/runner/git/deploy.rb +2 -2
  16. data/lib/avm/tools/runner/git.rb +2 -2
  17. data/lib/avm/tools/version.rb +1 -1
  18. metadata +7 -25
  19. data/lib/avm/launcher/git/base/class_methods.rb +0 -28
  20. data/lib/avm/launcher/git/base/dirty_files.rb +0 -23
  21. data/lib/avm/launcher/git/base/remotes.rb +0 -40
  22. data/lib/avm/launcher/git/base/subrepo.rb +0 -44
  23. data/lib/avm/launcher/git/base/underlying.rb +0 -63
  24. data/lib/avm/launcher/git/base.rb +0 -86
  25. data/lib/avm/launcher/git/error.rb +0 -13
  26. data/lib/avm/launcher/git/mirror_update.rb +0 -38
  27. data/lib/avm/launcher/git/publish_base.rb +0 -125
  28. data/lib/avm/launcher/git/remote.rb +0 -55
  29. data/lib/avm/launcher/git/sub_warp_base.rb +0 -33
  30. data/lib/avm/launcher/git/warp_base.rb +0 -67
  31. data/lib/avm/launcher/git.rb +0 -7
  32. data/lib/avm/launcher/ruby/gem/build.rb +0 -125
  33. data/lib/avm/launcher/ruby/gem/specification.rb +0 -63
  34. data/lib/avm/launcher/ruby/gem.rb +0 -4
  35. data/lib/avm/launcher/ruby.rb +0 -3
  36. data/lib/avm/projects/stereotype.rb +0 -63
@@ -1,86 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_git/local'
4
- require 'eac_ruby_utils/core_ext'
5
- require 'eac_ruby_utils/envs'
6
- require 'avm/launcher/paths/real'
7
- require 'avm/launcher/git/error'
8
-
9
- module Avm
10
- module Launcher
11
- module Git
12
- class Base < ::Avm::Launcher::Paths::Real
13
- require_sub __FILE__
14
- enable_simple_cache
15
- extend ::Avm::Launcher::Git::Base::ClassMethods
16
- include ::Avm::Launcher::Git::Base::DirtyFiles
17
- include ::Avm::Launcher::Git::Base::Remotes
18
- include ::Avm::Launcher::Git::Base::Subrepo
19
- include ::Avm::Launcher::Git::Base::Underlying
20
-
21
- attr_reader :eac_git
22
- delegate :descendant?, :merge_base, :rev_parse, to: :eac_git
23
-
24
- def initialize(path)
25
- super(path)
26
-
27
- @eac_git = ::EacGit::Local.new(path)
28
- end
29
-
30
- def init_bare
31
- FileUtils.mkdir_p(self)
32
- ::EacRubyUtils::Envs.local.command('git', 'init', '--bare', self).execute! unless
33
- File.exist?(subpath('.git'))
34
- end
35
-
36
- # @return [Pathname]
37
- def root_path
38
- @root_path ||= self.class.find_root(to_s)
39
- end
40
-
41
- def descendant?(descendant, ancestor)
42
- base = merge_base(descendant, ancestor)
43
- return false if base.blank?
44
-
45
- revparse = execute!('rev-parse', '--verify', ancestor).strip
46
- base == revparse
47
- end
48
-
49
- def subtree_split(prefix)
50
- execute!('subtree', '-q', 'split', '-P', prefix).strip
51
- end
52
-
53
- def push(remote_name, refspecs, options = {})
54
- refspecs = [refspecs] unless refspecs.is_a?(Array)
55
- args = ['push']
56
- args << '--dry-run' if options[:dryrun]
57
- args << '--force' if options[:force]
58
- system!(args + [remote_name] + refspecs)
59
- end
60
-
61
- def push_all(remote_name)
62
- system!('push', '--all', remote_name)
63
- system!('push', '--tags', remote_name)
64
- end
65
-
66
- def fetch(remote_name, options = {})
67
- args = ['fetch', '-p', remote_name]
68
- args += %w[--tags --prune-tags --force] if options[:tags]
69
- execute!(*args)
70
- end
71
-
72
- def current_branch
73
- execute!(%w[symbolic-ref -q HEAD]).gsub(%r{\Arefs/heads/}, '').strip
74
- end
75
-
76
- def reset_hard(ref)
77
- execute!('reset', '--hard', ref)
78
- end
79
-
80
- def raise(message)
81
- ::Kernel.raise Avm::Launcher::Git::Error.new(self, message)
82
- end
83
- end
84
- end
85
- end
86
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Avm
4
- module Launcher
5
- module Git
6
- class Error < StandardError
7
- def initialize(git_instance, message)
8
- super("#{message} (Repository: #{git_instance})")
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'avm/launcher/git/base'
4
-
5
- module Avm
6
- module Launcher
7
- module Git
8
- class MirrorUpdate < ::Avm::Launcher::Paths::Real
9
- include ::EacRubyUtils::SimpleCache
10
-
11
- def initialize(target_path, source_path, source_rev)
12
- super(target_path)
13
- @target_git = ::Avm::Launcher::Git::Base.new(self)
14
- @source_git = ::Avm::Launcher::Git::Base.new(source_path)
15
- @source_rev = source_rev
16
- run
17
- end
18
-
19
- private
20
-
21
- def run
22
- fetch_remote_source
23
- reset_source_rev
24
- end
25
-
26
- def fetch_remote_source
27
- @target_git.git
28
- @target_git.assert_remote_url('origin', @source_git)
29
- @target_git.fetch('origin', tags: true)
30
- end
31
-
32
- def reset_source_rev
33
- @target_git.reset_hard(@source_git.rev_parse(@source_rev, true))
34
- end
35
- end
36
- end
37
- end
38
- end
@@ -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