fastlane-plugin-automated_test_emulator_run 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 27d7e221e465ab83b1e9991ca29fcd58c8e27f9c
4
+ data.tar.gz: 697384557f846ccd443ee9532c016a75cf34878a
5
+ SHA512:
6
+ metadata.gz: c4faef2ed69687f843726f91b83d617d10ace7e931549a95e6f23d9f9029d864883cb2386f75ce49c303f63634eea284d5f336bfac5a54b101073bbd3ad8b583
7
+ data.tar.gz: 50b66be6a3383eb8344b0af1b56059c786d7ee6f4801c7de25054220118c43f48f994284cdfdadd7932460ad5513e3ef9b50329b064122df2def431122c59561
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Kamil Krzyk <krzyk.kamil@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,52 @@
1
+ # automated_test_emulator_run plugin
2
+
3
+ [![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-automated_test_emulator_run)
4
+
5
+ ## Getting Started
6
+
7
+ This project is a [fastlane](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-automated_test_emulator_run`, add it to your project by running:
8
+
9
+ ```bash
10
+ fastlane add_plugin automated_test_emulator_run
11
+ ```
12
+
13
+ ## About automated_test_emulator_run
14
+
15
+ Allows to wrap gradle task or shell command that runs integrated tests that prepare and starts single AVD before test run. After tests are finished, emulator is killed and deleted.
16
+
17
+ **Note to author:** Add a more detailed description about this plugin here. If your plugin contains multiple actions, make sure to mention them here.
18
+
19
+ ## Example
20
+
21
+ Check out the [example `Fastfile`](fastlane/Fastfile) to see how to use this plugin. Try it by cloning the repo, running `fastlane install_plugins` and `bundle exec fastlane test`.
22
+
23
+ **Note to author:** Please set up a sample project to make it easy for users to explore what your plugin does. Provide everything that is necessary to try out the plugin in this project (including a sample Xcode/Android project if necessary)
24
+
25
+ ## Run tests for this plugin
26
+
27
+ To run both the tests, and code style validation, run
28
+
29
+ ```
30
+ rake
31
+ ```
32
+
33
+ To automatically fix many of the styling issues, use
34
+ ```
35
+ rubocop -a
36
+ ```
37
+
38
+ ## Issues and Feedback
39
+
40
+ For any other issues and feedback about this plugin, please submit it to this repository.
41
+
42
+ ## Troubleshooting
43
+
44
+ If you have trouble using plugins, check out the [Plugins Troubleshooting](https://github.com/fastlane/fastlane/blob/master/fastlane/docs/PluginsTroubleshooting.md) doc in the main `fastlane` repo.
45
+
46
+ ## Using `fastlane` Plugins
47
+
48
+ For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Plugins.md).
49
+
50
+ ## About `fastlane`
51
+
52
+ `fastlane` is the easiest way to automate building and releasing your iOS and Android apps. To learn more, check out [fastlane.tools](https://fastlane.tools).
@@ -0,0 +1,16 @@
1
+ require 'fastlane/plugin/automated_test_emulator_run/version'
2
+
3
+ module Fastlane
4
+ module AutomatedTestEmulatorRun
5
+ # Return all .rb files inside the "actions" and "helper" directory
6
+ def self.all_classes
7
+ Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))]
8
+ end
9
+ end
10
+ end
11
+
12
+ # By default we want to import all available actions and helpers
13
+ # A plugin can contain any number of actions and plugins
14
+ Fastlane::AutomatedTestEmulatorRun.all_classes.each do |current|
15
+ require current
16
+ end
@@ -0,0 +1,206 @@
1
+ require 'open3'
2
+ require 'tempfile'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ module SharedValues
7
+ end
8
+
9
+ class AutomatedTestEmulatorRunAction < Action
10
+ def self.run(params)
11
+ gradle = Helper::GradleHelper.new(gradle_path: Dir["./gradlew"].last)
12
+
13
+ Action.sh("clear")
14
+
15
+ UI.message("The automated_test_emulator_run plugin is working!")
16
+
17
+ # Create output file
18
+ file = Tempfile.new('emulator_output')
19
+ UI.message(["Created temp file for emulator output", file.path].join(" ").yellow)
20
+
21
+ # Find unused port
22
+ port = getUnusedTcpPort
23
+ UI.message(["Open port found", port].join(" ").yellow)
24
+
25
+ # Set up params
26
+ UI.message("Preparing parameters...".yellow)
27
+ avd_name = "--name \"#{params[:avd_name]}\""
28
+ target_id = "--target \"#{params[:target_id]}\""
29
+ avd_abi = "--abi #{params[:avd_abi]}" unless params[:avd_abi].nil?
30
+ avd_tag = "--tag #{params[:avd_tag]}" unless params[:avd_tag].nil?
31
+ avd_create_options = params[:avd_create_options] unless params[:avd_create_options].nil?
32
+ avd_initdata = "-wipe-data -initdata #{params[:initdata_snapshot_path]}" unless params[:initdata_snapshot_path].nil?
33
+ avd_port = ["-port", port].join(" ")
34
+ sdkRoot = getSdkRoot(params)
35
+
36
+ # Set up commands
37
+ UI.message("Setting up run commands".yellow)
38
+ create_avd_command = [sdkRoot + "/tools/android", "create avd", avd_name, target_id, avd_abi, avd_tag, avd_create_options].join(" ")
39
+ get_devices_command = sdkRoot + "/tools/android list avd".chomp
40
+ start_avd_command = [sdkRoot + "/tools/emulator", avd_port, "-avd #{params[:avd_name]}", avd_initdata, "-gpu on -no-boot-anim &>#{file.path} &"].join(" ")
41
+ shell_command = "#{params[:shell_command]}" unless params[:shell_command].nil?
42
+ gradle_task = "#{params[:gradle_task]}" unless params[:gradle_task].nil?
43
+
44
+ # Get Available Devices
45
+ UI.message("Getting avaliable devices".yellow)
46
+ devices = Action.sh(get_devices_command)
47
+
48
+ # Delete avd if one already exists for clean state.
49
+ unless devices.match(/#{params[:avd_name]}/).nil?
50
+ UI.message("Deleting existing AVD to create fresh one".yellow)
51
+ Action.sh(sdkRoot + "/tools/android delete avd -n #{params[:avd_name]}")
52
+ end
53
+
54
+ # Creating AVD
55
+ UI.message("Creating AVD...".yellow)
56
+ Action.sh(create_avd_command)
57
+
58
+ # Starting AVD
59
+ UI.message("Starting AVD....".yellow)
60
+ begin
61
+ Action.sh(start_avd_command)
62
+ waitFor_emulatorBoot(sdkRoot, port)
63
+
64
+ UI.message("Starting tests".green)
65
+ begin
66
+ unless shell_command.nil?
67
+ UI.message("Using shell command".green)
68
+ Action.sh(shell_command)
69
+ end
70
+
71
+ unless gradle_task.nil?
72
+ UI.message("Using gradle task".green)
73
+ gradle.trigger(task: params[:gradle_task], flags: params[:gradle_flags], serial: nil)
74
+ end
75
+ ensure
76
+ waitFor_emulatorStop(sdkRoot, port, params, file)
77
+ end
78
+ ensure
79
+ file.close
80
+ file.unlink
81
+ end
82
+ end
83
+
84
+ def self.getUnusedTcpPort
85
+ min_port = 5556
86
+ max_port = 5586
87
+
88
+ port = min_port
89
+ while port < max_port do
90
+ unless system(["lsof -i:", port].join(""), out: '/dev/null')
91
+ break
92
+ end
93
+ port +=1
94
+ end
95
+ return port
96
+ end
97
+
98
+ def self.getSdkRoot(params)
99
+ dirs = "#{params[:sdk_path]}".split(':')
100
+ sdkRoot = ""
101
+ dirs.each do |dir|
102
+ if dir.include? "sdk"
103
+ sdkEndPos = dir.index("sdk") + "sdk".length
104
+ sdkRoot = dir.slice(0, sdkEndPos)
105
+ break
106
+ end
107
+ end
108
+ return sdkRoot
109
+ end
110
+
111
+ def self.waitFor_emulatorBoot(sdkRoot, port)
112
+ UI.message("Waiting for emulator to finish booting.....".yellow)
113
+ loop do
114
+ stdout, _stdeerr, _status = Open3.capture3(sdkRoot + ["/platform-tools/adb -s emulator-", port].join("") + " shell getprop sys.boot_completed")
115
+
116
+ if stdout.strip == "1"
117
+ break
118
+ end
119
+ end
120
+ UI.message("Emulator Booted!".green)
121
+ end
122
+
123
+ def self.waitFor_emulatorStop(sdkRoot, port, params, file)
124
+ adb = Helper::AdbHelper.new(adb_path: sdkRoot + "/platform-tools/adb")
125
+ temp = File.open(file.path).read
126
+
127
+ UI.message("Shutting down emulator...".green)
128
+ adb.trigger(command: "emu kill", serial: "emulator-#{port}")
129
+
130
+ UI.message("Deleting emulator....".green)
131
+ Action.sh(sdkRoot + "/tools/android delete avd -n #{params[:avd_name]}")
132
+ end
133
+
134
+ def self.available_options
135
+ [
136
+ FastlaneCore::ConfigItem.new(key: :avd_name,
137
+ env_name: "AVD_NAME",
138
+ description: "Name of the avd to be created",
139
+ is_string: true,
140
+ optional: false),
141
+ FastlaneCore::ConfigItem.new(key: :target_id,
142
+ env_name: "TARGET_ID",
143
+ description: "Target id of the avd to be created, get list of installed target by running command 'android list targets'",
144
+ is_string: true,
145
+ optional: false),
146
+ FastlaneCore::ConfigItem.new(key: :avd_create_options,
147
+ env_name: "AVD_CREATE_OPTIONS",
148
+ description: "Other avd options, used during avd creation, in the form of a <option>=<value> list, i.e \"--scale 96dpi --dpi-device 160\"",
149
+ is_string: true,
150
+ optional: true),
151
+ FastlaneCore::ConfigItem.new(key: :avd_abi,
152
+ env_name: "AVD_ABI",
153
+ description: "The ABI to use for the AVD. The default is to auto-select the ABI if the platform has only one ABI for its system images",
154
+ is_string: true,
155
+ optional: true),
156
+ FastlaneCore::ConfigItem.new(key: :avd_tag,
157
+ env_name: "AVD_TAG",
158
+ description: "The sys-img tag to use for the AVD. The default is to auto-select if the platform has only one tag for its system images",
159
+ is_string: true,
160
+ optional: true),
161
+ FastlaneCore::ConfigItem.new(key: :initdata_snapshot_path,
162
+ env_name: "INIT_DATA_PATH",
163
+ description: "The path to userdata-qemu which will be used to initialize AVD status",
164
+ is_string: true,
165
+ optional: true),
166
+ FastlaneCore::ConfigItem.new(key: :sdk_path,
167
+ env_name: "SDK_PATH",
168
+ description: "The path to your android sdk directory (root)",
169
+ is_string: true,
170
+ default_value: ENV['PATH'],
171
+ optional: true),
172
+ FastlaneCore::ConfigItem.new(key: :shell_command,
173
+ env_name: "SHELL_COMMAND",
174
+ description: "The shell command you want to execute",
175
+ is_string: true,
176
+ conflicting_options: [:gradle_task],
177
+ optional: true),
178
+ FastlaneCore::ConfigItem.new(key: :gradle_task,
179
+ env_name: "GRADLE_TASK",
180
+ description: "The gradle task you want to execute",
181
+ is_string: true,
182
+ conflicting_options: [:shell_command],
183
+ optional: true),
184
+ FastlaneCore::ConfigItem.new(key: :gradle_flags,
185
+ env_name: "GRADLE_FLAGS",
186
+ description: "All parameter flags you want to pass to the gradle command, e.g. `--exitcode --xml file.xml`",
187
+ optional: true,
188
+ conflicting_options: [:shell_command],
189
+ is_string: true),
190
+ ]
191
+ end
192
+
193
+ def self.description
194
+ "Starts single emulator before running tests."
195
+ end
196
+
197
+ def self.authors
198
+ ["joshrlesch, modified by F1sherKK"]
199
+ end
200
+
201
+ def self.is_supported?(platform)
202
+ platform == :android
203
+ end
204
+ end
205
+ end
206
+ end
@@ -0,0 +1,12 @@
1
+ module Fastlane
2
+ module Helper
3
+ class AutomatedTestEmulatorRunHelper
4
+ # class methods that you define here become available in your action
5
+ # as `Helper::AutomatedTestEmulatorRunHelper.your_method`
6
+ #
7
+ def self.show_message
8
+ UI.message("Hello from the automated_test_emulator_run plugin helper!")
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ module Fastlane
2
+ module AutomatedTestEmulatorRun
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fastlane-plugin-automated_test_emulator_run
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kamil Krzyk
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: fastlane
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 1.98.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 1.98.0
97
+ description:
98
+ email: krzyk.kamil@gmail.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - LICENSE
104
+ - README.md
105
+ - lib/fastlane/plugin/automated_test_emulator_run.rb
106
+ - lib/fastlane/plugin/automated_test_emulator_run/actions/automated_test_emulator_run_action.rb
107
+ - lib/fastlane/plugin/automated_test_emulator_run/helper/automated_test_emulator_run_helper.rb
108
+ - lib/fastlane/plugin/automated_test_emulator_run/version.rb
109
+ homepage:
110
+ licenses:
111
+ - MIT
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.5.1
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Allows to wrap gradle task or shell command that runs integrated tests that
133
+ prepare and starts single AVD before test run. After tests are finished, emulator
134
+ is killed and deleted.
135
+ test_files: []