avm-tools 0.32.0 → 0.33.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2f7b0d99cc8ad01cab62e8b140114290035e233b898fd34b7c4aa91be927a1a
4
- data.tar.gz: e63aef5208960e0a69578669e120493e24cc52354b8a94dc018b49645c0211a0
3
+ metadata.gz: f6ddfc7d16b8fdfe9667b1946cce15ec58148f16bd8f0df9eeb20017e37b6410
4
+ data.tar.gz: b04f18cc844998d78c2f0f9e337c2f276e092d10bc8f7d43bb88dfe5dc024425
5
5
  SHA512:
6
- metadata.gz: 3b61fd2e8df381376ee6ed62b5e269d1f2e3202b698ef72757246b140cfe86c8f7d8582fd8064b8cb1808769af9f557203eba90f133a7228677513f8a74e92a7
7
- data.tar.gz: d2a648257b9440a06c032030a055d5bc26bb411728fa6275e5f7bed29b42134825f1cbdc7f30e415fb6a3982768943627ff058aaf197cfb020e9720e9a5d7443
6
+ metadata.gz: 3a1fdec71e84673c36e350c9802e60e16159da27bd8761c196e3adafaa6b4528d2a51de0b2a0ad19a3a9eabeddaf590242e860eae3421cd839a9cc69d02043c5
7
+ data.tar.gz: 6e0e9d04f05d2d9c62342930bf572bab4304725fa012a710fe1f69569ef8d6673271a68c4e0562bfa4e3de8a8a4af2996714788383421693ca0604167ebe2705
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/filesystem_cache'
4
+
5
+ module Avm
6
+ class << self
7
+ def fs_cache
8
+ @fs_cache ||= ::EacRubyUtils::FilesystemCache.new(ENV['HOME'], '.cache', 'avm')
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/fs_cache'
4
+ require 'avm/ruby'
5
+ require 'eac_ruby_utils/core_ext'
6
+
7
+ module Avm
8
+ module Git
9
+ class RevisionTest
10
+ enable_simple_cache
11
+ enable_console_speaker
12
+ common_constructor :git, :sha1, :options
13
+
14
+ def banner
15
+ infov 'Revision to test', sha1
16
+ on_speaker_node do |node|
17
+ node.stderr_line_prefix = ' '
18
+ infov '* Subject', commit.subject
19
+ infov '* Success?', successful_label
20
+ infov '* STDOUT', stdout_cache.content_path
21
+ infov '* STDERR', stderr_cache.content_path
22
+ end
23
+ end
24
+
25
+ def successful_label
26
+ successful?.to_s.send((successful? ? :green : :red))
27
+ end
28
+
29
+ def to_s
30
+ sha1
31
+ end
32
+
33
+ def successful?
34
+ successful
35
+ end
36
+
37
+ private
38
+
39
+ def checkout_revision
40
+ infom 'Checking out revision...'
41
+ git.execute!('checkout', sha1)
42
+ end
43
+
44
+ def commit_uncached
45
+ ::Avm::Git::Commit.new(git, sha1)
46
+ end
47
+
48
+ def git_absolute_path
49
+ ::File.expand_path(git.to_s)
50
+ end
51
+
52
+ def root_cache
53
+ ::Avm.fs_cache.child('git', 'revision_test', git_absolute_path.parameterize, sha1,
54
+ options.fetch(:test_command).to_s.parameterize)
55
+ end
56
+
57
+ def run_test
58
+ infom "Running test command \"#{::Shellwords.join(test_command_args)}\"" \
59
+ " on \"#{git_absolute_path}\"..."
60
+ result = ::Avm::Ruby.on_clean_environment { test_command.execute }
61
+ infom 'Test done'
62
+ write_result_cache(result)
63
+ end
64
+
65
+ def stdout_cache
66
+ root_cache.child('stdout')
67
+ end
68
+
69
+ def stderr_cache
70
+ root_cache.child('stderr')
71
+ end
72
+
73
+ def successful_cache
74
+ root_cache.child('successful')
75
+ end
76
+
77
+ def successful_uncached
78
+ if options.fetch(:no_cache) || !successful_cache.cached?
79
+ checkout_revision
80
+ run_test
81
+ end
82
+ successful_cache.read == 'true'
83
+ end
84
+
85
+ def test_command
86
+ ::EacRubyUtils::Envs.local.command(*test_command_args).chdir(git.to_s)
87
+ end
88
+
89
+ def test_command_args
90
+ r = ::Shellwords.split(options.fetch(:test_command).to_s)
91
+ return r if r.any?
92
+
93
+ raise 'No command found'
94
+ end
95
+
96
+ def write_result_cache(result)
97
+ stdout_cache.write(result[:stdout])
98
+ stderr_cache.write(result[:stderr])
99
+ successful_cache.write(result[:exit_code].zero? ? 'true' : 'false')
100
+ end
101
+ end
102
+ end
103
+ end
@@ -19,6 +19,10 @@ module Avm
19
19
  ::EacRubyUtils::Envs.local.command(*args)
20
20
  end
21
21
 
22
+ def dirty?
23
+ dirty_files.any?
24
+ end
25
+
22
26
  def dirty_files
23
27
  execute!('status', '--porcelain', '--untracked-files').each_line.map do |line|
24
28
  parse_status_line(line.gsub(/\n\z/, ''))
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module Ruby
5
+ class << self
6
+ def on_clean_environment
7
+ on_clean_envvars('BUNDLE', 'RUBY') { yield }
8
+ end
9
+
10
+ private
11
+
12
+ def on_clean_envvars(*start_with_vars)
13
+ old_values = envvars_starting_with(start_with_vars)
14
+ old_values.keys.each { |k| ENV.delete(k) }
15
+ yield
16
+ ensure
17
+ old_values&.each { |k, v| ENV[k] = v }
18
+ end
19
+
20
+ def envvars_starting_with(start_with_vars)
21
+ ENV.select { |k, _v| start_with_vars.any? { |var| k.start_with?(var) } }
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'avm/ruby'
3
4
  require 'avm/stereotypes/eac_webapp_base0/deploy'
