fastlane-plugin-mango 1.1.0 → 1.1.1

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: 968c3231a114d8f5b371c05d887cc9e9dcb908f7baa8729370e9ba97dfab4c2c
4
- data.tar.gz: c0a3a9c50e99ca15806fbb253e10349f6cd263677cf6e45dad03078e04ebc584
3
+ metadata.gz: b461b1084d0ae59adbf1f20844acf789c2c8f04ab66dd26f54ce90251960130c
4
+ data.tar.gz: 7a77604dc25fc8b70eeef54acfb3e66571c5b18506202d9c49f4c57854a68beb
5
5
  SHA512:
6
- metadata.gz: db22d989c74376ec53583f7acb8254b4b01cabaff64a8742fa068b137bd023c1bc74dd80b3b0d8ebdde6f60e87b1e17324acf4968433239e1d3c5ac1023d4547
7
- data.tar.gz: 7d87f2df5052ade2b4aa40eb3999e28b2fe6f30c9eaf0974681048042a0ac53a2270ccaab4579db8178e82ef6797ebe9f54a37efe3be30d02d5799c5c4c33729
6
+ metadata.gz: 9c6f546b393173e943ef8c60217ade021ba1cf7cb0e3c4ab5ff9734316eb49121f005d4ba9e33101a19bf786b611e6684cbf05623ede9b3ab9dfadcb87f9d37e
7
+ data.tar.gz: 1df19671e8722c6c5bec82a1b1f77d5c59f2917bd1a8652cd69772929c5af3d0ae28ec9bb5a6ede443d8383b8af806aeacf9c6c172ef9c1f46010b46e9055f98
@@ -8,6 +8,8 @@ module Fastlane
8
8
  mango_helper = Fastlane::Helper::MangoHelper.new(params)
9
9
  mango_helper.setup_container
10
10
 
11
+ docker_commander = Helper::DockerCommander.new(mango_helper.container_name)
12
+
11
13
  failure_buffer_timeout = 5
12
14
  timeout_command = "timeout #{params[:maximal_run_time] - failure_buffer_timeout}m"
13
15
  workspace_dir = params[:workspace_dir]
@@ -17,13 +19,13 @@ module Fastlane
17
19
  UI.success("Starting Android Task.")
18
20
  bundle_install = params[:bundle_install] ? '&& bundle install ' : ''
19
21
 
20
- Helper::DockerCommander.docker_exec(command: "cd #{workspace_dir} #{bundle_install}&& #{timeout_command} #{android_task} || exit 1", container_name: mango_helper.container_name)
22
+ docker_commander.exec(command: "cd #{workspace_dir} #{bundle_install}&& #{timeout_command} #{android_task} || exit 1")
21
23
  end
22
24
 
23
25
  ensure
24
26
  post_actions = params[:post_actions]
25
27
  if post_actions && !mango_helper.kvm_disabled?
26
- Helper::DockerCommander.docker_exec(command: "cd #{workspace_dir} && #{post_actions}", container_name: mango_helper.container_name)
28
+ docker_commander.exec(command: "cd #{workspace_dir} && #{post_actions}")
27
29
  end
28
30
 
29
31
  UI.important("Cleaning up #{params[:emulator_name]} container")
@@ -3,17 +3,23 @@ require 'os'
3
3
 
4
4
  module Fastlane
5
5
  module Helper
6
- module DockerCommander
6
+ class DockerCommander
7
7
 
8
- def self.pull_image(docker_image_name:)
8
+ attr_accessor :container_name
9
+
10
+ def initialize(container_name)
11
+ @container_name = container_name
12
+ end
13
+
14
+ def pull_image(docker_image_name:)
9
15
  handle_thin_pool_exception do
10
16
  Actions.sh("docker pull #{docker_image_name}")
11
17
  end
12
18
  end
13
19
 
14
- def self.start_container(emulator_args:, docker_name:, docker_image:)
15
- docker_name = if docker_name
16
- "--name #{docker_name}"
20
+ def start_container(emulator_args:, docker_image:)
21
+ docker_name = if container_name
22
+ "--name #{container_name}"
17
23
  else
18
24
  ''
19
25
  end
@@ -26,25 +32,33 @@ module Fastlane
26
32
  end
27
33
  end
28
34
 
29
- def self.stop_container(container_name:)
35
+ def stop_container
30
36
  Actions.sh("docker stop #{container_name}") if container_name
31
37
  end
32
38
 
33
- def self.delete_container(container_name:)
39
+ def delete_container
34
40
  Actions.sh("docker rm #{container_name}") if container_name
35
41
  end
36
42
 
37
- def self.disconnect_network_bridge(container_name:)
43
+ def disconnect_network_bridge
38
44
  Actions.sh("docker network disconnect -f bridge #{container_name}") if container_name
39
45
  rescue StandardError
40
46
  # Do nothing if the network bridge is already gone
