Class: Fastlane::Actions::AppcircleEnterpriseAppStoreAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/appcircle_enterprise_app_store/actions/appcircle_enterprise_app_store_action.rb

Constant Summary collapse

@@apiToken =
nil
@@authEndpoint =
"https://auth.appcircle.io"
@@apiEndpoint =
"https://api.appcircle.io"

Class Method Summary collapse

Class Method Details

.ac_login_with_pak(personalAccessKey) ⇒ Object



69
70
71
72
73
74
75
76
# File 'lib/fastlane/plugin/appcircle_enterprise_app_store/actions/appcircle_enterprise_app_store_action.rb', line 69

def self.(personalAccessKey)
  user = AuthService.get_ac_token_with_pak(personal_access_key: personalAccessKey, auth_endpoint: @@authEndpoint)
  UI.success("Login is successful.")
  @@apiToken = user.accessToken
rescue StandardError => e
  UI.error("Login failed: #{e.message}")
  raise e
end

.ac_login_with_pat(accessToken) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/fastlane/plugin/appcircle_enterprise_app_store/actions/appcircle_enterprise_app_store_action.rb', line 60

def self.(accessToken)
  user = AuthService.get_ac_token(pat: accessToken, auth_endpoint: @@authEndpoint)
  UI.success("Login is successful.")
  @@apiToken = user.accessToken
rescue StandardError => e
  UI.error("Login failed: #{e.message}")
  raise e
end

.authorsObject



148
149
150
# File 'lib/fastlane/plugin/appcircle_enterprise_app_store/actions/appcircle_enterprise_app_store_action.rb', line 148

def self.authors
  ["Guven Karanfil"]
end

.available_optionsObject



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/fastlane/plugin/appcircle_enterprise_app_store/actions/appcircle_enterprise_app_store_action.rb', line 161

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :personalAPIToken,
                                 env_name: "AC_PERSONAL_API_TOKEN",
                                 description: "Provide Personal API Token to authenticate Appcircle services (use either personalAPIToken or personalAccessKey)",
                                 optional: true,
                                 type: String),

    FastlaneCore::ConfigItem.new(key: :personalAccessKey,
                                 env_name: "AC_PERSONAL_ACCESS_KEY",
                                 description: "Provide Personal Access Key to authenticate Appcircle services (use either personalAPIToken or personalAccessKey)",
                                 optional: true,
                                 type: String),

    FastlaneCore::ConfigItem.new(key: :authEndpoint,
                                 env_name: "AC_AUTH_ENDPOINT",
                                 description: "Optional: Authentication endpoint URL for self-hosted Appcircle installations. Defaults to the Appcircle cloud",
                                 optional: true,
                                 default_value: "https://auth.appcircle.io",
                                 type: String),

    FastlaneCore::ConfigItem.new(key: :apiEndpoint,
                                 env_name: "AC_API_ENDPOINT",
                                 description: "Optional: API endpoint URL for self-hosted Appcircle installations. Defaults to the Appcircle cloud",
                                 optional: true,
                                 default_value: "https://api.appcircle.io",
                                 type: String),

    FastlaneCore::ConfigItem.new(key: :appPath,
                                 env_name: "AC_APP_PATH",
                                 description: "Specify the path to your application file. For iOS, this can be a .ipa or .xcarchive file path. For Android, specify the .apk or .appbundle file path",
                                 optional: false,
                                 type: String),

    FastlaneCore::ConfigItem.new(key: :summary,
                                 env_name: "AC_SUMMARY",
                                 description: "Provide a summary for the application to be published. This summary will be displayed in the Appcircle Enterprise App Store",
                                 optional: false,
                                 type: String),

    FastlaneCore::ConfigItem.new(key: :releaseNotes,
                                 env_name: "AC_RELEASE_NOTES",
                                 description: "Provide release notes for the application to be published. These notes will be displayed in the Appcircle Enterprise App Store",
                                 optional: false,
                                 type: String),

    FastlaneCore::ConfigItem.new(key: :publishType,
                                 env_name: "AC_PUBLISH_TYPE",
                                 description: "Specify the publish type for the application. This can be 0: None, 1: Beta, 2: Live. Default is 0: None. For more information, provide the number of the publish type",
                                 optional: false,
                                 type: String)
  ]
end

.checkTaskStatus(taskId) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/fastlane/plugin/appcircle_enterprise_app_store/actions/appcircle_enterprise_app_store_action.rb', line 78

def self.checkTaskStatus(taskId)
  uri = URI.parse("#{@@apiEndpoint}/task/v1/tasks/#{taskId}")
  timeout = 1

  response = self.send_request(uri, @@apiToken)
  if response.kind_of?(Net::HTTPSuccess)
    stateValue = JSON.parse(response.body)["stateValue"]
    if stateValue == 1
      sleep(1)
      return checkTaskStatus(taskId)
    end
    if stateValue == 3
      return true
    else
      taskStatus = {
        0 => "Unknown",
        1 => "Begin",
        2 => "Canceled",
        3 => 'Completed'
      }
      UI.user_error!("#{taskId} id upload request failed with status #{taskStatus[stateValue]}.")
    end
  else
    UI.user_error!("Upload failed with response code #{response.code} and message '#{response.message}'.")
  end
end

.descriptionObject



144
145
146
# File 'lib/fastlane/plugin/appcircle_enterprise_app_store/actions/appcircle_enterprise_app_store_action.rb', line 144

