fastlane-plugin-taiwan_number_one 0.1.2 → 0.2.4

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: bb753f703cb1ca29144e73ab02075eef0ba777a23005447ae29b71b7851c5469
4
- data.tar.gz: 8d62b2ac64f6ff3b45adeec927f060e0785ee75f9c0ecb7ca70ac3e7217abc10
3
+ metadata.gz: 3f6eb09f64dd7bf6465761f674f378f6ea3d4a912976cd38f600a29a6a4752f1
4
+ data.tar.gz: b033ac75e5eb986c6902c857c9ea9fcfd125bb8513616f3a39100d1b8f5188ad
5
5
  SHA512:
6
- metadata.gz: 8ab1d0603fcb11a782a795a50d2c8624428215b16d5132bf1658657ffc0c8eff78c51c19a6e21ae870d6040444f24085a914116c52c1c72e82eab623dced7f9d
7
- data.tar.gz: 5f947b531a3e54378f787addf6b12af3882d84fcb9b935f9f3d97b0105de5dac820bddfcb5208f100aa5b3319cd27e6e1fcf4b0487eb925c136915ceeac5ca87
6
+ metadata.gz: fe2c9f523df133975f0bcca2b00a8f099b984add55edade12febf3dffd0227ee54fb080b46e50b0708f1b378f34561c99b93b8334d76d84752882797ea15cd7f
7
+ data.tar.gz: 15e3641963bb2568d9b0853dc24704450d04c797e405c2ff0137135e7501a97867a485c2446cb5e96752a7530ea15bb3dc5a66cdb760af38f7423a7df60370d3
data/README.md CHANGED
@@ -12,7 +12,7 @@ fastlane add_plugin taiwan_number_one
12
12
 
13
13
  ## About taiwan_number_one
14
14
 
15
- To approve or reject if status is Pending Developer Release.
15
+ To approve or reject if status is `Pending Developer Release`, otherwise do nothing.
16
16
 
17
17
  #### This feature is requsted for a while:
18
18
 
@@ -33,10 +33,10 @@ https://github.com/fastlane/fastlane/issues/17539
33
33
 
34
34
  ## Usage
35
35
 
36
- ##### install plugin for fastlane
36
+ ##### Install plugin for fastlane
37
37
  [install instructions](https://docs.fastlane.tools/plugins/using-plugins/)
38
38
  ```
39
- bundle exce fastlane add_plugin taiwan_number_one
39
+ bundle exec fastlane add_plugin taiwan_number_one
40
40
  ```
41
41
  but I personally prefer adding plugin in `Gemfile` like this to avoid additional `Pluginfile` in ~'your_ios_project_dir'/fastlane
42
42
 
@@ -59,11 +59,38 @@ lane :release_decision do |options|
59
59
  taiwan_number_one(
60
60
  username: username,
61
61
  app_identifier: app_identifier,
62
- app_decision: options[:app_decision]
62
+ app_decision: options[:app_decision],
63
+ api_key: api_key
63
64
  )
64
65
  end
65
66
  ```
66
67
 
68
+ and this:
69
+ ```
70
+ desc "release App store version"
71
+ lane :release_app do
72
+ result = release_decision(app_decision: Fastlane::Actions::TaiwanNumberOneAction::DicisionType::RELEASE)
73
+ if result == Fastlane::Actions::TaiwanNumberOneAction::ActionResult::SUCCESS
74
+ # do your thing here!
75
+ end
76
+ end
77
+ ```
78
+
79
+ or this:
80
+ ```
81
+ desc "reject App store version"
82
+ lane :reject_app do
83
+ api_key = app_store_connect_api_key(
84
+ key_id: ENV["ASC_API_KEY_ID"],
85
+ issuer_id: ENV["ISSUER_ID"],
86
+ key_content: ENV["ASC_API_KEY"]
87
+ )
88
+ release_decision(app_decision: Fastlane::Actions::TaiwanNumberOneAction::DicisionType::REJECT)
89
+ end
90
+ ```
91
+
92
+ *for more info about app_store_connect_api_key, please refer to [here](http://docs.fastlane.tools/actions/app_store_connect_api_key/#app_store_connect_api_key) and [here](http://docs.fastlane.tools/app-store-connect-api/#using-an-app-store-connect-api-key)
93
+
67
94
  Since there might have some problem in `reject_if_possible` of `Deliver`, so it's better to call this Action before `Deliver` everytime.
68
95
 
69
96
  something like this:
@@ -105,6 +132,13 @@ username |Your Apple ID Username |
105
132
  app_identifier|The bundle identifier of your app |
106
133
  team_id |The ID of your App Store Connect team if you're in multiple teams. (optional)|
107
134
  team_name |The name of your App Store Connect team if you're in multiple teams. (optional)|
135
+ api_key_path |Path to your App Store Connect API Key JSON file (https://docs.fastlane.tools/app-store-connect-api/#using-fastlane-api-key-json-file) |
136
+ api_key |Your App Store Connect API Key information (https://docs.fastlane.tools/app-store-connect-api/#use-return-value-and-pass-in-as-an-option) |
137
+
138
+ ## Action Return
139
+ `Fastlane::Actions::TaiwanNumberOneAction::ActionResult::SUCCESS`
140
+ or
141
+ `Fastlane::Actions::TaiwanNumberOneAction::ActionResult::DO_NOTHING`
108
142
 
109
143
  ## Run tests for this plugin
110
144
 
@@ -1,5 +1,4 @@
1
1
  require "fastlane/action"
2
- require "Spaceship"
3
2
  require_relative "../helper/taiwan_number_one_helper"
4
3
 
5
4
  module Fastlane
@@ -10,76 +9,98 @@ module Fastlane
10
9
  REJECT = "reject"
11
10
  end
12
11
 
13
- def self.run(params)
14
- app_id = params.fetch(:app_identifier)
15
- username = params.fetch(:username)
16
- unless app_id && username
17
- UI.message("Could not find app_id and username.")
18
- return
19
- end
12
+ module ActionResult
13
+ SUCCESS = "Success"
14
+ DO_NOTHING = "Nothing has changed"
15
+ end
20
16
 
21
- # Prompts select team if multiple teams and none specified
22
- UI.message("Login to App Store Connect (#{params[:username]})")
23
- Spaceship::ConnectAPI.login(
24
- params[:username],
25
- use_portal: false,
26
- use_tunes: true,
27
- tunes_team_id: params[:team_id],
28
- team_name: params[:team_name]
29
- )
30
- UI.message("Login successful")
31
-
32
- # Get App
33
- application = Spaceship::Application.find(app_id)
34
- unless application
35
- UI.user_error!("Could not find app with bundle identifier '#{app_id}' on account #{params[:username]}")
36
- end
17
+ def self.run(params)
18
+ require 'spaceship'
19
+ begin
20
+ params[:api_key] ||= Actions.lane_context[SharedValues::APP_STORE_CONNECT_API_KEY]
37
21
 
38
- app = Spaceship::ConnectAPI::App.find(app_id)
39
- version = app.get_app_store_versions.first
40
- UI.message("app_store_state is #{version.app_store_state}")
41
- client ||= Spaceship::ConnectAPI
42
- platform ||= Spaceship::ConnectAPI::Platform::IOS
43
- filter = {
44
- appStoreState: [
45
- Spaceship::ConnectAPI::AppStoreVersion::AppStoreState::PENDING_DEVELOPER_RELEASE
46
- ].join(","),
47
- platform: platform
48
- }
49
- app_store_version = app.get_app_store_versions(client: client, filter: filter, includes: "appStoreVersionSubmission")
50
- .sort_by { |v| Gem::Version.new(v.version_string) }
51
- .last
52
- if app_store_version
53
- version_string = app_store_version.version_string
54
- state = app_store_version.app_store_state
55
- UI.message("version #{version_string} is #{state}")
56
- unless state == Spaceship::ConnectAPI::AppStoreVersion::AppStoreState::PENDING_DEVELOPER_RELEASE
57
- UI.message("AppStoreState is not PENDING_DEVELOPER_RELEASE")
22
+ app_id = params.fetch(:app_identifier)
23
+ username = params.fetch(:username)
24
+ unless app_id && username
25
+ UI.message("Could not find app_id and username.")
58
26
  return
59
27
  end
60
- decision = params[:app_decision]
61
- decision ||= fetch_decision
62
- case decision
63
- when DicisionType::RELEASE
64
- UI.message("decision is release")
65
- release_version_if_possible(app: application, app_store_version: app_store_version)
66
- when DicisionType::REJECT
67
- UI.message("decision is reject")
68
- reject_version_if_possible(app: app, app_store_version: app_store_version)
28
+
29
+ token = self.api_token(params)
30
+ if token
31
+ UI.message("Using App Store Connect API token...")
32
+ Spaceship::ConnectAPI.token = token
69
33
  else
70
- decision ||= fetch_decision
34
+ UI.message("Login to App Store Connect (#{params[:username]})")
35
+ Spaceship::ConnectAPI.login(
36
+ params[:username],
37
+ use_portal: false,
38
+ use_tunes: true,
39
+ tunes_team_id: params[:team_id],
40
+ team_name: params[:team_name]
41
+ )
42
+ UI.message("Login successful")
71
43
  end
72
- else
73
- UI.message("no pending release version exist.")
44
+
45
+ app = Spaceship::ConnectAPI::App.find(app_id)
46
+ version = app.get_app_store_versions.first
47
+ UI.message("app_store_state is #{version.app_store_state}")
48
+ client ||= Spaceship::ConnectAPI
49
+ platform ||= Spaceship::ConnectAPI::Platform::IOS
50
+ filter = {
51
+ appStoreState: [
52
+ Spaceship::ConnectAPI::AppStoreVersion::AppStoreState::PENDING_DEVELOPER_RELEASE
53
+ ].join(","),
54
+ platform: platform
55
+ }
56
+ app_store_version = app.get_app_store_versions(client: client, filter: filter, includes: "appStoreVersionSubmission")
57
+ .sort_by { |v| Gem::Version.new(v.version_string) }
58
+ .last
59
+ if app_store_version
60
+ version_string = app_store_version.version_string
61
+ state = app_store_version.app_store_state
62
+ UI.message("version #{version_string} is #{state}")
63
+ unless state == Spaceship::ConnectAPI::AppStoreVersion::AppStoreState::PENDING_DEVELOPER_RELEASE
64
+ UI.message("AppStoreState is not PENDING_DEVELOPER_RELEASE")
65
+ UI.message("🇹🇼 Taiwan helps you do nothing!")
66
+ return
67
+ end
68
+ decision ||= fetch_decision(param)
69
+
70
+ result = ActionResult::DO_NOTHING
71
+ case decision
72
+ when DicisionType::RELEASE
73
+ UI.message("decision is release")
74
+ result = release_version_if_possible(app: app, app_store_version: app_store_version)
75
+ when DicisionType::REJECT
76
+ UI.message("decision is reject")
77
+ result = reject_version_if_possible(app: app, app_store_version: app_store_version)
78
+ else
79
+ UI.user_error!("App's decision must be release or reject")
80
+ result = ActionResult::DO_NOTHING
81
+ end
82
+
83
+ UI.message("The taiwan_number_one plugin action is finished!")
84
+ UI.message("🇹🇼 Taiwan can help!")
85
+ return result
86
+ else
87
+ UI.message("no pending release version exist.")
88
+ UI.message("The taiwan_number_one plugin action is finished!")
89
+ UI.message("🇹🇼 Taiwan can help!")
90
+ return ActionResult::DO_NOTHING
91
+ end
92
+ rescue => error
93
+ UI.message("🇹🇼 Taiwan might not be able to help you with this...")
94
+ UI.user_error!("The taiwan_number_one plugin action is finished with error: #{error.message}!")
95
+ return ActionResult::DO_NOTHING
74
96
  end
75
- UI.message("The taiwan_number_one plugin action is finished!")
76
97
  end
77
98
 
78
- def self.fetch_decision
79
- decision = nil
99
+ def self.fetch_decision(param)
100
+ decision = params[:app_decision]
80
101
  until ["release", "reject"].include?(decision)
81
- decision = UI.input("Please enter the app's release decision (release, reject): ")
82
- UI.message("App's decision must be release or reject")
102
+ UI.user_error!("App's decision must be release or reject.")
103
+ return
83
104
  end
84
105
  # return decision
85
106
  UI.message("return type #{decision}")
@@ -89,33 +110,45 @@ module Fastlane
89
110
  return DicisionType::REJECT
90
111
  end
91
112
  end
92
-
113
+
93
114
  def self.release_version_if_possible(app: nil, app_store_version: Spaceship::ConnectAPI::AppStoreVersion)
94
115
  unless app
95
116
  UI.user_error!("Could not find app with bundle identifier '#{params[:app_identifier]}' on account #{params[:username]}")
117
+ return ActionResult::DO_NOTHING
96
118
  end
97
119
 
98
120
  begin
99
121
  app_store_version.create_app_store_version_release_request
100
122
  UI.message("release version #{app_store_version.version_string} successfully!")
123
+ return ActionResult::SUCCESS
101
124
  rescue => e
102
- UI.user_error!("An error occurred while releasing version #{app_store_version}")
103
- UI.error("#{e.message}\n#{e.backtrace.join("\n")}") if FastlaneCore::Globals.verbose?
125
+ UI.user_error!("An error occurred while releasing version #{app_store_version}, #{e.message}\n#{e.backtrace.join("\n")}")
126
+ return ActionResult::DO_NOTHING
104
127
  end
105
128
  end
106
129
 
107
130
  def self.reject_version_if_possible(app: nil, app_store_version: Spaceship::ConnectAPI::AppStoreVersion)
108
131
  unless app
109
132
  UI.user_error!("Could not find app with bundle identifier '#{params[:app_identifier]}' on account #{params[:username]}")
133
+ return ActionResult::DO_NOTHING
110
134
  end
111
-
135
+
112
136
  if app_store_version.reject!
113
- UI.success("rejected version #{app_store_version} Successfully!")
137
+ UI.success("rejected version #{app_store_version.version_string} Successfully!")
138
+ return ActionResult::SUCCESS
114
139
  else
115
140
  UI.user_error!("An error occurred while rejected version #{app_store_version}")
141
+ return ActionResult::DO_NOTHING
116
142
  end
117
143
  end
118
144
 
145
+ def self.api_token(params)
146
+ params[:api_key] ||= Actions.lane_context[SharedValues::APP_STORE_CONNECT_API_KEY]
147
+ api_token ||= Spaceship::ConnectAPI::Token.create(params[:api_key]) if params[:api_key]
148
+ api_token ||= Spaceship::ConnectAPI::Token.from_json_file(params[:api_key_path]) if params[:api_key_path]
149
+ return api_token
150
+ end
151
+
119
152
  def self.description
120
153
  "release or reject if status is Pending Developer Release."
121
154
  end
@@ -125,14 +158,20 @@ module Fastlane
125
158
  end
126
159
 
127
160
  def self.return_value
128
- # If your method provides a return value, you can describe here what it does
161
+ return "'Success' if action passes, else, 'Nothing has changed'"
129
162
  end
130
163
 
131
164
  def self.details
132
- # Optional:
133
165
  "use fastlane to release or reject reviewed version"
134
166
  end
135
167
 
168
+ def self.output
169
+ [
170
+ [ActionResult::SUCCESS, 'Successfully release or reject.'],
171
+ [ActionResult::DO_NOTHING, 'Do nothing.']
172
+ ]
173
+ end
174
+
136
175
  def self.available_options
137
176
  user = CredentialsManager::AppfileConfig.try_fetch_value(:itunes_connect_id)
138
177
  user ||= CredentialsManager::AppfileConfig.try_fetch_value(:apple_id)
@@ -180,7 +219,22 @@ module Fastlane
180
219
  default_value_dynamic: true,
181
220
  verify_block: proc do |value|
182
221
  ENV["FASTLANE_ITC_TEAM_NAME"] = value.to_s
183
- end)
222
+ end),
223
+ FastlaneCore::ConfigItem.new(key: :api_key_path,
224
+ env_name: "FL_REGISTER_DEVICE_API_KEY_PATH",
225
+ description: "Path to your App Store Connect API Key JSON file (https://docs.fastlane.tools/app-store-connect-api/#using-fastlane-api-key-json-file)",
226
+ optional: true,
227
+ conflicting_options: [:api_key],
228
+ verify_block: proc do |value|
229
+ UI.user_error!("Couldn't find API key JSON file at path '#{value}'") unless File.exist?(value)
230
+ end),
231
+ FastlaneCore::ConfigItem.new(key: :api_key,
232
+ env_name: "FL_REGISTER_DEVICE_API_KEY",
233
+ description: "Your App Store Connect API Key information (https://docs.fastlane.tools/app-store-connect-api/#use-return-value-and-pass-in-as-an-option)",
234
+ type: Hash,
235
+ optional: true,
236
+ sensitive: true,
237
+ conflicting_options: [:api_key_path])
184
238
  ]
185
239
  end
186
240
 
@@ -194,7 +248,8 @@ module Fastlane
194
248
  def self.example_code
195
249
  [
196
250
  'taiwan_number_one(
197
- app_decision: "release", # Set to true to skip verification of HTML preview
251
+ app_decision: "release",
252
+ api_key: "api_key" # your app_store_connect_api_key
198
253
  )'
199
254
  ]
200
255
  end
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module TaiwanNumberOne
3
- VERSION = "0.1.2"
3
+ VERSION = "0.2.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-taiwan_number_one
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - andrew54068
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-13 00:00:00.000000000 Z
11
+ date: 2021-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry