Class: Fastlane::Actions::UploadToLambdatestAction

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

Constant Summary collapse

API_ENDPOINT =
"https://manual-api.lambdatest.com/app/upload/realDevice"
SUPPORTED_EXTENSIONS =
["apk", "ipa", "aab"]

Class Method Summary collapse

Class Method Details

.authorsObject



54
55
56
# File 'lib/fastlane/plugin/lambdatest/actions/upload_to_lambdatest.rb', line 54

def self.authors
  ["Pawan Rai"]
end

.available_optionsObject



73
74
75
76
77
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
104
105
106
107
108
109
110
# File 'lib/fastlane/plugin/lambdatest/actions/upload_to_lambdatest.rb', line 73

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :lt_username,
                                 description: "Lambdatest's username",
                                 optional: false,
                                 is_string: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("No LT username given.") if value.to_s.empty?
                                 end),
    FastlaneCore::ConfigItem.new(key: :lt_access_key,
                                 description: "Lambdatest's access token",
                                 optional: false,
                                 is_string: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("No lt_access_key given.") if value.to_s.empty?
                                 end),
    FastlaneCore::ConfigItem.new(key: :file_path,
                                 description: "App file path",
                                 optional: true,
                                 is_string: true,
                                 default_value: default_file_path),
    FastlaneCore::ConfigItem.new(key: :custom_id,
                                 description: "Custom ID",
                                 optional: true,
                                 is_string: false,
                                default_value: nil),
    FastlaneCore::ConfigItem.new(key: :app_name,
                                 description: "App name",
                                 optional: true,
                                 is_string: true,
                                 default_value: "app"),
    FastlaneCore::ConfigItem.new(key: :visibility,
                                 description: "Visibility",
                                 optional: true,
                                 is_string: true,
                                 default_value: "individual")
  ]
end

.default_file_pathObject



62
63
64
65
66
67
68
69
70
71
# File 'lib/fastlane/plugin/lambdatest/actions/upload_to_lambdatest.rb', line 62

def self.default_file_path
  platform = Actions.lane_context[Actions::SharedValues::PLATFORM_NAME]
  if platform == :ios
    # Shared value for ipa path if it was generated by gym https://docs.fastlane.tools/actions/gym/.
    return Actions.lane_context[Actions::SharedValues::IPA_OUTPUT_PATH]
  else
    # Shared value for apk if it was generated by gradle.
    return Actions.lane_context[Actions::SharedValues::GRADLE_APK_OUTPUT_PATH]
  end
end

.descriptionObject



50
51
52
# File 'lib/fastlane/plugin/lambdatest/actions/upload_to_lambdatest.rb', line 50

def self.description
  "LambdaTest fastlane plugin for android and ios apps."
end

.detailsObject



58
59
60
# File 'lib/fastlane/plugin/lambdatest/actions/upload_to_lambdatest.rb', line 58

def self.details
  "Uploads IPA and APK files to Lambdatest for test."
end

.example_codeObject



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/fastlane/plugin/lambdatest/actions/upload_to_lambdatest.rb', line 122

def self.example_code
  [
    'upload_to_lambdatest',
    'upload_to_lambdatest(
      lt_username: ENV["LT_USERNAME"],
      lt_access_key: ENV["LT_ACCESS_KEY"],
      file_path: "path_to_app_file",
      app_name: "android_app"
     )',
     'upload_to_lambdatest(
      lt_username: ENV["LT_USERNAME"],
      lt_access_key: ENV["LT_ACCESS_KEY"],
      file_path: "path_to_app_file",
      app_name: "android_app",
      visibility: "team",
     )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/fastlane/plugin/lambdatest/actions/upload_to_lambdatest.rb', line 112

def self.is_supported?(platform)
  [:ios, :android].include?(platform)
end

.outputObject



116
117
118
119
120
# File 'lib/fastlane/plugin/lambdatest/actions/upload_to_lambdatest.rb', line 116

def self.output
  [
    ['APP_URL', 'App URL of uploaded app.']
  ]
end

.run(params) ⇒ Object



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
# File 'lib/fastlane/plugin/lambdatest/actions/upload_to_lambdatest.rb', line 15

def self.run(params)
  lt_username = params[:lt_username] # Required
  lt_access_key = params[:lt_access_key] # Required
  file_path = params[:file_path].to_s # Required
  custom_id = params[:custom_id] # Optional
  app_name = params[:app_name]  #Optional
  visibility =  params[:visibility] #Optional

  validate_file_path(file_path)

  UI.message("Started Uploading app to Lambdatest...")

  lt_app_url = Helper::LambdatestHelper.upload_file(lt_username, lt_access_key, file_path, API_ENDPOINT, custom_id, app_name, visibility)

  # Set 'APP_URL' environment variable, if app upload was successful. 
  ENV['APP_URL'] = lt_app_url


  UI.success("Successfully uploaded app " + file_path + " to Lambdatest with app_url : " + lt_app_url + "")

  UI.success("Setting Environment variable APP_URL = " + lt_app_url)

  # Setting APP_URL in SharedValues, which can be used by other fastlane actions.
  Actions.lane_context[SharedValues::APP_URL] = lt_app_url
end

.validate_file_path(file_path) ⇒ Object

Validating file_path and extension.



42
43
44
45
46
47
48
# File 'lib/fastlane/plugin/lambdatest/actions/upload_to_lambdatest.rb', line 42

def self.validate_file_path(file_path)
  UI.user_error!("file not found at '#{file_path}' ❌ .") unless File.exist?(file_path)
  file_path_parts = file_path.split(".")
  unless file_path_parts.length > 1 && SUPPORTED_EXTENSIONS.include?(file_path_parts.last)
    UI.user_error!("Invalid file extension, only files with extensions " + SUPPORTED_EXTENSIONS.to_s + " are allowed to be uploaded.")
  end
end