Class: Fastlane::Actions::CopyArtifactsAction

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

Constant Summary

Constants inherited from Fastlane::Action

Fastlane::Action::AVAILABLE_CATEGORIES, Fastlane::Action::RETURN_TYPES

Documentation collapse

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, author, deprecated_notes, lane_context, method_missing, other_action, output, return_type, return_value, sample_return_value, shell_out_should_use_bundle_exec?, step_text

Class Method Details

.authorsObject


81
82
83
# File 'fastlane/lib/fastlane/actions/copy_artifacts.rb', line 81

def self.authors
  ["lmirosevic"]
end

.available_optionsObject


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'fastlane/lib/fastlane/actions/copy_artifacts.rb', line 56

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :keep_original,
                                 description: "Set this to false if you want move, rather than copy, the found artifacts",
                                 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

.categoryObject


109
110
111
# File 'fastlane/lib/fastlane/actions/copy_artifacts.rb', line 109

def self.category
  :misc
end

.descriptionObject


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

def self.description
  "Copy and save your build artifacts (useful when you use reset_git_repo)"
end

.detailsObject


49
50
51
52
53
54
# File 'fastlane/lib/fastlane/actions/copy_artifacts.rb', line 49

def self.details
  [
    "This action copies artifacts to a target directory. It's useful if you have a CI that will pick up these artifacts and attach them to the build. Useful e.g. for storing your `.ipa`s, `.dSYM.zip`s, `.mobileprovision`s, `.cert`s.",
    "Make sure your `:target_path` is ignored from git, and if you use `reset_git_repo`, make sure the artifacts are added to the exclude list."
  ].join("\n")
end

.example_codeObject


89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'fastlane/lib/fastlane/actions/copy_artifacts.rb', line 89

def self.example_code
  [
    'copy_artifacts(
      target_path: "artifacts",
      artifacts: ["*.cer", "*.mobileprovision", "*.ipa", "*.dSYM.zip", "path/to/file.txt", "another/path/*.extension"]
    )

    # Reset the git repo to a clean state, but leave our artifacts in place
    reset_git_repo(
      exclude: "artifacts"
    )',
    '# Copy the .ipa created by _gym_ if it was successfully created
    artifacts = []
    artifacts << lane_context[SharedValues::IPA_OUTPUT_PATH] if lane_context[SharedValues::IPA_OUTPUT_PATH]
    copy_artifacts(
       artifacts: artifacts
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:


85
86
87
# File 'fastlane/lib/fastlane/actions/copy_artifacts.rb', line 85

def self.is_supported?(platform)
  true
end

.run(params) ⇒ Object


6
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
39
# File 'fastlane/lib/fastlane/actions/copy_artifacts.rb', line 6

def self.run(params)
  # expand the path to make sure we can deal with relative paths
  target_path = File.expand_path(params[:target_path])

  # we want to make sure that our target folder exist already
  FileUtils.mkdir_p(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
  artifacts = artifacts_to_search.flat_map { |f| f.include?("*") ? Dir.glob(f) : f }

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

  if params[:fail_on_missing]
    missing = artifacts.reject { |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-existent files, don't try to copy non-existent files
    artifacts.select! { |artifact| File.exist?(artifact) }
  end

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

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