Class: Fastlane::Actions::AppcircleTestingDistributionAction

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

Class Method Summary collapse

Class Method Details

.ac_login(personalAPIToken) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/fastlane/plugin/appcircle_testing_distribution/actions/appcircle_testing_distribution_action.rb', line 44

def self.(personalAPIToken)
  begin
    user = TDAuthService.get_ac_token(pat: personalAPIToken)
    UI.success("Login is successful.")
    return user.accessToken
  rescue => e
    UI.user_error!("Login failed: #{e.message}")
  end
end

.ac_upload(token, appPath, profileID, message) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/fastlane/plugin/appcircle_testing_distribution/actions/appcircle_testing_distribution_action.rb', line 85

def self.ac_upload(token, appPath, profileID, message)
  begin
    response = TDUploadService.upload_artifact(token: token, message: message, app: appPath, dist_profile_id: profileID)
    result = self.checkTaskStatus(token, response['taskId'])

    if result
      UI.success("#{appPath} Uploaded to profile id #{profileID} successfully  🎉")
    end
  rescue => e
    status_code = e.respond_to?(:response) && e.response ? e.response.code : 'unknown'
    UI.user_error!("Upload failed with status code #{status_code}, with message '#{e.message}'")
  end
end

.authorsObject



103
104
105
# File 'lib/fastlane/plugin/appcircle_testing_distribution/actions/appcircle_testing_distribution_action.rb', line 103

def self.authors
  ["appcircleio"]
end

.available_optionsObject



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/fastlane/plugin/appcircle_testing_distribution/actions/appcircle_testing_distribution_action.rb', line 116

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :personalAPIToken,
                                 env_name: "AC_PERSONAL_API_TOKEN",
                                 description: "Provide Personal API Token to authenticate connections to Appcircle services",
                                 optional: false,
                                 type: String),
    
    FastlaneCore::ConfigItem.new(key: :profileName,
                                 env_name: "AC_PROFILE_NAME",
                                 description: "Enter the profile name of the Appcircle distribution profile. This name uniquely identifies the profile under which your applications will be distributed",
                                 optional: false,
                                 type: String),
    
    FastlaneCore::ConfigItem.new(key: :createProfileIfNotExists,
                                 env_name: "AC_CREATE_PROFILE_IF_NOT_EXISTS",
                                 description: "If the profile does not exist, create a new profile with the given name",
                                 optional: true,
                                 type: Boolean),

    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: :message,
                                 env_name: "AC_MESSAGE",
                                 description: "Optional message to include with the distribution to provide additional information to testers or users receiving the build",
                                 optional: false,
                                 type: String)
  ]
end

.checkTaskStatus(authToken, taskId) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/fastlane/plugin/appcircle_testing_distribution/actions/appcircle_testing_distribution_action.rb', line 54

def self.checkTaskStatus(authToken, taskId)
  uri = URI.parse("https://api.appcircle.io/task/v1/tasks/#{taskId}")
  timeout = 1
  
  response = self.send_request(uri, authToken)
  if response.is_a?(Net::HTTPSuccess)
    stateValue = JSON.parse(response.body)["stateValue"]
    
    if stateValue == 1
      sleep(1)
      return checkTaskStatus(authToken, taskId)
    end
    if stateValue == 3
      return true
    else
      UI.error("Task Id #{taskId} failed with state value #{stateValue}")
      raise "Upload could not completed successfully"
    end
  else
    raise "Upload failed with response code #{response.code} and message '#{response.message}'"
  end
end

.descriptionObject



99
100
101
# File 'lib/fastlane/plugin/appcircle_testing_distribution/actions/appcircle_testing_distribution_action.rb', line 99

def self.description
  "Efficiently distribute application builds to users or testing groups using Appcircle's robust platform."
end

.detailsObject



111
112
113
114
# File 'lib/fastlane/plugin/appcircle_testing_distribution/actions/appcircle_testing_distribution_action.rb', line 111

def self.details
  # Optional:
  "Appcircle simplifies the distribution of builds to test teams with an extensive platform for managing and tracking applications, versions, testers, and teams. Appcircle integrates with enterprise authentication mechanisms such as LDAP and SSO, ensuring secure distribution of testing packages. Learn more about Appcircle testing distribution"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


150
151
152
153
154
155
# File 'lib/fastlane/plugin/appcircle_testing_distribution/actions/appcircle_testing_distribution_action.rb', line 150

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, :android].include?(platform)
end

.return_valueObject



107
108
109
# File 'lib/fastlane/plugin/appcircle_testing_distribution/actions/appcircle_testing_distribution_action.rb', line 107

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

.run(params) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/fastlane/plugin/appcircle_testing_distribution/actions/appcircle_testing_distribution_action.rb', line 13

def self.run(params)
  personalAPIToken = params[:personalAPIToken]
  profileName = params[:profileName]
  appPath = params[:appPath]
  message = params[:message]
  createProfileIfNotExists = params[:createProfileIfNotExists]

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

  file_extension = File.extname(appPath).downcase
  unless valid_extensions.include?(file_extension)
    UI.user_error!("Invalid file extension: #{file_extension}. For Android, use .apk or .aab. For iOS, use .ipa or .zip(.xcarchive).")
  end

  if personalAPIToken.nil?
    UI.user_error!("Personal API Token is required to authenticate connections to Appcircle services. Please provide a valid access token")
  elsif profileName.nil?
    UI.user_error!("Distribution profile name is required to distribute applications. Please provide a distribution profile name")
  elsif appPath.nil?
    UI.user_error!("Application file path is required to distribute applications. Please provide a valid application file path")
  elsif message.nil?
    UI.user_error!("Message field is required. Please provide a valid message")
  end


  authToken = self.(personalAPIToken)

  profileId = TDUploadService.get_profile_id(authToken, profileName, createProfileIfNotExists)
  self.ac_upload(authToken, appPath, profileId, message)
end

.send_request(uri, access_token) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/fastlane/plugin/appcircle_testing_distribution/actions/appcircle_testing_distribution_action.rb', line 77

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