41
47
  end
42
48
 
43
- def self.prune
49
+ def exec(command:)
50
+ if container_name
51
+ Actions.sh("docker exec -i #{container_name} bash -l -c \"#{command}\"")
52
+ else
53
+ raise('Cannot execute docker command because the container name is unknown')
54
+ end
55
+ end
56
+
57
+ def prune
44
58
  Action.sh('docker system prune -f')
45
59
  end
46
60
 
47
- def self.handle_thin_pool_exception(&block)
61
+ def handle_thin_pool_exception(&block)
48
62
  begin
49
63
  block.call
50
64
  rescue FastlaneCore::Interface::FastlaneShellError => exception
@@ -58,9 +72,6 @@ module Fastlane
58
72
  end
59
73
  end
60
74
 
61
- def self.docker_exec(command:, container_name:)
62
- Actions.sh("docker exec -i #{container_name} bash -l -c \"#{command}\"") if container_name
63
- end
64
75
  end
65
76
  end
66
77
  end
@@ -2,23 +2,43 @@ require_relative 'docker_commander'
2
2
 
3
3
  module Fastlane
4
4
  module Helper
5
- module EmulatorCommander
6
5
 
7
- def self.disable_animations(container_name:)
8
- DockerCommander.docker_exec(command: 'adb shell settings put global window_animation_scale 0.0', container_name: container_name)
9
- DockerCommander.docker_exec(command: 'adb shell settings put global transition_animation_scale 0.0', container_name: container_name)
10
- DockerCommander.docker_exec(command: 'adb shell settings put global animator_duration_scale 0.0', container_name: container_name)
6
+ class EmulatorCommander
7
+
8
+ attr_accessor :container_name
9
+
10
+ def initialize(container_name)
11
+ @container_name = container_name
12
+ @docker_commander = DockerCommander.new(container_name)
13
+ end
14
+
15
+ # Disables animation for faster and stable testing
16
+ def disable_animations
17
+ @docker_commander.exec(command: 'adb shell settings put global window_animation_scale 0.0')
18
+ @docker_commander.exec(command: 'adb shell settings put global transition_animation_scale 0.0')
19
+ @docker_commander.exec(command: 'adb shell settings put global animator_duration_scale 0.0')
20
+ rescue FastlaneCore::Interface::FastlaneShellError => e
21
+ # Under weird circumstances it can happen that adb is running but shell on the emu is not completely up
22
+ # it recovers after some time, so wait and retry
23
+ retry_counter = retry_counter.to_i + 1
24
+ if retry_counter <= 5
25
+ sleep 10*retry_counter
26
+ retry
27
+ else
28
+ raise e
29
+ end
11
30
  end
12
31
 
13
- def self.increase_logcat_storage(container_name:)
14
- DockerCommander.docker_exec(command: 'adb logcat -G 16m', container_name: container_name)
32
+ # Increases logcat storage
33
+ def increase_logcat_storage
34
+ @docker_commander.exec(command: 'adb logcat -G 16m')
15
35
  end
16
36
 
17
- # Checks if created emulator is connected
18
- def self.check_connection(container_name:)
37
+ # Restarts adb on the separate port and checks if created emulator is connected
38
+ def check_connection
19
39
  UI.success('Checking if emulator is connected to ADB.')
20
40
 
21
- if emulator_is_healthy?(container_name: container_name)
41
+ if emulator_is_healthy?
22
42
  UI.success('Emulator connected successfully')
23
43
  true
24
44
  else
@@ -27,8 +47,8 @@ module Fastlane
27
47
  end
28
48
  end
29
49
 
30
- def self.emulator_is_healthy?(container_name: container_name)
31
- list_devices = DockerCommander.docker_exec(command: 'adb devices', container_name: container_name)
50
+ def emulator_is_healthy?
51
+ list_devices = @docker_commander.exec(command: 'adb devices')
32
52
  list_devices.include? "\tdevice"
33
53
  end
34
54
  end
@@ -26,6 +26,9 @@ module Fastlane
26
26
  @pre_action = params[:pre_action]
27
27
  @docker_registry_login = params[:docker_registry_login]
28
28
  @pull_latest_image = params[:pull_latest_image]
29
+
30
+ @docker_commander = DockerCommander.new(container_name)
31
+ @emulator_commander = EmulatorCommander.new(container_name)
29
32
  end
30
33
 
31
34
  # Setting up the container:
@@ -48,7 +51,7 @@ module Fastlane
48
51
  pull_from_registry if @pull_latest_image
49
52
 
50
53
  # Make sure that network bridge for the current container is not already used
51
- DockerCommander.disconnect_network_bridge(container_name: container_name)
54
+ @docker_commander.disconnect_network_bridge
52
55
 
53
56
  create_container
54
57
 
@@ -59,7 +62,7 @@ module Fastlane
59
62
  container_state = wait_for_healthy_container
60
63
 
61
64
  if is_running_on_emulator
62
- connection_state = EmulatorCommander.check_connection(container_name: container_name)
65
+ connection_state = @emulator_commander.check_connection
63
66
  container_state = connection_state && connection_state
64
67
  end
65
68
 
@@ -76,25 +79,25 @@ module Fastlane
76
79
  exit 2
77
80
  end
78
81
 
79
- if is_running_on_emulator && !EmulatorCommander.check_connection(container_name: container_name)
82
+ if is_running_on_emulator && !@emulator_commander.check_connection
80
83
  UI.important('Cannot connect to emulator. Exiting..')
81
84
  exit 2
82
85
  end
83
86
  end
84
87
 
85
88
  if is_running_on_emulator
86
- EmulatorCommander.disable_animations(container_name: container_name)
87
- EmulatorCommander.increase_logcat_storage(container_name: container_name)
89
+ @emulator_commander.disable_animations
90
+ @emulator_commander.increase_logcat_storage
88
91
  end
89
92
  end
90
93
 
91
94
  def kvm_disabled?
92
95
  begin
93
- DockerCommander.docker_exec(command: 'kvm-ok > kvm-ok.txt', container_name: container_name)
96
+ @docker_commander.exec(command: 'kvm-ok > kvm-ok.txt')
94
97
  rescue StandardError
95
98
  # kvm-ok will always throw regardless of the result. therefore we save the output in the file and ignore the error
96
99
  end
97
- DockerCommander.docker_exec(command: 'cat kvm-ok.txt', container_name: container_name).include?('KVM acceleration can NOT be used')
100
+ @docker_commander.exec(command: 'cat kvm-ok.txt').include?('KVM acceleration can NOT be used')
98
101
  end
99
102
 
100
103
  # Stops and remove container
@@ -124,15 +127,16 @@ module Fastlane
124
127
  print_cpu_load
125
128
  begin
126
129
  container = create_container_call
127
- @container_name = container unless container_name
130
+ set_container_name(container)
128
131
  rescue StandardError
129
132
  UI.important("Something went wrong while creating: #{container_name}, will retry in #{@sleep_interval} seconds")
130
133
  print_cpu_load
131
- DockerCommander.stop_container(container_name: container_name)
132
- DockerCommander.delete_container(container_name: container_name)
134
+ @docker_commander.stop_container
135
+ @docker_commander.delete_container
136
+
133
137
  sleep @sleep_interval
134
138
  container = create_container_call
135
- @container_name = container unless container_name
139
+ set_container_name(container)
136
140
  end
137
141
  get_container_instance(container)
138
142
  end
@@ -154,7 +158,7 @@ module Fastlane
154
158
 
155
159
  emulator_args = is_running_on_emulator ? "-p #{no_vnc_port}:6080 -e DEVICE='#{device_name}'" : ''
156
160
 
157
- DockerCommander.start_container(emulator_args: emulator_args, docker_name: container_name, docker_image: docker_image)
161
+ @docker_commander.start_container(emulator_args: emulator_args, docker_image: docker_image)
158
162
  end
159
163
 
160
164
  def execute_pre_action
@@ -165,7 +169,7 @@ module Fastlane
165
169
  def pull_from_registry
166
170
  docker_image_name = docker_image.gsub(':latest', '')
167
171
  Actions.sh(@docker_registry_login) if @docker_registry_login
168
- DockerCommander.pull_image(docker_image_name: docker_image_name)
172
+ @docker_commander.pull_image(docker_image_name: docker_image_name)
169
173
  end
170
174
 
171
175
  # Checks that chosen ports are not already allocated. If they are, it will stop the allocated container
@@ -179,8 +183,8 @@ module Fastlane
179
183
  if port_open?('0.0.0.0', @no_vnc_port)
180
184
  UI.important('Something went wrong. VNC port is still busy')
181
185
  sleep @sleep_interval
182
- DockerCommander.stop_container(container_name: container_name)
183
- DockerCommander.delete_container(container_name: container_name)
186
+ @docker_commander.stop_container
187
+ @docker_commander.delete_container
184
188
  end
185
189
  end
186
190
 
@@ -281,6 +285,13 @@ module Fastlane
281
285
  raise "CPU was overloaded. Couldn't start emulator"
282
286
  end
283
287
 
288
+ # if we do not have container name, we cane use container ID that we got from create call
289
+ def set_container_name(container)
290
+ unless container_name
291
+ @container_name = @emulator_commander.container_name = @docker_commander.container_name = container
292
+ end
293
+ end
294
+
284
295
  end
285
296
  end
286
297
  end
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module Mango
3
- VERSION = '1.1.0'.freeze
3
+ VERSION = '1.1.1'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-mango
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Serghei Moret, Daniel Hartwich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-28 00:00:00.000000000 Z
11
+ date: 2018-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docker-api