fastlane-plugin-yafirim 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fda73aab4128a00f79116d4f5f3269e2a2e78e0b
4
+ data.tar.gz: 473554247382c24b750fa13970bdae17d52bb0b7
5
+ SHA512:
6
+ metadata.gz: 220026cf80ef59a2e2b74f66ec8788fb3eceb60b5e67b4cc643257adfd7b5f6a8394939b7169665d7950c68b990befb1af83e3221a8621676761f0c53a7b37b5
7
+ data.tar.gz: 3aeeca366001d9f0d3bbe588e4ec58586e866165170020141efb7f69a197f4f2dc13f409e3c53c78bc7e22c6d26e6e5b14628a22efa926667f93bd7059d8b928
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 wd <wd@wdicc.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.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # yafirim plugin
2
+
3
+ [![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-yafirim)
4
+
5
+ ## Getting Started
6
+
7
+ This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-yafirim`, add it to your project by running:
8
+
9
+ ```bash
10
+ fastlane add_plugin yafirim
11
+ ```
12
+
13
+ ## About yafirim
14
+
15
+ Yet another fastlane fir.im plugin
16
+
17
+ This plugin is in it's very beta stage now, DO NOT USE IN PRODUCTION.
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
+ ## Run tests for this plugin
24
+
25
+ To run both the tests, and code style validation, run
26
+
27
+ ```
28
+ rake
29
+ ```
30
+
31
+ To automatically fix many of the styling issues, use
32
+ ```
33
+ rubocop -a
34
+ ```
35
+
36
+ ## Issues and Feedback
37
+
38
+ For any other issues and feedback about this plugin, please submit it to this repository.
39
+
40
+ ## Troubleshooting
41
+
42
+ If you have trouble using plugins, check out the [Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/) guide.
43
+
44
+ ## Using _fastlane_ Plugins
45
+
46
+ For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/).
47
+
48
+ ## About _fastlane_
49
+
50
+ _fastlane_ is the easiest way to automate beta deployments and releases for your iOS and Android apps. To learn more, check out [fastlane.tools](https://fastlane.tools).
@@ -0,0 +1,254 @@
1
+ require 'faraday' # HTTP Client
2
+
3
+ module Fastlane
4
+ module Actions
5
+ class YafirimAction < Action
6
+ @token_url = 'http://api.fir.im/apps'
7
+ @app_info = {}
8
+
9
+ def self.run(params)
10
+ UI.message("Yafirim Begin process")
11
+ @options = params
12
+ if @options[:ipa]
13
+ @platform = 'ios'
14
+ Yafirim::DetectIosValues.new.run!(@options)
15
+ @options[:file] = @options[:ipa]
16
+ else
17
+ @platform = 'android'
18
+ Yafirim::DetectAndroidValues.new.run!(@options)
19
+ @options[:file] = @options[:apk_path] + @options[:name] + "_" + @options[:version] + "_" + @options[:build_version] + "_" + @options[:build_type] + ".apk"
20
+ end
21
+
22
+ UI.user_error!("Error, file #{@options[:file]} not exists.") unless File.exist?(@options[:file])
23
+ FastlaneCore::PrintTable.print_values(config: @options)
24
+
25
+ binary_info = self.get_upload_token
26
+
27
+ begin
28
+ self.upload_binary binary_info
29
+ rescue Exception => e
30
+ raise e
31
+ end
32
+ end
33
+
34
+ def self.validation_response response_data
35
+ error_code = response_data['code'].to_i rescue 0
36
+ if error_code == 100020
37
+ UI.user_error!("Firim API Token(#{@options[:api_token]}) not correct")
38
+ end
39
+ end
40
+
41
+ def self.get_upload_token
42
+ firim_client = Faraday.new(@token_url,
43
+ {
44
+ request: {
45
+ timeout: 300,
46
+ open_timeout: 300
47
+ }
48
+ }
49
+ ) do |c|
50
+ c.request :url_encoded # form-encode POST params
51
+ c.adapter :net_http
52
+ c.response :json, :content_type => /\bjson$/
53
+ end
54
+
55
+ response = firim_client.post do |req|
56
+ req.url @token_url
57
+ req.body = { :type => @platform, :bundle_id => @options[:bundle_id], :api_token => @options[:api_token] }
58
+ end
59
+
60
+ info = response.body
61
+ self.validation_response info
62
+
63
+ UI.message(info)
64
+ UI.message(info['cert']['binary'])
65
+ return info['cert']['binary']
66
+ end
67
+
68
+ def self.upload_binary binary_info
69
+ params = {
70
+ 'key' => binary_info['key'],
71
+ 'token' => binary_info['token'],
72
+ 'file' => Faraday::UploadIO.new(@options[:file], 'application/octet-stream'),
73
+ 'x:name' => @options[:name],
74
+ 'x:version' => @options[:version],
75
+ 'x:build' => @options[:build_version]
76
+ }
77
+
78
+ UI.message "Start upload #{@options[:name]} binary..."
79
+
80
+ firim_client = Faraday.new(nil,
81
+ {
82
+ request: {
83
+ timeout: 1000,
84
+ open_timeout: 300
85
+ }
86
+ }
87
+ ) do |c|
88
+ c.request :multipart
89
+ c.request :url_encoded
90
+ c.response :json, content_type: /\bjson$/
91
+ c.adapter :net_http
92
+ end
93
+
94
+ response = firim_client.post binary_info['upload_url'], params
95
+ unless response.body['is_completed']
96
+ raise UI.user_error!("Upload binary to Qiniu error #{response.body}")
97
+ end
98
+ UI.success 'Upload binary successed!'
99
+ end
100
+
101
+ def self.description
102
+ "Yet another fastlane fir.im plugin"
103
+ end
104
+
105
+ def self.authors
106
+ ["wd"]
107
+ end
108
+
109
+ def self.return_value
110
+ # If your method provides a return value, you can describe here what it does
111
+ end
112
+
113
+ def self.details
114
+ # Optional:
115
+ "A fastlane plugin to help you upload your ipa/apk to fir.im"
116
+ end
117
+
118
+ def self.available_options
119
+ [
120
+ FastlaneCore::ConfigItem.new(key: :api_token,
121
+ short_option: "-a",
122
+ optional: true,
123
+ description: "fir.im user api token"),
124
+
125
+ # Content path
126
+ FastlaneCore::ConfigItem.new(key: :ipa,
127
+ short_option: "-i",
128
+ optional: true,
129
+ description: "Path to your ipa file",
130
+ default_value: Dir["*.ipa"].first,
131
+ verify_block: proc do |value|
132
+ UI.user_error!("Could not find ipa file at path '#{value}'") unless File.exist?(value)
133
+ UI.user_error!("'#{value}' doesn't seem to be an ipa file") unless value.end_with?(".ipa")
134
+ end,
135
+ conflicting_options: [:apk_path],
136
+ conflict_block: proc do |value|
137
+ UI.user_error!("You can't use 'ipa' and '#{value.key}' options in one run.")
138
+ end),
139
+
140
+ FastlaneCore::ConfigItem.new(key: :apk_path,
141
+ short_option: "-p",
142
+ optional: true,
143
+ description: "Path to your apk file",
144
+ default_value: "./app/build/outputs/apk/",
145
+ verify_block: proc do |value|
146
+ UI.user_error!("Directory '#{value}' not exists.") unless Dir.exist?(value)
147
+ end,
148
+ conflicting_options: [:ipa],
149
+ conflict_block: proc do |value|
150
+ UI.user_error!("You can't use 'apk_path' and '#{value.key}' options in one run.")
151
+ end),
152
+
153
+ FastlaneCore::ConfigItem.new(key: :file,
154
+ description: "file",
155
+ optional: true),
156
+
157
+ FastlaneCore::ConfigItem.new(key: :bundle_id,
158
+ description: "bundle id",
159
+ optional: true),
160
+ FastlaneCore::ConfigItem.new(key: :name,
161
+ description: "app name",
162
+ optional: true),
163
+ FastlaneCore::ConfigItem.new(key: :version,
164
+ description: "app version",
165
+ optional: true),
166
+ FastlaneCore::ConfigItem.new(key: :build_version,
167
+ description: "app build version number",
168
+ optional: true),
169
+ FastlaneCore::ConfigItem.new(key: :build_type,
170
+ description: "app build type",
171
+ optional: true),
172
+ ]
173
+ end
174
+
175
+ def self.is_supported?(platform)
176
+ # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
177
+ # See: https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Platforms.md
178
+ #
179
+ [:ios, :android].include?(platform)
180
+ end
181
+ end
182
+ end
183
+
184
+
185
+ module Yafirim
186
+ class DetectIosValues
187
+ def run!(options)
188
+ find_app_identifier(options)
189
+ find_app_name(options)
190
+ find_version(options)
191
+ find_build_version(options)
192
+ end
193
+
194
+ def find_app_identifier(options)
195
+ identifier = FastlaneCore::IpaFileAnalyser.fetch_app_identifier(options[:ipa])
196
+ if identifier.to_s.length != 0
197
+ options[:bundle_id] = identifier
198
+ else
199
+ UI.user_error!("Could not find ipa with app identifier '#{options[:app_identifier]}' in your iTunes Connect account (#{options[:username]} - Team: #{Spaceship::Tunes.client.team_id})")
200
+ end
201
+ end
202
+
203
+ def find_app_name(options)
204
+ return if options[:name]
205
+ plist = FastlaneCore::IpaFileAnalyser.fetch_info_plist_file(options[:ipa])
206
+ options[:name] ||= plist['CFBundleDisplayName']
207
+ options[:name] ||= plist['CFBundleName']
208
+ end
209
+
210
+ def find_version(options)
211
+ options[:version] ||= FastlaneCore::IpaFileAnalyser.fetch_app_version(options[:ipa])
212
+ end
213
+
214
+ def find_build_version(options)
215
+ plist = FastlaneCore::IpaFileAnalyser.fetch_info_plist_file(options[:ipa])
216
+ options[:build_version] = plist['CFBundleVersion']
217
+ end
218
+ end
219
+
220
+ class DetectAndroidValues
221
+ def run!(options)
222
+ find_app_identifier(options)
223
+ find_app_name(options)
224
+ find_version(options)
225
+ find_build_version(options)
226
+ end
227
+
228
+ def find_app_identifier(options)
229
+ return if options[:bundle_id]
230
+ out = `grep 'applicationId' app/build.gradle | awk -F '"' '{print $2}'`
231
+ options[:bundle_id] = out.chomp
232
+ end
233
+
234
+ def find_app_name(options)
235
+ return if options[:name]
236
+ out = `grep 'def appName' app/build.gradle | awk -F '"' '{print $2}'`
237
+ options[:name] = out.chomp
238
+ end
239
+
240
+ def find_version(options)
241
+ return if options[:version]
242
+ out = `grep ' versionName "' app/build.gradle | awk -F '"' '{print $2}'`
243
+ options[:version] = out.chomp
244
+ end
245
+
246
+ def find_build_version(options)
247
+ return if options[:build_version]
248
+ out = `grep ' versionCode ' app/build.gradle | awk -F ' *' '{print $3}'`
249
+ options[:build_version] = out.chomp
250
+ end
251
+ end
252
+
253
+ end
254
+ end
@@ -0,0 +1,12 @@
1
+ module Fastlane
2
+ module Helper
3
+ class YafirimHelper
4
+ # class methods that you define here become available in your action
5
+ # as `Helper::YafirimHelper.your_method`
6
+ #
7
+ def self.show_message
8
+ UI.message("Hello from the yafirim plugin helper!")
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ module Fastlane
2
+ module Yafirim
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ require 'fastlane/plugin/yafirim/version'
2
+
3
+ module Fastlane
4
+ module Yafirim
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::Yafirim.all_classes.each do |current|
15
+ require current
16
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fastlane-plugin-yafirim
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - wd
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-31 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: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: fastlane
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 2.54.3
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 2.54.3
111
+ description:
112
+ email: wd@wdicc.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - LICENSE
118
+ - README.md
119
+ - lib/fastlane/plugin/yafirim.rb
120
+ - lib/fastlane/plugin/yafirim/actions/yafirim_action.rb
121
+ - lib/fastlane/plugin/yafirim/helper/yafirim_helper.rb
122
+ - lib/fastlane/plugin/yafirim/version.rb
123
+ homepage: https://github.com/wd/fastlane-plugin-yafirim
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.6.11
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: Yet another fastlane fir.im plugin
147
+ test_files: []