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, output, return_value, sh, step_text

Class Method Details

.authorsObject



61
62
63
# File 'lib/fastlane/actions/copy_artifacts.rb', line 61

def self.authors
  ["lmirosevic"]
end

.available_optionsObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/fastlane/actions/copy_artifacts.rb', line 36

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



32
33
34
# File 'lib/fastlane/actions/copy_artifacts.rb', line 32

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

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/fastlane/actions/copy_artifacts.rb', line 65

def self.is_supported?(platform)
  true
end

.run(params) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fastlane/actions/copy_artifacts.rb', line 4

def self.run(params)
  # we want to make sure that our target folder exist already
  target_folder_command = 'mkdir -p ' + params[:target_path]
  Actions.sh(target_folder_command)

  # construct the main command that will do the copying/moving for us
  base_command = params[:keep_original] ? 'cp' : 'mv'
  options = []
  options << '-f'
  options << '-R' if params[:keep_original] # we only want the -R flag for the cp command, which we get when the user asks to keep the original
  options << params[:artifacts].map { |e| e.tr(' ', '\ ') }
  options << params[:target_path]

  command = ([base_command] + options).join(' ')

  # if we don't want to fail on missing files, then we need to swallow the error from our command, by ORing with the nil command, guaranteeing a 0 status code
  command += ' || :' unless params[:fail_on_missing]

  # call our command
  Actions.sh(command)

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