Commit 62976b9a authored by Vadim Vlasov's avatar Vadim Vlasov

Added restore_cache and try_update_cache

parent 790f13ad
module Fastlane
module Actions
class RestoreCacheAction < Action
def self.run(params)
if params[:ignore_cache]
UI.message("Skipping cache restoration.")
return
end
directory = params[:directory]
cache_storage_path = params[:cache_storage_path]
if Dir.exist?(cache_storage_path)
UI.message("Restoring cache...")
output = `rsync -a --delete #{cache_storage_path}/ #{directory}/`
puts output unless output.strip.empty?
UI.message("Cache restored from #{cache_storage_path}")
else
UI.message("Cache directory not found. Skipping cache restoration.")
end
end
def self.description
"Restores the cache from a specified storage path to a local directory"
end
def self.authors
["Vadim Vlasov"]
end
def self.available_options
[
FastlaneCore::ConfigItem.new(key: :directory,
description: "Local directory where the cache will be restored",
optional: true,
default_value: "Library",
type: String),
FastlaneCore::ConfigItem.new(key: :cache_storage_path,
optional: true,
default_value: "#{Dir.home}/Data/Cache/#{ENV['CI_PROJECT_PATH_SLUG']}/Library",
env_name: "CACHE_STORAGE_PATH",
description: "Storage path from where the cache will be restored",
type: String),
FastlaneCore::ConfigItem.new(key: :ignore_cache,
env_name: "IGNORE_CACHE",
description: "If set, cache restoration will be skipped",
optional: true,
is_string: false,
default_value: false)
]
end
def self.is_supported?(platform)
true
end
end
end
end
\ No newline at end of file
module Fastlane
module Actions
class TryUpdateCacheAction < Action
def self.run(params)
if params[:ignore_cache]
UI.message("Skipping cache restoration.")
return
end
branch = `git rev-parse --abbrev-ref HEAD`.strip
allowed_update_branches = params[:allowed_update_branches]
directory = params[:directory]
cache_storage_path = params[:cache_storage_path]
if allowed_update_branches.include?(branch)
UI.message("Updating cache...")
# Create cache storage directory if it doesn't exist
FileUtils.mkdir_p(cache_storage_path) unless Dir.exist?(cache_storage_path)
output = `rsync -a --delete #{directory}/ #{cache_storage_path}/`
puts output unless output.strip.empty?
UI.message("Cache saved in #{cache_storage_path}")
else
UI.message("Cache not updated as the branch is not in the allowed update list")
end
end
def self.description
"Saves the cache from a local directory to a specified storage path if the current branch is allowed"
end
def self.authors
["Vadim Vlasov"]
end
def self.available_options
[
FastlaneCore::ConfigItem.new(key: :allowed_update_branches,
description: "List of branches that are allowed to update the cache",
optional: true,
default_value: ["develop", "feature/cicd-cache-library"],
type: Array),
FastlaneCore::ConfigItem.new(key: :directory,
description: "Local directory from which the cache will be saved",
optional: true,
default_value: "Library",
type: String),
FastlaneCore::ConfigItem.new(key: :cache_storage_path,
description: "Storage path where the cache will be saved",
optional: true,
default_value: "#{Dir.home}/Data/Cache/#{ENV['CI_PROJECT_PATH_SLUG']}/Library",
env_name: "CACHE_STORAGE_PATH",
type: String),
FastlaneCore::ConfigItem.new(key: :ignore_cache,
env_name: "IGNORE_CACHE",
description: "If set, cache restoration will be skipped",
optional: true,
is_string: false,
default_value: false)
]
end
def self.is_supported?(platform)
true
end
end
end
end
\ No newline at end of file
module Fastlane module Fastlane
module Furylion module Furylion
VERSION = "1.1.3" VERSION = "1.1.4"
end end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment