fastlane-plugin-zealot 0.3.0 → 0.4.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: a788cca160ba486e17a20fd061e5368816654ebdae1fcf9510d0acccfb65e18f
4
- data.tar.gz: c174efc979901a397706e503c7dd44576d5f78e8e69c285ba74a8584a854bc30
3
+ metadata.gz: 876ca038d87e1cd85c34e6f60fec74125e639c7d8a55d5c67b80bd33abb0295a
4
+ data.tar.gz: 6346d81d2edddf64242e4d0b3f5891bd2271d143c22b28a37895cbe2e54a0287
5
5
  SHA512:
6
- metadata.gz: 97b483952f0260032ca1d0f51b97fd43c1744ec0e9b3c85d33f691cc4197d8fdb99fdc6f2b29b886f1a20892427ab2671e77c409a458cb26f7b80b4c35983d6e
7
- data.tar.gz: 9009126f49d736dbf350ed8e5e4295b1d489d48af11db93675156a5b13429237b0820cc27a64cd23b4b90dd479cb41fd79b75b4ce2d632993b760ae5e16af741
6
+ metadata.gz: 8bfd4fd75beee932bb1a6577c27aba4b1437daa4071d83d21a45a03c7f8f05db30e5449b087a5828135bec636fbdb26f2fa770319cef79e09e003478b806b0e6
7
+ data.tar.gz: bbc559185354975864ce0f1f12fc1341ed1ca85bd9d319a1dcbdda275a07509775c821d5c3fb6f77d5891fa5953e052aacce1a50b43d40e8853dc565bae9d1a6
@@ -137,6 +137,11 @@ module Fastlane
137
137
  optional: true,
138
138
  default_value: 'fastlane',
139
139
  type: String),
