Update Fastfile

This commit is contained in:
Marcos Rodriguez Velez 2024-09-05 15:40:28 -04:00
parent d4f6a50fb3
commit a5c8eddde4

View File

@ -81,47 +81,52 @@ end
lane :upload_to_browserstack_and_comment do lane :upload_to_browserstack_and_comment do
Dir.chdir(project_root) do Dir.chdir(project_root) do
# Download the artifact if necessary # Download the artifact if necessary
apk_path = ENV['APK_PATH'] apk_path = ENV['APK_PATH']
if apk_path.nil? || apk_path.empty? if apk_path.nil? || apk_path.empty?
UI.message("No APK path provided, attempting to download the artifact...") UI.message("No APK path provided, attempting to download the artifact...")
apk_path = `find ./ -name "*.apk"`.strip apk_path = `find ./ -name "*.apk"`.strip
UI.user_error!("No APK file found after downloading the artifact") if apk_path.nil? || apk_path.empty? UI.user_error!("No APK file found after downloading the artifact") if apk_path.nil? || apk_path.empty?
end end
UI.message("Uploading APK to BrowserStack: #{apk_path}...") UI.message("Uploading APK to BrowserStack: #{apk_path}...")
upload_to_browserstack_app_live( upload_to_browserstack_app_live(
file_path: apk_path, file_path: apk_path,
browserstack_username: ENV['BROWSERSTACK_USERNAME'], browserstack_username: ENV['BROWSERSTACK_USERNAME'],
browserstack_access_key: ENV['BROWSERSTACK_ACCESS_KEY'] browserstack_access_key: ENV['BROWSERSTACK_ACCESS_KEY']
) )
# Extract the BrowserStack URL from the output # Extract the BrowserStack URL from the output
app_url = ENV['BROWSERSTACK_LIVE_APP_ID'] app_url = ENV['BROWSERSTACK_LIVE_APP_ID']
# Extract the filename from the APK path # Extract the filename from the APK path
apk_filename = File.basename(apk_path) apk_filename = File.basename(apk_path)
pr_number = ENV['GITHUB_PR_NUMBER'] # Remove 'bs://' from the app_url
browserstack_hashed_id = app_url.gsub('bs://', '')
comment = <<~COMMENT pr_number = ENV['GITHUB_PR_NUMBER']
APK successfully uploaded to BrowserStack. You can test it using the following URL:
#{app_url}
Filename: #{apk_filename} # Construct the comment content
COMMENT comment = <<~COMMENT
APK successfully uploaded to BrowserStack. You can test it using the following URL:
https://app-live.browserstack.com/dashboard#os=android&os_version=12.0&device=Google+Pixel+5&app_hashed_id=#{browserstack_hashed_id}&scale_to_fit=true&speed=1&start=true
Filename: #{apk_filename}
COMMENT
# Post the comment to the PR # Post the comment to the PR
if pr_number if pr_number
sh("GH_TOKEN=#{ENV['GH_TOKEN']} gh pr comment #{pr_number} --body '#{comment}'") sh("GH_TOKEN=#{ENV['GH_TOKEN']} gh pr comment #{pr_number} --body '#{comment}'")
else else
UI.important("No PR number found. Skipping PR comment.") UI.important("No PR number found. Skipping PR comment.")
end
end end
end end
end end
end
platform :ios do platform :ios do