def self.description
  "Efficiently publish your apps to Appcircle Enterprise Store"
end

.detailsObject



156
157
158
159
# File 'lib/fastlane/plugin/appcircle_enterprise_app_store/actions/appcircle_enterprise_app_store_action.rb', line 156

def self.details
  # Optional:
  "Appcircle Enterprise Mobile App Store is your own mobile app store for providing access to in-house apps with a customizable mobile storefront"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


215
216
217
218
219
220
221
# File 'lib/fastlane/plugin/appcircle_enterprise_app_store/actions/appcircle_enterprise_app_store_action.rb', line 215

def self.is_supported?(platform)
  # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
  # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
  #
  # [:ios, :mac, :android].include?(platform)
  true
end

.publishToStore(entProfileId, entVersionId, summary, releaseNote, publishType) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/fastlane/plugin/appcircle_enterprise_app_store/actions/appcircle_enterprise_app_store_action.rb', line 120

def self.publishToStore(entProfileId, entVersionId, summary, releaseNote, publishType)
  options = {
    auth_token: @@apiToken,
    ent_profile_id: entProfileId,
    ent_version_id: entVersionId,
    summary: summary,
    release_notes: releaseNote,
    publish_type: publishType,
    api_endpoint: @@apiEndpoint
  }
  response = UploadService.publishVersion(options)
rescue StandardError => e
  UI.error("App could not publish at Enterprise App Store. #{e&.response}")
  raise e
end

.return_valueObject



152
153
154
# File 'lib/fastlane/plugin/appcircle_enterprise_app_store/actions/appcircle_enterprise_app_store_action.rb', line 152

def self.return_value
  # If your method provides a return value, you can describe here what it does
end

.run(params) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/fastlane/plugin/appcircle_enterprise_app_store/actions/appcircle_enterprise_app_store_action.rb', line 19

def self.run(params)
  personalAPIToken = params[:personalAPIToken]
  personalAccessKey = params[:personalAccessKey]
  appPath = params[:appPath]
  summary = params[:summary]
  releaseNotes = params[:releaseNotes]
  publishType = params[:publishType]
  @@authEndpoint = params[:authEndpoint]
  @@apiEndpoint = params[:apiEndpoint]

  valid_extensions = ['.apk', '.ipa']

  file_extension = File.extname(appPath).downcase
  unless valid_extensions.include?(file_extension)
    raise "Invalid file extension: #{file_extension}. For Android, use .apk. For iOS, use .ipa."
  end

  if personalAPIToken.nil? && personalAccessKey.nil?
    UI.user_error!("Please provide either Personal API Token (personalAPIToken) or Personal Access Key (personalAccessKey) to authenticate connections to Appcircle services")
  elsif !personalAPIToken.nil? && !personalAccessKey.nil?
    UI.user_error!("Please provide only one authentication method: either Personal API Token (personalAPIToken) or Personal Access Key (personalAccessKey), not both")
  elsif appPath.nil?
    UI.user_error!("Please specify the path to your application file. For iOS, this can be a .ipa or .xcarchive file path. For Android, specify the .apk or .appbundle file path")
  elsif summary.nil?
    UI.user_error!("Please provide a summary for the application to be published. This summary will be displayed in the Appcircle Enterprise App Store")
  elsif releaseNotes.nil?
    UI.user_error!("Please provide release notes for the application to be published. These notes will be displayed in the Appcircle Enterprise App Store")
  elsif publishType.nil?
    UI.user_error!("Please specify the publish type for the application. This can be 0: None, 1: Beta, 2: Live. Default is 0: None. For more information, provide the number of the publish type")
  elsif publishType != "0" && publishType != "1" && publishType != "2"
    UI.user_error!("Please provide a valid publish type. This can be 0: None, 1: Beta, 2: Live. Default is 0: None. For more information, provide the number of the publish type")
  end

  if personalAPIToken.nil?
    self.(personalAccessKey)
  else
    self.(personalAPIToken)
  end
  self.uploadToProfile(appPath, summary, releaseNotes, publishType)
end

.send_request(uri, access_token) ⇒ Object



136
137
138
139
140
141
142
# File 'lib/fastlane/plugin/appcircle_enterprise_app_store/actions/appcircle_enterprise_app_store_action.rb', line 136

def self.send_request(uri, access_token)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = (uri.scheme == "https")
  request = Net::HTTP::Get.new(uri.request_uri)
  request["Authorization"] = "Bearer #{access_token}"
  http.request(request)
end

.uploadToProfile(appPath, summary, releaseNotes, publishType) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/fastlane/plugin/appcircle_enterprise_app_store/actions/appcircle_enterprise_app_store_action.rb', line 105

def self.uploadToProfile(appPath, summary, releaseNotes, publishType)
  response = UploadService.upload_artifact(token: @@apiToken, app: appPath, api_endpoint: @@apiEndpoint)
  result = self.checkTaskStatus(response["taskId"])

  if result
    profileId = UploadService.getProfileId(authToken: @@apiToken, api_endpoint: @@apiEndpoint)
    appVersions = UploadService.getAppVersions(auth_token: @@apiToken, entProfileId: profileId, api_endpoint: @@apiEndpoint)
    appVersionId = UploadService.getVersionId(versionList: appVersions)
    if publishType != "0"
      self.publishToStore(profileId, appVersionId, summary, releaseNotes, publishType)
    end
    UI.success("#{appPath} uploaded to the Appcircle Enterprise Store successfully")
  end
end