Skip to content

Instantly share code, notes, and snippets.

@lifely
Created January 11, 2022 15:26
Show Gist options
  • Save lifely/7f8b68bb3f1fed31da8c1a8aff93ae6b to your computer and use it in GitHub Desktop.
Save lifely/7f8b68bb3f1fed31da8c1a8aff93ae6b to your computer and use it in GitHub Desktop.
Fastlane fix for archives.
fastlane_require('plist')
fastlane_require('gym')
fastlane_require('pp')
fastlane_require('tiny_url')
class Gym::Runner
# The only way to run my custom method after the pod integrates with the project (http://blog.bigbinary.com/2012/01/08/alias-vs-alias-method.html)
# Repace the method implementation integrate_user_project with ours
alias_method :verify_archive_legacy, :verify_archive
# singleton_class.send(:alias_method, :verify_archive_legacy, :verify_archive)
# Makes sure the archive is there and valid
def verify_archive
archive_path = Gym::BuildCommandGenerator.archive_path
puts archive_path
if Dir[archive_path + "/*"].count == 0
ErrorHandler.handle_empty_archive
end
archive_info_path = archive_path + "/Info.plist"
archive_info = Plist.parse_xml(archive_info_path)
puts "Archive Infos: "
pp(archive_info)
archive_product_paths = Dir[archive_path + "/Products/*/*.app"]
if archive_info.has_key?("ApplicationProperties") == false && archive_product_paths.first
archive_app_info = parse_binary_plist(archive_product_paths.first)
required_keys = ["CFBundleIdentifier", "CFBundleVersion", "CFBundleShortVersionString"]
appProperties = archive_app_info.slice(*required_keys)
appProperties["ApplicationPath"] = archive_product_paths.first.delete_prefix(archive_path + "/Products/")
archive_info["ApplicationProperties"] = appProperties
updated_archive_info = Plist::Emit.dump(archive_info)
File.write(archive_info_path, updated_archive_info)
puts "Updated Archive Infos: "
puts updated_archive_info
end
archive_info = Plist.parse_xml(archive_info_path)
if (archive_info.has_key?("ApplicationProperties") == false)
Gym::ErrorHandler.handle_empty_archive
end
end
def parse_binary_plist(application_path)
data = File.read(application_path + "/Info.plist")
# Creates a temporary directory with a unique name tagged with 'fastlane'
# The directory is deleted automatically at the end of the block
Dir.mktmpdir("fastlane") do |tmp|
# The XML file has to be properly unpacked first
tmp_path = File.join(tmp, "Info.plist")
File.open(tmp_path, 'wb') do |output|
output.write(data)
end
result = CFPropertyList.native_types(CFPropertyList::List.new(file: tmp_path).value)
if result['CFBundleIdentifier'] || result['CFBundleVersion']
return result
end
end
return nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment