avm-tools 0.58.1 → 0.59.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/lib/avm/local_projects.rb +9 -0
  3. data/lib/avm/local_projects/instance.rb +28 -0
  4. data/lib/avm/projects.rb +9 -0
  5. data/lib/avm/projects/stereotype.rb +55 -0
  6. data/lib/avm/projects/stereotypes.rb +20 -0
  7. data/lib/avm/projects/stereotypes/git.rb +25 -0
  8. data/lib/avm/projects/stereotypes/git/publish.rb +15 -0
  9. data/lib/avm/projects/stereotypes/git/warp.rb +27 -0
  10. data/lib/avm/projects/stereotypes/git_subrepo.rb +34 -0
  11. data/lib/avm/projects/stereotypes/git_subrepo/publish.rb +14 -0
  12. data/lib/avm/projects/stereotypes/git_subrepo/warp.rb +87 -0
  13. data/lib/avm/projects/stereotypes/git_subtree.rb +51 -0
  14. data/lib/avm/projects/stereotypes/git_subtree/publish.rb +12 -0
  15. data/lib/avm/projects/stereotypes/git_subtree/warp.rb +29 -0
  16. data/lib/avm/projects/stereotypes/rails_application.rb +23 -0
  17. data/lib/avm/projects/stereotypes/redmine_plugin.rb +23 -0
  18. data/lib/avm/projects/stereotypes/ruby_gem.rb +30 -0
  19. data/lib/avm/projects/stereotypes/ruby_gem/publish.rb +129 -0
  20. data/lib/avm/tools/runner/launcher.rb +10 -2
  21. data/lib/avm/tools/runner/launcher/instances.rb +45 -0
  22. data/lib/avm/tools/runner/launcher/projects.rb +50 -0
  23. data/lib/avm/tools/runner/launcher/publish.rb +65 -0
  24. data/lib/avm/tools/runner/local_project.rb +32 -0
  25. data/lib/avm/tools/runner/local_project/info.rb +25 -0
  26. data/lib/avm/tools/version.rb +1 -1
  27. data/lib/eac_launcher.rb +1 -2
  28. data/lib/eac_launcher/git/publish_base.rb +1 -0
  29. data/lib/eac_launcher/git/sub_warp_base.rb +1 -1
  30. data/lib/eac_launcher/git/warp_base.rb +2 -2
  31. data/lib/eac_launcher/instances/base.rb +2 -2
  32. data/lib/eac_launcher/instances/runner_helper.rb +1 -1
  33. data/lib/eac_launcher/paths/logical.rb +2 -2
  34. metadata +25 -21
  35. data/lib/eac_launcher/runner.rb +0 -21
  36. data/lib/eac_launcher/runner/instances.rb +0 -41
  37. data/lib/eac_launcher/runner/projects.rb +0 -46
  38. data/lib/eac_launcher/runner/publish.rb +0 -59
  39. data/lib/eac_launcher/stereotype.rb +0 -52
  40. data/lib/eac_launcher/stereotypes.rb +0 -14
  41. data/lib/eac_launcher/stereotypes/git.rb +0 -21
  42. data/lib/eac_launcher/stereotypes/git/publish.rb +0 -13
  43. data/lib/eac_launcher/stereotypes/git/warp.rb +0 -25
  44. data/lib/eac_launcher/stereotypes/git_subrepo.rb +0 -30
  45. data/lib/eac_launcher/stereotypes/git_subrepo/publish.rb +0 -12
  46. data/lib/eac_launcher/stereotypes/git_subrepo/warp.rb +0 -85
  47. data/lib/eac_launcher/stereotypes/git_subtree.rb +0 -47
  48. data/lib/eac_launcher/stereotypes/git_subtree/publish.rb +0 -10
  49. data/lib/eac_launcher/stereotypes/git_subtree/warp.rb +0 -27
  50. data/lib/eac_launcher/stereotypes/rails.rb +0 -21
  51. data/lib/eac_launcher/stereotypes/redmine_plugin.rb +0 -21
  52. data/lib/eac_launcher/stereotypes/ruby_gem.rb +0 -27
  53. data/lib/eac_launcher/stereotypes/ruby_gem/publish.rb +0 -127
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/projects/stereotype'
4
+
5
+ module Avm
6
+ module Projects
7
+ module Stereotypes
8
+ class RailsApplication
9
+ include Avm::Projects::Stereotype
10
+
11
+ class << self
12
+ def match?(path)
13
+ File.exist?(path.real.subpath('config.ru')) && path.real.basename != 'dummy'
14
+ end
15
+
16
+ def color
17
+ :magenta
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/projects/stereotype'
4
+
5
+ module Avm
6
+ module Projects
7
+ module Stereotypes
8
+ class RedminePlugin
9
+ include Avm::Projects::Stereotype
10
+
11
+ class << self
12
+ def match?(path)
13
+ File.exist?(path.real.subpath('init.rb'))
14
+ end
15
+
16
+ def color
17
+ :light_magenta
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/projects/stereotype'
4
+ require 'eac_launcher/ruby/gem/specification'
5
+ require 'eac_ruby_utils/core_ext'
6
+
7
+ module Avm
8
+ module Projects
9
+ module Stereotypes
10
+ class RubyGem
11
+ require_sub __FILE__
12
+ include Avm::Projects::Stereotype
13
+
14
+ class << self
15
+ def match?(path)
16
+ Dir.glob(File.join(path.real, '*.gemspec')).any?
17
+ end
18
+
19
+ def color
20
+ :red
21
+ end
22
+
23
+ def load_gemspec(gemspec_file)
24
+ ::EacLauncher::Ruby::Gem::Specification.new(gemspec_file)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,129 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'curb'
4
+ require 'json'
5
+ require 'eac_ruby_utils/simple_cache'
6
+ require 'rubygems'
7
+ require 'eac_ruby_utils/console/speaker'
8
+ require 'eac_launcher/publish/base'
9
+ require 'eac_launcher/publish/check_result'
10
+ require 'eac_launcher/ruby/gem'
11
+
12
+ module Avm
13
+ module Projects
14
+ module Stereotypes
15
+ class RubyGem
16
+ class Publish < ::EacLauncher::Publish::Base
17
+ include ::EacRubyUtils::SimpleCache
18
+ include ::EacRubyUtils::Console::Speaker
19
+
20
+ protected
21
+
22
+ def internal_check
23
+ gem_published? ? internal_check_gem_published : internal_check_gem_unpublished
24
+ end
25
+
26
+ private
27
+
28
+ def internal_check_gem_published
29
+ if version_published?
30
+ outdated_version? ? outdated_version_check_result : version_published_check_result
31
+ else
32
+ version_unpublished_check_result
33
+ end
34
+ end
35
+
36
+ def internal_check_gem_unpublished
37
+ if new_gem_allowed?
38
+ version_unpublished_check_result
39
+ else
40
+ new_gem_disallowed_check_result
41
+ end
42
+ end
43
+
44
+ def new_gem_disallowed_check_result
45
+ ::EacLauncher::Publish::CheckResult.blocked(
46
+ "#{gem_spec.full_name} does not exist in RubyGems"
47
+ )
48
+ end
49
+
50
+ def version_published_check_result
51
+ ::EacLauncher::Publish::CheckResult.updated("#{gem_spec.full_name} already pushed")
52
+ end
53
+
54
+ def outdated_version_check_result
55
+ ::EacLauncher::Publish::CheckResult.outdated(
56
+ "#{gem_spec.full_name} is outdated (Max: #{gem_version_max})"
57
+ )
58
+ end
59
+
60
+ def version_unpublished_check_result
61
+ ::EacLauncher::Publish::CheckResult.pending("#{gem_spec.full_name} not found " \
62
+ 'in RubyGems')
63
+ end
64
+
65
+ def source_uncached
66
+ instance.warped
67
+ end
68
+
69
+ def gem_spec_uncached
70
+ ::Avm::Projects::Stereotypes::RubyGem.load_gemspec(gemspec)
71
+ end
72
+
73
+ def gem_build_uncached
74
+ ::EacLauncher::Ruby::Gem::Build.new(source)
75
+ end
76
+
77
+ def publish
78
+ gem_build.build
79
+ push_gem
80
+ ensure
81
+ gem_build.close
82
+ end
83
+
84
+ def new_gem_allowed?
85
+ ::EacLauncher::Context.current.publish_options[:new]
86
+ end
87
+
88
+ def gem_published?
89
+ gem_versions.any?
90
+ end
91
+
92
+ def version_published?
93
+ gem_versions.any? { |v| v['number'] == gem_spec.version }
94
+ end
95
+
96
+ def outdated_version?
97
+ gem_version_max.present? && ::Gem::Version.new(gem_spec.version) < gem_version_max
98
+ end
99
+
100
+ def gem_versions_uncached
101
+ http = Curl.get("https://rubygems.org/api/v1/versions/#{gem_spec.name}.json")
102
+ return JSON.parse!(http.body_str) if /\A2/ =~ http.status
103
+ return [] if /\A4/ =~ http.status
104
+
105
+ raise "#{http} code error: #{http.status}"
106
+ end
107
+
108
+ def gem_version_max_uncached
109
+ gem_versions.map { |v| ::Gem::Version.new(v['number']) }.max
110
+ end
111
+
112
+ def push_gem
113
+ info("Pushing gem #{gem_spec}...")
114
+ command = ['gem', 'push', gem_build.output_file]
115
+ unless ::EacLauncher::Context.current.publish_options[:confirm]
116
+ command = %w[echo] + command + %w[(Dry-run)]
117
+ end
118
+ EacRubyUtils::Envs.local.command(command).system
119
+ info('Pushed!')
120
+ end
121
+
122
+ def gemspec_uncached
123
+ source.find_file_with_extension('.gemspec')
124
+ end
125
+ end
126
+ end
127
+ end
128
+ end
129
+ end
@@ -1,11 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_launcher/runner'
3
+ require 'eac_cli/default_runner'
4
+ require 'eac_ruby_utils/core_ext'
4
5
 
5
6
  module Avm
6
7
  module Tools
7
8
  class Runner < ::EacRubyUtils::Console::DocoptRunner
8
- class Launcher < ::EacLauncher::Runner
9
+ class Launcher < ::EacRubyUtils::Console::DocoptRunner
10
+ require_sub __FILE__
11
+ include ::EacCli::DefaultRunner
12
+
13
+ runner_definition do
14
+ desc 'Utilities to deploy applications and libraries.'
15
+ subcommands
16
+ end
9
17
  end
10
18
  end
11
19
  end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_launcher/instances/runner_helper'
4
+
5
+ module Avm
6
+ module Tools
7
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
8
+ class Launcher < ::EacRubyUtils::Console::DocoptRunner
9
+ class Instances < ::EacLauncher::Instances::RunnerHelper
10
+ DOC = <<~DOCOPT
11
+ Mostra informações sobre instâncias.
12
+
13
+ Usage:
14
+ __PROGRAM__ [options] [<instance_path>...]
15
+ __PROGRAM__ -h | --help
16
+
17
+ Options:
18
+ -h --help Show this screen.
19
+ --all Get all instances.
20
+ --recache Rewrite instances cache.
21
+
22
+ DOCOPT
23
+
24
+ def run
25
+ ::EacLauncher::Context.current.recache = options['--recache']
26
+ instances.each { |i| show_instance(i) }
27
+ end
28
+
29
+ private
30
+
31
+ def show_instance(instance)
32
+ puts instance_label(instance)
33
+ infov(' * Parent', (instance.parent ? instance_label(instance.parent) : '-'))
34
+ infov(' * Git current revision', instance.options.git_current_revision)
35
+ infov(' * Git publish remote', instance.options.git_publish_remote)
36
+ end
37
+
38
+ def instance_path
39
+ options['<instance_path>']
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_launcher/context'
4
+ require 'eac_launcher/instances/runner_helper'
5
+
6
+ module Avm
7
+ module Tools
8
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
9
+ class Launcher < ::EacRubyUtils::Console::DocoptRunner
10
+ class Projects < ::EacLauncher::Instances::RunnerHelper
11
+ DOC = <<~DOCOPT
12
+ Shows available projects.
13
+
14
+ Usage:
15
+ __PROGRAM__ [options]
16
+ __PROGRAM__ -h | --help
17
+
18
+ Options:
19
+ -h --help Show this screen.
20
+ -i --instances Show instances.
21
+ --recache Rewrite instances cache.
22
+
23
+ DOCOPT
24
+
25
+ def run
26
+ ::EacLauncher::Context.current.recache = options['--recache']
27
+ ::EacLauncher::Context.current.projects.each do |p|
28
+ show_project(p)
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def show_project(project)
35
+ puts project_label(project)
36
+ return unless options['--instances']
37
+
38
+ project.instances.each do |i|
39
+ puts " * #{instance_label(i)}"
40
+ end
41
+ end
42
+
43
+ def project_label(project)
44
+ project.to_s.cyan.to_s
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_launcher/instances/runner_helper'
4
+
5
+ module Avm
6
+ module Tools
7
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
8
+ class Launcher < ::EacRubyUtils::Console::DocoptRunner
9
+ class Publish < ::EacLauncher::Instances::RunnerHelper
10
+ DOC = <<~DOCOPT
11
+ Publica projetos ou instâncias.
12
+
13
+ Usage:
14
+ __PROGRAM__ [options] [<instance_path>...]
15
+ __PROGRAM__ -h | --help
16
+
17
+ Options:
18
+ -h --help Show this screen.
19
+ --new Publish projects not published before.
20
+ -s --stereotype=<st> Publish only for stereotype <stereotype>.
21
+ --all Publish all instances.
22
+ -d --dry-run "Dry run" publishing.
23
+ --pending Publish only pending.
24
+ --recache Rewrite instances cache.
25
+ --run Confirm publishing.
26
+
27
+ DOCOPT
28
+
29
+ def run
30
+ ::EacLauncher::Context.current.recache = options['--recache']
31
+ build_publish_options
32
+ instances.each do |i|
33
+ next unless i.options.publishable?
34
+
35
+ i.send(instance_method)
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def dry_run?
42
+ options.fetch('--dry-run')
43
+ end
44
+
45
+ def instance_method
46
+ run? || dry_run? ? 'publish_run' : 'publish_check'
47
+ end
48
+
49
+ def build_publish_options
50
+ ::EacLauncher::Context.current.publish_options = publish_options
51
+ end
52
+
53
+ def publish_options
54
+ { new: options.fetch('--new'), stereotype: options.fetch('--stereotype'),
55
+ confirm: run? }
56
+ end
57
+
58
+ def run?
59
+ options.fetch('--run') && !dry_run?
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/console/docopt_runner'
4
+ require 'eac_ruby_utils/core_ext'
5
+ require 'avm/local_projects/instance'
6
+
7
+ module Avm
8
+ module Tools
9
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
10
+ class LocalProject < ::EacRubyUtils::Console::DocoptRunner
11
+ require_sub __FILE__
12
+ include ::EacCli::DefaultRunner
13
+
14
+ runner_definition do
15
+ desc 'Utilities for local projects.'
16
+ arg_opt '-C', '--path', 'Path to local project instance.'
17
+ subcommands
18
+ end
19
+
20
+ private
21
+
22
+ def instance_uncached
23
+ ::Avm::LocalProject::Instance.new(instance_path)
24
+ end
25
+
26
+ def instance_path_uncached
27
+ (options.fetch('--path') || '.').to_pathname.expand_path
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,25 @@
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 Info < ::EacRubyUtils::Console::DocoptRunner
11
+ include ::EacCli::DefaultRunner
12
+
13
+ runner_definition do
14
+ desc 'Show information about local project instance.'
15
+ end
16
+
17
+ def run
18
+ infov 'Path', context(:instance).path
19
+ infov 'Stereotypes', context(:instance).stereotypes.map(&:label).join(', ')
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end