140
+ FastlaneCore::ConfigItem.new(key: :ci_url,
141
+ env_name: 'ZEALOT_CI_CURL',
142
+ description: 'The name of upload source',
143
+ optional: true,
144
+ type: String),
140
145
  FastlaneCore::ConfigItem.new(key: :timeout,
141
146
  env_name: 'ZEALOT_TIMEOUT',
142
147
  description: 'Request timeout in seconds',
@@ -0,0 +1,146 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'credentials_manager'
4
+ require 'fastlane/action'
5
+ require_relative '../helper/zealot_helper'
6
+
7
+ module Fastlane
8
+ module Actions
9
+
10
+ class ZealotSyncDevicesAction < Action
11
+ extend Fastlane::Helper::ZealotHelper
12
+
13
+ def self.run(params)
14
+ require 'spaceship'
15
+
16
+ credentials = CredentialsManager::AccountManager.new(user: params[:username])
17
+ Spaceship.login(credentials.user, credentials.password)
18
+ Spaceship.select_team
19
+
20
+ UI.message('Fetching list of currently registered devices...')
21
+ all_platforms = Set[params[:platform]]
22
+ supported_platforms = all_platforms.select { |platform| self.is_supported?(platform.to_sym) }
23
+
24
+ devices = supported_platforms.flat_map { |platform| Spaceship::Device.all(mac: platform == "mac") }
25
+
26
+ print_table(build_table_data(params, devices), title: 'zealot_sync_devices')
27
+
28
+ UI.verbose("Syncing devices to #{params[:endpoint]} ...")
29
+ failed_devices = []
30
+ devices.each do |device|
31
+ begin
32
+ sync_deivce(params, device)
33
+ rescue Faraday::ConnectionFailed
34
+ failed_devices << {udid: device.udid, error: 'Can not connecting to Zealot'}
35
+ rescue Faraday::TimeoutError
36
+ failed_devices << {udid: device.udid, error: 'Timed out to Zealot'}
37
+ end
38
+ end
39
+
40
+ failed = failed_devices.size
41
+ successed = devices.size - failed
42
+ UI.success "Successful Synced devices. success: #{successed}, failed: #{failed}"
43
+ UI.verbose "Failed devices: #{failed_devices}"
44
+ end
45
+
46
+ #####################################################
47
+ # @!group Documentation
48
+ #####################################################
49
+
50
+ def self.description
51
+ 'Check app version exists from Zealot'
52
+ end
53
+
54
+ def self.available_options
55
+ [
56
+ FastlaneCore::ConfigItem.new(key: :endpoint,
57
+ env_name: 'ZEALOT_ENDPOINT',
58
+ description: 'The endpoint of zealot',
59
+ type: String),
60
+ FastlaneCore::ConfigItem.new(key: :token,
61
+ env_name: 'ZEALOT_TOKEN',
62
+ description: 'The token of user',
63
+ sensitive: true,
64
+ verify_block: proc do |value|
65
+ UI.user_error!("No user token for Zealot given, pass using `token: 'token'`") if value.nil? || value.empty?
66
+ end,
67
+ type: String),
68
+ FastlaneCore::ConfigItem.new(key: :username,
69
+ env_name: 'DELIVER_USER',
70
+ description: 'The apple id (username) of Apple Developer Portal',
71
+ default_value_dynamic: true,
72
+ optional: true,
73
+ type: String),
74
+ FastlaneCore::ConfigItem.new(key: :team_id,
75
+ env_name: 'ZEALOT_APPLE_TEAM_ID',
76
+ description: 'The ID of your Developer Portal team if you\'re in multiple teams',
77
+ default_value: CredentialsManager::AppfileConfig.try_fetch_value(:team_id),
78
+ default_value_dynamic: true,
79
+ optional: true,
80
+ type: String,
81
+ verify_block: proc do |value|
82
+ ENV["FASTLANE_TEAM_ID"] = value.to_s
83
+ end),
84
+ FastlaneCore::ConfigItem.new(key: :team_name,
85
+ env_name: 'ZEALOT_APPLE_TEAM_NAME',
86
+ description: 'The name of your Developer Portal team if you\'re in multiple teams',
87
+ default_value: CredentialsManager::AppfileConfig.try_fetch_value(:team_id),
88
+ default_value_dynamic: true,
89
+ optional: true,
90
+ type: String,
91
+ verify_block: proc do |value|
92
+ ENV["FASTLANE_TEAM_NAME"] = value.to_s
93
+ end),
94
+ FastlaneCore::ConfigItem.new(key: :platform,
95
+ env_name: 'ZEALOT_APPLE_PLATFORM',
96
+ description: 'The platform to use (optional)',
97
+ optional: true,
98
+ default_value: 'ios',
99
+ verify_block: proc do |value|
100
+ UI.user_error!('The platform can only be ios or mac') unless %('ios', 'mac').include?(value)
101
+ end),
102
+ FastlaneCore::ConfigItem.new(key: :verify_ssl,
103
+ env_name: 'ZEALOT_VERIFY_SSL',
104
+ description: 'Should verify SSL of zealot service',
105
+ optional: true,
106
+ default_value: true,
107
+ type: Boolean),
108
+ FastlaneCore::ConfigItem.new(key: :timeout,
109
+ env_name: 'ZEALOT_TIMEOUT',
110
+ description: 'Request timeout in seconds',
111
+ type: Integer,
112
+ optional: true),
113
+ FastlaneCore::ConfigItem.new(key: :fail_on_error,
114
+ env_name: 'ZEALOT_FAIL_ON_ERROR',
115
+ description: 'Should an error http request cause a failure? (true/false)',
116
+ optional: true,
117
+ default_value: false,
118
+ type: Boolean)
119
+ ]
120
+ end
121
+
122
+ def self.example_code
123
+ [
124
+ 'zealot_sync_devices(
125
+ endpoint: "...",
126
+ token: "...",
127
+ username: "...",
128
+ team_id: "..."
129
+ )'
130
+ ]
131
+ end
132
+
133
+ def self.category
134
+ :beta
135
+ end
136
+
137
+ def self.authors
138
+ ['icyleaf']
139
+ end
140
+
141
+ def self.is_supported?(_)
142
+ true
143
+ end
144
+ end
145
+ end
146
+ end
@@ -71,14 +71,16 @@ module Fastlane
71
71
  end
72
72
 
73
73
  UPLOAD_APP_PARAMS_KEYS = %w[
74
- name changelog release_type slug branch
75
- source git_commit password custom_fields
74
+ name changelog release_type slug branch password
75
+ git_commit custom_fields source ci_url
76
76
  ].freeze
77
77
 
78
78
  def avialable_upload_app_params(params)
79
79
  UPLOAD_APP_PARAMS_KEYS.each_with_object({}) do |key, obj|
80
80
  value = params.fetch(key.to_sym, ask: false)
81
81
  value = JSON.dump(value) if key == 'custom_fields' && value
82
+ value = detect_ci_url(params) if key == 'ci_url'
83
+ value = detect_source(params) if key == 'source'
82
84
  obj[key.to_sym] = value if value && !value.empty?
83
85
  end
84
86
  end
@@ -133,8 +135,30 @@ module Fastlane
133
135
  end
134
136
  end
135
137
 
138
+ #######################################
139
+
140
+ def sync_deivce(params, device)
141
+ body = { token: params[:token], name: device.name }
142
+ http_request(:put, "/api/devices/#{device.udid}", body, params)
143
+ end
144
+
145
+ def build_table_data(params, devices)
146
+ data = {
147
+ 'Endpoint' => params[:endpoint],
148
+ 'Token' => params[:token],
149
+ "Devices (#{devices.size})" => devices.map {|d| "#{d.name}: #{d.udid}"}.join("\n")
150
+ }
151
+ end
152
+
136
153
  #####################################
137
154
 
155
+ def http_request(method, uri, body, params)
156
+ connection = make_connection(params[:endpoint], params[:verify_ssl])
157
+ connection.run_request(method, uri, body, nil) do |req|
158
+ req.options.timeout = params[:timeout] if params[:timeout]
159
+ end
160
+ end
161
+
138
162
  def make_connection(endpoint, verify_ssl = true)
139
163
  require 'faraday'
140
164
  require 'faraday_middleware'
@@ -179,6 +203,40 @@ module Fastlane
179
203
 
180
204
  [:token]
181
205
  end
206
+
207
+ def detect_source(params)
208
+ return 'jenkins' if jenkins?
209
+ return 'gitlab-ci' if gitlab?
210
+
211
+ params[:source]
212
+ end
213
+
214
+ def detect_ci_url(params)
215
+ return params[:ci_url] if params[:ci_url]
216
+
217
+ if ENV['BUILD_URL']
218
+ # Jenkins
219
+ return ENV['BUILD_URL']
220
+ elsif ENV['CI_JOB_URL']
221
+ # Gitlab >= 11.1, Runner 0.5
222
+ return ENV['CI_JOB_URL']
223
+ elsif ENV['CI_PROJECT_URL']
224
+ # Gitlab >= 8.10, Runner 0.5
225
+ return "#{ENV['CI_PROJECT_URL']}/-/jobs/#{ENV['CI_BUILD_ID']}"
226
+ end
227
+ end
228
+
229
+ def jenkins?
230
+ %w(JENKINS_URL JENKINS_HOME).each do |current|
231
+ return true if ENV.key?(current)
232
+ end
233
+
234
+ return false
235
+ end
236
+
237
+ def gitlab?
238
+ ENV.key?('GITLAB_CI')
239
+ end
182
240
  end
183
241
  end
184
242
  end
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module Zealot
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-zealot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - icyleaf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-21 00:00:00.000000000 Z
11
+ date: 2020-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -175,6 +175,7 @@ files:
175
175
  - lib/fastlane/plugin/zealot.rb
176
176
  - lib/fastlane/plugin/zealot/actions/zealot_action.rb
177
177
  - lib/fastlane/plugin/zealot/actions/zealot_debug_file.rb
178
+ - lib/fastlane/plugin/zealot/actions/zealot_sync_devices.rb
178
179
  - lib/fastlane/plugin/zealot/actions/zealot_version_check.rb
179
180
  - lib/fastlane/plugin/zealot/helper/zealot_helper.rb
180
181
  - lib/fastlane/plugin/zealot/version.rb