Skip to content

Commit

Permalink
Decoupled Waldo Go CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
eBardX committed Apr 13, 2022
1 parent 014f535 commit 03594ba
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 36 deletions.
Binary file removed lib/fastlane/plugin/waldo/assets/waldo-linux-arm64
Binary file not shown.
Binary file removed lib/fastlane/plugin/waldo/assets/waldo-linux-x86_64
Binary file not shown.
Binary file removed lib/fastlane/plugin/waldo/assets/waldo-macos-arm64
Binary file not shown.
Binary file removed lib/fastlane/plugin/waldo/assets/waldo-macos-x86_64
Binary file not shown.
Binary file not shown.
Binary file not shown.
109 changes: 74 additions & 35 deletions lib/fastlane/plugin/waldo/helper/waldo_helper.rb
@@ -1,6 +1,74 @@
module Fastlane
module Helper
class WaldoHelper
require 'net/http'

def self.determine_asset_name
platform = RUBY_PLATFORM.downcase

if platform.include?('linux')
ext = ''
os = 'linux'
elsif platform.include?('darwin')
ext = ''
os = 'macos'
elsif platform.include?('mswin')
ext = '.exe'
os = 'windows'
else
UI.error("Unsupported platform: #{platform}")
end

if platform.include?('arm64')
arch = 'arm64'
elsif platform.include?('x86_64')
arch = 'x86_64'
else
UI.error("Unsupported platform: #{platform}")
end

"waldo-#{os}-#{arch}#{ext}"
end

def self.download(uri, path)
begin
request_uri = uri.request_uri
response = nil

loop do
response = Net::HTTP.get_response(uri)

break unless response.is_a?(Net::HTTPRedirection)

uri = URI.parse(response['location'])
end

fp = File.open(path, 'wb')

fp.write(response.body)
rescue => exc
UI.error("Unable to download #{request_uri}: #{exc.inspect.to_s}")
ensure
fp.close if fp
end
end

def self.download_binary
asset_name = determine_asset_name

uri_string = 'https://github.com/waldoapp/waldo-go-cli/releases/latest/download/'

uri_string += asset_name

binary_path = File.join(Dir.tmpdir, 'waldo')

download(URI(uri_string), binary_path)

File.chmod(0755, binary_path)

binary_path
end

def self.filter_parameters(in_params)
out_params = {}

Expand All @@ -12,9 +80,9 @@ def self.filter_parameters(in_params)
upload_token = in_params[:upload_token]
variant_name = in_params[:variant_name] || Actions.lane_context[Actions::SharedValues::GRADLE_BUILD_TYPE]

apk_path.gsub!("\\ ", ' ') if apk_path
app_path.gsub!("\\ ", ' ') if app_path
ipa_path.gsub!("\\ ", ' ') if ipa_path
apk_path.gsub!('\\ ', ' ') if apk_path
app_path.gsub!('\\ ', ' ') if app_path
ipa_path.gsub!('\\ ', ' ') if ipa_path

out_params[:apk_path] = apk_path if apk_path

Expand Down Expand Up @@ -49,35 +117,6 @@ def self.filter_parameters(in_params)
out_params
end

def self.get_binary_path
platform = RUBY_PLATFORM.downcase

if platform.include?("linux")
ext = ""
os = "linux"
elsif platform.include?("darwin")
ext = ""
os = "macos"
elsif platform.include?("mswin")
ext = ".exe"
os = "windows"
else
UI.error("Unsupported platform: #{platform}")
end

if platform.include?("arm64")
arch = "arm64"
elsif platform.include?("x86_64")
arch = "x86_64"
else
UI.error("Unsupported platform: #{platform}")
end

root = Pathname.new(File.expand_path('../../..', __FILE__))

File.join(root, "waldo", "assets", "waldo-#{os}-#{arch}#{ext}")
end

def self.upload_build(params)
apk_path = params[:apk_path]
app_path = params[:app_path]
Expand All @@ -90,16 +129,16 @@ def self.upload_build(params)
elsif ipa_path
build_path = ipa_path
else
build_path = ""
build_path = ''
end

command = []

command << "WALDO_WRAPPER_NAME_OVERRIDE='Fastlane'"
command << "WALDO_WRAPPER_VERSION_OVERRIDE='#{Fastlane::Waldo::VERSION}'"

command << get_binary_path.shellescape
command << "upload"
command << download_binary.shellescape
command << 'upload'

if params[:git_branch]
command << '--git_branch'
Expand Down
2 changes: 1 addition & 1 deletion lib/fastlane/plugin/waldo/version.rb
@@ -1,5 +1,5 @@
module Fastlane
module Waldo
VERSION = "3.0.1"
VERSION = "3.1.0"
end
end

0 comments on commit 03594ba

Please sign in to comment.