Class: Fastlane::Actions::CopyArtifactsAction

Inherits:
Fastlane::Action show all
Defined in:
lib/fastlane/actions/copy_artifacts.rb

Documentation collapse

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, author, details, method_missing, other_action, output, return_value, sh, step_text

Class Method Details

.authorsObject



73
74
75
# File 'lib/fastlane/actions/copy_artifacts.rb', line 73

def self.authors
  ["lmirosevic"]
end

.available_optionsObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/fastlane/actions/copy_artifacts.rb', line 48

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :keep_original,
                                 description: "Set this to true if you want copy, rather than move, semantics",
                                 is_string: false,
                                 optional: true,
                                 default_value: true),
    FastlaneCore::ConfigItem.new(key: :target_path,
                                 description: "The directory in which you want your artifacts placed",
                                 is_string: false,
                                 optional: false,
                                 default_value: 'artifacts'),
    FastlaneCore::ConfigItem.new(key: :artifacts,
                                 description: "An array of file patterns of the files/folders you want to preserve",
                                 is_string: false,
                                 optional: false,
                                 default_value: []),
    FastlaneCore::ConfigItem.new(key: :fail_on_missing,
                                 description: "Fail when a source file isn't found",
                                 is_string: false,
                                 optional: true,
                                 default_value: false)
  ]
end

.descriptionObject



44
45
46
# File 'lib/fastlane/actions/copy_artifacts.rb', line 44

def self.description
  "Small action to save your build artifacts. Useful when you use reset_git_repo"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/fastlane/actions/copy_artifacts.rb', line 77

def self.is_supported?(platform)
  true
end

.run(params) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fastlane/actions/copy_artifacts.rb', line 7

def self.run(params)
  # we want to make sure that our target folder exist already
  FileUtils.mkdir_p(params[:target_path])

  # Ensure that artifacts is an array
  artifacts_to_search = [params[:artifacts]].flatten

  # If any of the paths include "*", we assume that we are referring to the Unix entries
  # e.g /tmp/fastlane/* refers to all the files in /tmp/fastlane
  # We use Dir.glob to expand all those paths, this would create an array of arrays though, so flatten
  # Lastly, we shell escape everything in case they contain incompatible symbols (e.g. spaces)
  artifacts = artifacts_to_search.map { |f| f.include?("*") ? Dir.glob(f) : f }.flatten.map(&:shellescape)

  UI.verbose("Copying artifacts #{artifacts.join(', ')} to #{params[:target_path]}")
  UI.verbose(params[:keep_original] ? "Keeping original files" : "Not keeping original files")

  if params[:fail_on_missing]
    missing = artifacts.select { |a| !File.exist?(a) }
    UI.user_error! "Not all files were present in copy artifacts. Missing #{missing.join(', ')}" unless missing.empty?
  else
    # If we don't fail on non-existant files, don't try to copy non-existant files
    artifacts.reject! { |artifact| !File.exist?(artifact) }
  end

  if params[:keep_original]
    FileUtils.cp_r(artifacts, params[:target_path], remove_destination: true)
  else
    FileUtils.mv(artifacts, params[:target_path], force: true)
  end

  UI.success('Build artifacts successfully copied!')
end