fastlane-plugin-taiwan_number_one 0.1.0 → 0.2.3

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