From d0f6f7d6a89019f35282287b7d6d3ab9237272ed Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Tue, 13 Oct 2020 17:25:06 +0300 Subject: [PATCH] add local storage (project folder) type for match --- xcode/commonFastfile | 26 ++++-- .../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 5 files changed, 103 insertions(+), 10 deletions(-) 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/xcode/commonFastfile b/xcode/commonFastfile index 8564ade..d9ef852 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" @@ -339,21 +347,23 @@ lane :ManuallyUpdateCodeSigning do |options| end def sync_code_signing_using_options(options) + Match::Storage.register_backend(type: 'local', storage_class: Touchlane::LocalStorage) + Match::Encryption.register_backend(type: 'local', encryption_class: Match::Encryption::OpenSSL) + + signing_identities_path = File.expand_path "../EncryptedSigningIdentities" + 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: signing_identities_path, skip_docs: true, - platform: "ios" + keychain_name: options[:keychain_name], + keychain_password: options[:keychain_password] ) end 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..c8751e6 --- /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 = current_file.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