From 2a23dcea668096462ce6eebb0182a19839b4ac16 Mon Sep 17 00:00:00 2001 From: petropavel13 Date: Thu, 15 Oct 2020 12:26:49 +0300 Subject: [PATCH] Merge pull request #231 from TouchInstinct/feature/match_local_storage match local storage # Conflicts: # xcode/commonFastfile --- .DS_Store | Bin 0 -> 6148 bytes xcode/commonFastfile | 59 +++++++------ .../lib/match/storage/local_storage.rb | 82 ++++++++++++++++++ xcode/fastlane/touchlane/lib/touchlane.rb | 5 +- .../lib/{ => touchlane}/configuration.rb | 0 .../lib/{ => touchlane}/configuration_type.rb | 0 6 files changed, 119 insertions(+), 27 deletions(-) create mode 100644 .DS_Store create mode 100644 xcode/fastlane/touchlane/lib/match/storage/local_storage.rb rename xcode/fastlane/touchlane/lib/{ => touchlane}/configuration.rb (100%) rename xcode/fastlane/touchlane/lib/{ => touchlane}/configuration_type.rb (100%) diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..088c7b494dd7875ad60c62d2c74406767b9eeaa4 GIT binary patch literal 6148 zcmeHKI|>3Z5S{S@f{mqRuHX%V=n3`$f{KkO2#V!ap39^8=F=>TofgU)n7m{%FCnkk z*%1+4UUv(TnTSl_hVrnXZ?xe! V*akWsai;_MGhn*VsKB=scmev_6utle literal 0 HcmV?d00001 diff --git a/xcode/commonFastfile b/xcode/commonFastfile index f9f6d50..04671fd 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -2,6 +2,14 @@ $appName = File.basename(Dir['../*.xcworkspace'].first, '.*') require_relative 'fastlane/touchlane/lib/touchlane' +# ugly hack to add support for custom storage + +Match.module_eval do + def self.storage_modes + return %w(git google_cloud s3 local) + end +end + private_lane :installDependencies do |options| podsReposPath = File.expand_path "~/.cocoapods/repos/master/" lockFilePath = "#{podsReposPath}/.git/index.lock" @@ -271,25 +279,18 @@ private_lane :openKeychain do |options| end lane :ManuallyUpdateCodeSigning do |options| - # based on this article https://medium.com/@jonathancardoso/using-fastlane-match-with-existing-certificates-without-revoking-them-a325be69dac6 - require 'fastlane_core' + register_local_storage_for_match() + require 'match' - conf = FastlaneCore::Configuration.create(Match::Options.available_options, {}) - conf.load_configuration_file("Matchfile") - - git_url = conf.config_file_options[:git_url] - shallow_clone = false - branch = 'fastlane_certificates' - - storage_conf = lambda do - new_storage = Match::Storage.for_mode('git', { git_url: git_url, shallow_clone: shallow_clone, git_branch: branch, clone_branch_directly: false}) + storage_factory = lambda do + new_storage = Match::Storage.for_mode('local', { git_url: get_signing_identities_path() }) new_storage.download return new_storage end - encryption_conf_for_storage = lambda do |stor| - new_encryption = Match::Encryption.for_storage_mode('git', { git_url: git_url, working_directory: stor.working_directory}) + encryption_factory = lambda do |stor| + new_encryption = Match::Encryption.for_storage_mode('local', { working_directory: stor.working_directory }) new_encryption.decrypt_files return new_encryption end @@ -298,8 +299,8 @@ lane :ManuallyUpdateCodeSigning do |options| Dir[File.join(stor.working_directory, "**", "*.{cer,p12,mobileprovision}")] end - storage = storage_conf.call - encryption = encryption_conf_for_storage.call(storage) + storage = storage_factory.call + encryption = encryption_factory.call(storage) old_files = get_all_files.call(storage) sh("open #{storage.working_directory}") @@ -322,8 +323,8 @@ lane :ManuallyUpdateCodeSigning do |options| # to avoid this we use storage twice if needed if files_diff.length > 0 - storage = storage_conf.call - encryption = encryption_conf_for_storage.call(storage) + storage = storage_factory.call + encryption = encryption_factory.call(storage) files_to_delete = files_diff.map do |file| old_file = file @@ -340,24 +341,32 @@ lane :ManuallyUpdateCodeSigning do |options| end def sync_code_signing_using_options(options) + register_local_storage_for_match() + match( app_identifier: options[:app_identifier], username: options[:username] || options[:apple_id], team_id: options[:team_id], type: options[:type], readonly: options[:readonly].nil? ? true : options[:readonly], - storage_mode: "git", - git_url: options[:git_url], - git_branch: "fastlane_certificates", - shallow_clone: true, - clone_branch_directly: true, - keychain_name: options[:keychain_name], - keychain_password: options[:keychain_password], + storage_mode: "local", + # we can't pass signing_identities_path as parameter name since params is hardcoded in match/runner.rb + git_url: get_signing_identities_path(), skip_docs: true, - platform: "ios" + keychain_name: options[:keychain_name], + keychain_password: options[:keychain_password] ) end +def register_local_storage_for_match + Match::Storage.register_backend(type: 'local', storage_class: Touchlane::LocalStorage) + Match::Encryption.register_backend(type: 'local', encryption_class: Match::Encryption::OpenSSL) +end + +def get_signing_identities_path + File.expand_path "../EncryptedSigningIdentities" +end + def fill_up_options_using_configuration_type(options, configuration_type) configuration = get_configuration_for_type(configuration_type.type) diff --git a/xcode/fastlane/touchlane/lib/match/storage/local_storage.rb b/xcode/fastlane/touchlane/lib/match/storage/local_storage.rb new file mode 100644 index 0000000..f2ed2bd --- /dev/null +++ b/xcode/fastlane/touchlane/lib/match/storage/local_storage.rb @@ -0,0 +1,82 @@ +require 'match' +require 'fileutils' +require 'fastlane_core/ui/ui' + +module Touchlane + class LocalStorage < Match::Storage::Interface + attr_accessor :signing_identities_path + + def self.configure(params) + return self.new( + # we can't pass signing_identities_path since params is hardcoded in match/runner.rb + signing_identities_path: params[:git_url] + ) + end + + def initialize(signing_identities_path: nil) + self.signing_identities_path = signing_identities_path + end + + def prefixed_working_directory + return working_directory + end + + def download + # Check if we already have a functional working_directory + return if @working_directory + + # No existing working directory, creating a new one now + self.working_directory = Dir.mktmpdir + + Dir.mkdir(self.signing_identities_path) unless File.exists?(self.signing_identities_path) + + FileUtils.cp_r("#{self.signing_identities_path}/.", self.working_directory) + end + + def human_readable_description + "Local folder [#{self.signing_identities_path}]" + end + + def upload_files(files_to_upload: [], custom_message: nil) + # `files_to_upload` is an array of files that need to be moved to signing identities dir + # Those doesn't mean they're new, it might just be they're changed + # Either way, we'll upload them using the same technique + + Dir.mkdir(self.signing_identities_path) unless File.exists?(self.signing_identities_path) + + files_to_upload.each do |current_file| + # Go from + # "/var/folders/px/bz2kts9n69g8crgv4jpjh6b40000gn/T/d20181026-96528-1av4gge/profiles/development/Development_me.mobileprovision" + # to + # "profiles/development/Development_me.mobileprovision" + # + + # We also have to remove the trailing `/` as Google Cloud doesn't handle it nicely + target_path = current_file.gsub(self.working_directory + "/", "") + FileUtils.cp_r(current_file, File.join(self.signing_identities_path, target_path), remove_destination: true) + end + end + + def delete_files(files_to_delete: [], custom_message: nil) + files_to_delete.each do |file_name| + target_path = file_name.gsub(self.working_directory + "/", "") + File.delete(File.join(self.signing_identities_path, target_path)) + end + end + + def skip_docs + false + end + + def list_files(file_name: "", file_ext: "") + Dir[File.join(working_directory, "**", file_name, "*.#{file_ext}")] + end + + def generate_matchfile_content + path = Fastlane::UI.input("Path to the signing identities folder: ") + + return "git_url(\"#{path}\")" + end + + end +end diff --git a/xcode/fastlane/touchlane/lib/touchlane.rb b/xcode/fastlane/touchlane/lib/touchlane.rb index 8038507..f366ab1 100644 --- a/xcode/fastlane/touchlane/lib/touchlane.rb +++ b/xcode/fastlane/touchlane/lib/touchlane.rb @@ -1,4 +1,5 @@ module Touchlane - require_relative "configuration_type" - require_relative "configuration" + require_relative "touchlane/configuration_type" + require_relative "touchlane/configuration" + require_relative "match/storage/local_storage" end \ No newline at end of file diff --git a/xcode/fastlane/touchlane/lib/configuration.rb b/xcode/fastlane/touchlane/lib/touchlane/configuration.rb similarity index 100% rename from xcode/fastlane/touchlane/lib/configuration.rb rename to xcode/fastlane/touchlane/lib/touchlane/configuration.rb diff --git a/xcode/fastlane/touchlane/lib/configuration_type.rb b/xcode/fastlane/touchlane/lib/touchlane/configuration_type.rb similarity index 100% rename from xcode/fastlane/touchlane/lib/configuration_type.rb rename to xcode/fastlane/touchlane/lib/touchlane/configuration_type.rb