4
5
 
5
6
  module Avm
@@ -10,7 +11,7 @@ module Avm
10
11
 
11
12
  def run_installer
12
13
  infom 'Running installer'
13
- on_clean_ruby do
14
+ ::Avm::Ruby.on_clean_environment do
14
15
  installer_command.system!
15
16
  end
16
17
  end
@@ -31,24 +32,6 @@ module Avm
31
32
  'redmine_as_apache_base'
32
33
  end
33
34
  end
34
-
35
- def on_clean_ruby
36
- on_clear_envvars('BUNDLE', 'RUBY') { yield }
37
- end
38
-
39
- private
40
-
41
- def on_clear_envvars(*start_with_vars)
42
- old_values = envvars_starting_with(start_with_vars)
43
- old_values.keys.each { |k| ENV.delete(k) }
44
- yield
45
- ensure
46
- old_values&.each { |k, v| ENV[k] = v }
47
- end
48
-
49
- def envvars_starting_with(start_with_vars)
50
- ENV.select { |k, _v| start_with_vars.any? { |var| k.start_with?(var) } }
51
- end
52
35
  end
53
36
  end
54
37
  end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_ruby_utils/console/docopt_runner'
5
+ require 'avm/git/revision_test'
6
+
7
+ module Avm
8
+ module Tools
9
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
10
+ class Git < ::EacRubyUtils::Console::DocoptRunner
11
+ class RevisionsTest < ::EacRubyUtils::Console::DocoptRunner
12
+ enable_simple_cache
13
+ enable_console_speaker
14
+
15
+ DOC = <<~DOCOPT
16
+ Test multiple revisions until a error is found.
17
+
18
+ Usage:
19
+ __PROGRAM__ [options]
20
+ __PROGRAM__ -h | --help
21
+
22
+ Options:
23
+ -h --help Mostra esta ajuda.
24
+ -c --command=<test-command> Command to test instance.
25
+ -n --no-cache Does not use cache.
26
+ DOCOPT
27
+
28
+ def run
29
+ fatal_error('Repository is dirty') if context(:git).dirty?
30
+
31
+ return_to_branch_on_end do
32
+ infov 'Revisions found', revisions.count
33
+ if revision_with_error
34
+ warn("First revision with error: #{revision_with_error}")
35
+ else
36
+ success('No error found in revisions')
37
+ end
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def return_to_branch_on_end
44
+ current_branch = context(:git).current_branch
45
+ yield
46
+ ensure
47
+ infom "Returning to original branch \"#{current_branch}\""
48
+ context(:git).execute!('checkout', current_branch)
49
+ end
50
+
51
+ def revision_with_error_uncached
52
+ revision_with_error = nil
53
+ revisions.each do |revision|
54
+ revision.banner
55
+ unless revision.successful?
56
+ revision_with_error = revision
57
+ break
58
+ end
59
+ end
60
+ revision_with_error
61
+ end
62
+
63
+ def revisions_uncached
64
+ context(:git).execute!('log', '--pretty=format:%H', 'origin/master..HEAD')
65
+ .each_line.map(&:strip).reverse.map do |sha1|
66
+ ::Avm::Git::RevisionTest.new(context(:git), sha1, test_revision_options)
67
+ end
68
+ end
69
+
70
+ def test_revision_options
71
+ { test_command: options.fetch('--command'), no_cache: options.fetch('--no-cache') }
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module Tools
5
- VERSION = '0.32.0'
5
+ VERSION = '0.33.0'
6
6
  end
7
7
  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.32.0
4
+ version: 0.33.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-02-07 00:00:00.000000000 Z
11
+ date: 2020-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aranha-parsers
@@ -194,6 +194,7 @@ files:
194
194
  - lib/avm/executables.rb
195
195
  - lib/avm/files.rb
196
196
  - lib/avm/files/rotate.rb
197
+ - lib/avm/fs_cache.rb
197
198
  - lib/avm/git.rb
198
199
  - lib/avm/git/commit.rb
199
200
  - lib/avm/git/commit/deploy.rb
@@ -209,6 +210,7 @@ files:
209
210
  - lib/avm/git/issue/complete/_remote.rb
210
211
  - lib/avm/git/issue/complete/_tracker.rb
211
212
  - lib/avm/git/issue/complete/_validations.rb
213
+ - lib/avm/git/revision_test.rb
212
214
  - lib/avm/git/spec_helper.rb
213
215
  - lib/avm/instances.rb
214
216
  - lib/avm/instances/application.rb
@@ -232,6 +234,7 @@ files:
232
234
  - lib/avm/patches/object/template.rb
233
235
  - lib/avm/path_string.rb
234
236
  - lib/avm/result.rb
237
+ - lib/avm/ruby.rb
235
238
  - lib/avm/self.rb
236
239
  - lib/avm/self/docker_image.rb
237
240
  - lib/avm/self/instance.rb
@@ -293,6 +296,7 @@ files:
293
296
  - lib/avm/tools/runner/git/dirty_files.rb
294
297
  - lib/avm/tools/runner/git/issue.rb
295
298
  - lib/avm/tools/runner/git/issue/complete.rb
299
+ - lib/avm/tools/runner/git/revisions_test.rb
296
300
  - lib/avm/tools/runner/self.rb
297
301
  - lib/avm/tools/runner/self/docker.rb
298
302
  - lib/avm/tools/version.rb