fastlane-plugin-mango 1.3.15 → 1.3.34

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: 789e89cc42d904d6f20d595d4e4e5e536688431cef29839e784e6fbe8dfd7e13
4
- data.tar.gz: e4143d7a96c169910ec836972f4362b0244828f1899a7837b33911b62f31e7f3
3
+ metadata.gz: b7858bdb16a89774de4d49284cb900ec6bfd0b226d42765303a60a1daedc425f
4
+ data.tar.gz: 3dbfefd9bbf1edd815a7ad68ac260415d34c07adc2665d7027bb06833b8fb033
5
5
  SHA512:
6
- metadata.gz: '0243850ec81a9f5108d5c6ca0a46770238fced448407bdb0c6abacb734bc7804bedc58880275187908cf2a7993a52c635d84749d155d62265e8401788b53dcd4'
7
- data.tar.gz: f0dc414874f535ac73ba139fe5476516bc340d5b66b78fd162b6760ca4f783e4911d18ee4d36bec31032431869d093e6e364756ad7c216e6685bd91ae7846c61
6
+ metadata.gz: b60056f85329209a5cced72bd0181e023f4e12f1e8d1d058a8456deb956d6ee98a02af9d5eda0891c2d8f62c2ae6d0af8183f39b7c96cab20f78d8071a8a4e99
7
+ data.tar.gz: ac31d9b3f06da7fa85c100cd8838cb0925730e1135effc8801722ccfb4e7c98dc2651014fa0e40f7b3d15dec13f25ecb0f4ae91781070f3b10a3f0c64fa0f953
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-mango) [![License](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://github.com/xing/mango/blob/master/LICENSE)
5
5
  [![Gem](https://img.shields.io/gem/v/fastlane-plugin-mango.svg?style=flat)](http://rubygems.org/gems/fastlane-plugin-mango)
6
6
 
7
- A fastlane plugin that runs Android tasks on a specified [Docker](https://www.docker.com/) image
7
+ A fastlane plugin that runs Android tasks on a specified [Docker](https://www.docker.com/) image. Can be used for orchestrating android tasks on a CI syste.
8
8
 
9
9
  <img src="assets/mango_logo.png" alt="Mango Logo" width="256px" height="256px"/>
10
10
 
@@ -47,19 +47,26 @@ desc "Run espresso tests on docker images"
47
47
  end
48
48
  ```
49
49
 
50
- or to this for unit tests or other gradle tasks:
50
+ or to this for unit tests or other gradle tasks(some of the variables are optional):
51
51
  ```ruby
52
52
  desc "Run unit tests on docker images"
53
- lane :Unit_Tests do
54
- run_dockerized_task(
55
- container_name: "unit_tests_container",
56
- port_factor: options[:port_factor],
57
- docker_image: "joesss/mango-base:latest",
58
- is_running_on_emulator: false,
59
- android_task: "./gradlew testDebug",
60
- pull_latest_image: true
61
- )
62
- end
53
+ lane :example do
54
+ run_dockerized_task(
55
+ container_name: "emulator_#{options[:port_factor]}",
56
+ port_factor: options[:port_factor],
57
+ docker_image: 'joesss/mango-base:latest',
58
+ android_task: './gradlew testDebug',
59
+ post_actions: 'adb logcat -d > logcat.txt',
60
+ bundle_install: true,
61
+ core_amount: '8',
62
+ workspace_dir: '/root/tests/espresso-tests',
63
+ docker_registry_login: "docker login -u='USER' -p='PASS' some.docker.com",
64
+ pull_latest_image: true,
65
+ pre_action: 'echo $GIT_BRANCH > /root/.branch',
66
+ vnc_enabled: false,
67
+ environment_variables: options[:environment_variables] ? options[:environment_variables].split(' ') : ''
68
+ )
69
+ end
63
70
  ```
64
71
 
65
72
  Now you can call this new lane by calling `bundle exec fastlane Espresso_Tests`.
@@ -11,6 +11,7 @@ module Fastlane
11
11
  mango_helper.setup_container
12
12
 
13
13
  docker_commander = Helper::DockerCommander.new(mango_helper.container_name)
14
+ Helper::EmulatorLanguage.set(params[:emulator_language], docker_commander) if params[:emulator_language]
14
15
 
15
16
  failure_buffer_timeout = 5
16
17
  timeout_command = "timeout #{params[:maximal_run_time] - failure_buffer_timeout}m"
@@ -22,10 +23,23 @@ module Fastlane
22
23
 
23
24
  docker_commander.exec(command: "cd #{workspace_dir} #{bundle_install}&& #{timeout_command} #{android_task} || exit 1")
24
25
  end
26
+ rescue StandardError => e
27
+ begin
28
+ Actions.sh("docker logs #{mango_helper.container_name} --tail 200")
29
+ rescue StandardError
30
+ # do nothing
31
+ end
32
+ docker_commander.exec(command:
33
+ 'cat /var/log/supervisor/docker-android.stderr.log', raise_when_fail: false)
34
+ docker_commander.exec(command: 'cat /var/log/supervisor/supervisord.log',
35
+ raise_when_fail: false)
36
+ raise e
25
37
  ensure
26
38
  begin
27
39
  post_actions = params[:post_actions]
28
- docker_commander&.exec(command: "cd #{workspace_dir} && #{post_actions}") if post_actions && !mango_helper.kvm_disabled?
40
+ if post_actions && !mango_helper.kvm_disabled?
41
+ docker_commander&.exec(command: "cd #{workspace_dir} && #{post_actions}")
42
+ end
29
43
 
30
44
  UI.important("Cleaning up #{params[:emulator_name]} container")
31
45
  docker_commander.delete_container if mango_helper&.instance_variable_get('@container')
@@ -189,6 +203,12 @@ module Fastlane
189
203
  description: 'A bool. True for vnc_enabled False for vnc_disabled',
190
204
  type: Boolean,
191
205
  default_value: true,
206
+ optional: true),
207
+
208
+ FastlaneCore::ConfigItem.new(key: :emulator_language,
209
+ env_name: 'EMULATOR_LANGUAGE',
210
+ description: 'A string that identify a device locale (e.g. de_DE)',
211
+ type: String,
192
212
  optional: true)
193
213
  ]
194
214
  end
@@ -25,6 +25,7 @@ module Fastlane
25
25
  30.times do
26
26
  load = cpu_load
27
27
  return true if load <= cpu_core_amount.to_i * 1.5
28
+
28
29
  print_cpu_load(load)
29
30
  UI.important('Waiting for available resources..')
30
31
  sleep 60
@@ -11,8 +11,8 @@ module Fastlane
11
11
 
12
12
  def pull_image(docker_image_name:)
13
13
  Actions.sh("docker pull #{docker_image_name}")
14
- rescue StandardError => exception
15
- prune if exception.message =~ /Create more free space in thin pool/
14
+ rescue StandardError => e
15
+ prune if e.message =~ /Create more free space in thin pool/
16
16
  Actions.sh("docker pull #{docker_image_name}")
17
17
  end
18
18
 
@@ -34,8 +34,8 @@ module Fastlane
34
34
  # interested in the last line, since it contains the id of the created container.
35
35
  UI.important("Attaching #{ENV['PWD']} to the docker container")
36
36
  Actions.sh("docker run -v $PWD:/root/tests --privileged -t -d #{core_amount} #{emulator_args} #{docker_name} #{docker_image}").chomp
37
- rescue StandardError => exception
38
- if exception.message =~ /Create more free space in thin pool/ && (retries += 1) < 2
37
+ rescue StandardError => e
38
+ if e.message =~ /Create more free space in thin pool/ && (retries += 1) < 2
39
39
  prune
40
40
  retry
41
41
  end
@@ -43,6 +43,10 @@ module Fastlane
43
43
 
44
44
  def delete_container
45
45
  Actions.sh("docker rm -f #{container_name}") if container_name
46
+ rescue StandardError
47
+ sleep 5
48
+ UI.important('Was not able to delete the container after the first attempt, trying again')
49
+ retry
46
50
  end
47
51
 
48
52
  def disconnect_network_bridge
@@ -52,14 +56,22 @@ module Fastlane
52
56
  # Do nothing if the network bridge is already gone
53
57
  end
54
58
 
55
- def exec(command:)
59
+ def exec(command:, raise_when_fail: true)
56
60
  if container_name
57
- Actions.sh("docker exec -i #{container_name} bash -l -c \"#{command}\"")
61
+ begin
62
+ Actions.sh("docker exec #{container_name} bash -l -c \"#{command}\"")
63
+ rescue StandardError => e
64
+ raise(e) if raise_when_fail
65
+ end
58
66
  else
59
67
  raise('Cannot execute docker command because the container name is unknown')
60
68
  end
61
69
  end
62
70
 
71
+ def cp(file:)
72
+ Actions.sh("docker cp #{file} #{container_name}:/root/tests/.")
73
+ end
74
+
63
75
  def prune
64
76
  Action.sh('docker system prune -f')
65
77
  end
@@ -0,0 +1,25 @@
1
+ module Fastlane
2
+ module Helper
3
+ module EmulatorLanguage
4
+ def self.set(lang, docker_commander)
5
+ UI.important("Changing device locale to #{lang}")
6
+
7
+ retries ||= 5
8
+ language = lang.split('_')[0]
9
+ country = lang.split('_')[1]
10
+ apk_path = File.join(File.dirname(__FILE__), 'settings.apk')
11
+ docker_commander.cp(file: apk_path)
12
+ docker_commander.exec(command: 'adb install /root/tests/settings.apk')
13
+ docker_commander.exec(command: 'adb shell pm grant io.appium.settings android.permission.CHANGE_CONFIGURATION')
14
+ docker_commander.exec(command: "adb shell am broadcast -a io.appium.settings.locale -n io.appium.settings/.receivers.LocaleSettingReceiver --es lang #{language} --es country #{country}")
15
+ rescue StandardError => e
16
+ raise e if retries.zero?
17
+
18
+ puts "Got an exception: #{e.message}. Will retry in 5 seconds"
19
+ retries -= 1
20
+ sleep 5
21
+ retry
22
+ end
23
+ end
24
+ end
25
+ end
@@ -6,7 +6,8 @@ require_relative 'cpu_load_handler'
6
6
  module Fastlane
7
7
  module Helper
8
8
  class MangoHelper
9
- attr_reader :container_name, :no_vnc_port, :device_name, :docker_image, :timeout, :port_factor, :maximal_run_time, :sleep_interval, :is_running_on_emulator, :environment_variables, :vnc_enabled, :core_amount
9
+ attr_reader :container_name, :no_vnc_port, :device_name, :docker_image, :timeout, :port_factor,
10
+ :maximal_run_time, :sleep_interval, :is_running_on_emulator, :environment_variables, :vnc_enabled, :core_amount
10
11
 
11
12
  def initialize(params)
12
13
  @container_name = params[:container_name]
@@ -162,7 +163,8 @@ module Fastlane
162
163
  end
163
164
  emulator_args = is_running_on_emulator ? "-p #{no_vnc_port}:6080 -e DEVICE='#{device_name}'" : ''
164
165
  emulator_args = "#{emulator_args}#{additional_env}"
165
- @docker_commander.start_container(emulator_args: emulator_args, docker_image: docker_image, core_amount: core_amount)
166
+ @docker_commander.start_container(emulator_args: emulator_args, docker_image: docker_image,
167
+ core_amount: core_amount)
166
168
  end
167
169
 
168
170
  def execute_pre_action
@@ -204,6 +206,7 @@ module Fastlane
204
206
  # Checks if container is already available
205
207
  def container_available?
206
208
  return false unless container_name
209
+
207
210
  all_containers = Docker::Container.all(all: true)
208
211
 
209
212
  all_containers.each do |container|
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module Mango
3
- VERSION = '1.3.15'.freeze
3
+ VERSION = '1.3.34'.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.3.15
4
+ version: 1.3.34
5
5
  platform: ruby
6
6
  authors:
7
7
  - Serghei Moret, Daniel Hartwich
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-04 00:00:00.000000000 Z
11
+ date: 2021-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docker-api
@@ -112,16 +112,16 @@ dependencies:
112
112
  name: rubocop
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - '='
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: 0.58.2
117
+ version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - '='
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
- version: 0.58.2
124
+ version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: simplecov
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -136,7 +136,7 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
- description:
139
+ description:
140
140
  email: serghei.moret@xing.com, hartwich.daniel@gmail.com
141
141
  executables: []
142
142
  extensions: []
@@ -149,13 +149,15 @@ files:
149
149
  - lib/fastlane/plugin/mango/helper/cpu_load_handler.rb
150
150
  - lib/fastlane/plugin/mango/helper/docker_commander.rb
151
151
  - lib/fastlane/plugin/mango/helper/emulator_commander.rb
152
+ - lib/fastlane/plugin/mango/helper/emulator_language.rb
152
153
  - lib/fastlane/plugin/mango/helper/mango_helper.rb
154
+ - lib/fastlane/plugin/mango/helper/settings.apk
153
155
  - lib/fastlane/plugin/mango/version.rb
154
156
  homepage: https://github.com/xing/mango
155
157
  licenses:
156
158
  - MIT
157
159
  metadata: {}
158
- post_install_message:
160
+ post_install_message:
159
161
  rdoc_options: []
160
162
  require_paths:
161
163
  - lib
@@ -170,8 +172,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
172
  - !ruby/object:Gem::Version
171
173
  version: '0'
172
174
  requirements: []
173
- rubygems_version: 3.0.6
174
- signing_key:
175
+ rubygems_version: 3.1.4
176
+ signing_key:
175
177
  specification_version: 4
176
- summary: This plugin Android tasks on docker images
178
+ summary: This plugin orchtestrates Android tasks on docker images
177
179
  test_files: []