milou 0.0.6 → 0.0.7

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: df81326dc5e5454d15d4ed6611611fffc3d2f00723b5bdf584702828e68eb702
4
- data.tar.gz: b958f56028ebac211ce2414a1a511e0c2116bd6a11831aa33e4ae7a2e419b7ef
3
+ metadata.gz: 687aec27808949b4cbc36912fb43a4da89914b0ee8615d654c9ef5cf7c154654
4
+ data.tar.gz: d4592882c81da612bbc4c1957a56a744f8c864e14cc46e5b3340d61d4579952c
5
5
  SHA512:
6
- metadata.gz: 9d4fdc65b08a6b465173f8b1cd4766b4acd98956ab928ce6a97e1162c8709ac5ccbbb62c75af06dbc621111f90468a08f65f186f9bc7a289dd13cf244f432a54
7
- data.tar.gz: db0c028274f4dac4709e2b3ac3388936139fab7a83cc935fe9092d824f7abd071635dca1b0aaf35e691d5045df9a9bada03f317fe5f08edaa2803204d8e4cae5
6
+ metadata.gz: 7664f8a943335848af0790f481085c0a4d8c5fcae055061fe03b9ccfc5daaa43606c88636e52813a74c674f8d776120b7d4c6fcc856fc3ad39ab86edecfbb2cd
7
+ data.tar.gz: bce1b121bc7ff1a24c6edf2188d238cdf70b25f2249822a172be23bd3afc5eaa47bd02e74af5c4043d2f35e6933ab4891614f76b4eb184875e7c98725af895f5
data/bin/watchdog CHANGED
@@ -1,14 +1,18 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'watchdog'
3
+ require "watchdog/version"
3
4
  puts ARGV
4
5
 
6
+ case ARGV[1]
7
+ when 'bootstrap'
8
+ puts Watchdog::bootstrap
9
+ end
10
+
5
11
  case ARGV[0]
6
12
  when 'detox'
7
13
  puts Watchdog::run_detox
8
- when 'jest'
9
- puts 'JEST'
10
- when 'hackerman'
11
- puts Watchdog::run_hacker
14
+ when 'version'
15
+ puts Watchdog::VERSION
12
16
  else
13
17
  puts 'need to specify which runner'
14
18
  end
@@ -0,0 +1,24 @@
1
+ require_relative 'utils'
2
+
3
+ module Watchdog
4
+ class Bootstrap
5
+ def self.clone_repository(git_url)
6
+ %x[ #{"git clone #{git_url} project_dir"} ]
7
+
8
+ $watchdog_relative_dir = 'project_dir'
9
+ end
10
+
11
+ def self.change_branch(git_branch)
12
+ Watchdog::Utils.run_cmd "git checkout #{git_branch}"
13
+ Watchdog::Utils.run_cmd "git reset --hard origin/#{git_branch}"
14
+ end
15
+
16
+ def self.setup_environment
17
+ %x[ #{"cp .env.project #{$watchdog_relative_dir}/.env"} ]
18
+ end
19
+
20
+ def self.setup_project(setup_cmd)
21
+ Watchdog::Utils.run_cmd setup_cmd
22
+ end
23
+ end
24
+ end
@@ -1,30 +1,49 @@
1
1
  require 'httparty'
2
2
 
3
+ require_relative 'utils'
4
+
3
5
  module Watchdog
4
6
  class Detox
5
7
  def initialize()
6
8
  end
7
9
 
8
10
  def run
11
+ build_detox
12
+
9
13
  detox_result = run_detox
10
14
 
11
15
  run_watchdog(detox_result)
12
16
  end
13
17
 
18
+ def build_detox
19
+ detox_cmd = 'yarn run detox-build'
20
+
21
+ Watchdog::Utils.run_cmd detox_cmd
22
+
23
+ # %x[ #{detox_cmd} 2>&1 ]
24
+ end
25
+
14
26
  # Detox runner
15
27
  def run_detox
16
28
  detox_cmd = 'yarn run detox-test'
17
29
 
18
- %x[ #{detox_cmd} 2>&1 ]
30
+ Watchdog::Utils.run_cmd(detox_cmd).chomp
31
+
32
+ # %x[ #{detox_cmd} 2>&1 ]
19
33
  end
20
34
 
21
35
  # Watchdog runner
22
36
  def run_watchdog(detox_result)
37
+
23
38
  status_regex = /(FAIL|PASS) (.*\.js) \((.*)\)/
24
39
 
25
- commit_branch = %x[ #{'git symbolic-ref --short HEAD'} 2>&1 ]
26
- commit_sha = %x[ #{'git --no-pager show -s --format=%H'} 2>&1 ]
27
- commit_timestamp = %x[ #{'git --no-pager log -1 --format=%cd'} 2>&1 ]
40
+ commit_branch = Watchdog::Utils.run_cmd('git symbolic-ref --short HEAD').chomp
41
+ commit_sha = Watchdog::Utils.run_cmd('git --no-pager show -s --format=%H').chomp
42
+ commit_timestamp = Watchdog::Utils.run_cmd('git --no-pager log -1 --format=%cd').chomp
43
+
44
+ # commit_branch = %x[ #{'git symbolic-ref --short HEAD'} 2>&1 ]
45
+ # commit_sha = %x[ #{'git --no-pager show -s --format=%H'} 2>&1 ]
46
+ # commit_timestamp = %x[ #{'git --no-pager log -1 --format=%cd'} 2>&1 ]
28
47
 
29
48
  run = {
30
49
  test_run: {
@@ -36,9 +55,6 @@ module Watchdog
36
55
  }
37
56
  }
38
57
 
39
- puts 'detox_result'
40
- puts detox_result
41
-
42
58
  detox_result.each_line do |line|
43
59
  line_match = line.match(status_regex)
44
60
 
@@ -56,7 +72,8 @@ module Watchdog
56
72
  'Content-Type' => 'application/json',
57
73
  'X-API-KEY' => ENV['WATCHDOG_AUTH_TOKEN']
58
74
  }
59
-
75
+ puts "run"
76
+ puts run
60
77
  response = HTTParty.post(
61
78
  ENV['WATCHDOG_API_URL'],
62
79
  :body => run.to_json,
@@ -0,0 +1,16 @@
1
+ module Watchdog
2
+ class Utils
3
+ def self.run_cmd(cmd)
4
+ if $watchdog_relative_dir
5
+ Dir.chdir($watchdog_relative_dir){
6
+ # %x[ #{cmd} ]
7
+ _out, err, _sts = Open3.capture3(cmd)
8
+ return _out
9
+ }
10
+ else
11
+ _out, err, _sts = Open3.capture3(cmd)
12
+ return _out
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Watchdog
4
- VERSION = "0.0.6".freeze
4
+ VERSION = "0.0.7".freeze
5
5
  end
data/lib/watchdog.rb CHANGED
@@ -2,16 +2,29 @@ require 'dotenv'
2
2
  Dotenv.load
3
3
 
4
4
  require_relative 'watchdog/detox'
5
- require_relative 'watchdog/hacker'
5
+ require_relative 'watchdog/bootstrap'
6
6
 
7
7
  module Watchdog
8
- def self.run_detox
9
- runner = Watchdog::Detox.new
10
- runner.run
8
+ def self.bootstrap
9
+ if ENV['WATCHDOG_GIT_URL']
10
+ Watchdog::Bootstrap.clone_repository(ENV['WATCHDOG_GIT_URL'])
11
+
12
+ if ENV['WATCHDOG_GIT_BRANCH']
13
+ Watchdog::Bootstrap.change_branch(ENV['WATCHDOG_GIT_BRANCH'])
14
+ end
15
+
16
+ Watchdog::Bootstrap.setup_environment
17
+
18
+ if ENV['WATCHDOG_SETUP_CMD']
19
+ Watchdog::Bootstrap.setup_project(ENV['WATCHDOG_SETUP_CMD'])
20
+ end
21
+ else
22
+ puts 'Bootstrap execution missing WATCHDOG_GIT_URL in environment'
23
+ end
11
24
  end
12
25
 
13
- def self.run_hacker
14
- runner = Watchdog::Hacker.new
26
+ def self.run_detox
27
+ runner = Watchdog::Detox.new
15
28
  runner.run
16
29
  end
17
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: milou
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Silva
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-05 00:00:00.000000000 Z
11
+ date: 2022-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
@@ -48,8 +48,9 @@ extra_rdoc_files: []
48
48
  files:
49
49
  - bin/watchdog
50
50
  - lib/watchdog.rb
51
+ - lib/watchdog/bootstrap.rb
51
52
  - lib/watchdog/detox.rb
52
- - lib/watchdog/hacker.rb
53
+ - lib/watchdog/utils.rb
53
54
  - lib/watchdog/version.rb
54
55
  homepage: https://github.com/Gaspard-Bruno/watchdog-ruby-gem
55
56
  licenses:
@@ -1,46 +0,0 @@
1
- require 'httparty'
2
-
3
- module Watchdog
4
- class Hacker
5
- def initialize()
6
- end
7
-
8
- def run
9
- send_test
10
- end
11
-
12
- # Watchdog runner
13
- def send_test
14
- run = {
15
- test_run: {
16
- commit_branch: "main",
17
- commit_sha: "awugdadba",
18
- commit_timestamp: "2022-05-27 17:42:31 +0100",
19
- test_suite_name: "Test Suite v3",
20
- test_results: [
21
- { status: "FAIL", test: "TEST-1", time: "50.028" },
22
- { status: "PASS", test: "TEST-2", time: "31.363" },
23
- ]
24
- }
25
- }
26
-
27
- puts "ENV"
28
- puts ENV['WATCHDOG_TEST_SUIT_NAME']
29
- puts ENV['WATCHDOG_AUTH_TOKEN']
30
- puts ENV['WATCHDOG_API_URL']
31
-
32
- headers = {
33
- 'Content-Type' => 'application/json',
34
- 'X-API-KEY' => ENV['WATCHDOG_AUTH_TOKEN']
35
- }
36
- puts headers
37
- response = HTTParty.post(
38
- ENV['WATCHDOG_API_URL'],
39
- :body => run.to_json,
40
- :headers => headers
41
- )
42
-
43
- puts "Watchdog response: #{response}"
44
- end
45
- end
46
- end