Class: Fastlane::Actions::BackupXcarchiveAction

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

Constant Summary

Constants inherited from Fastlane::Action

Fastlane::Action::AVAILABLE_CATEGORIES

Documentation collapse

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, authors, details, lane_context, method_missing, other_action, return_value, sample_return_value, sh, step_text

Class Method Details

.authorObject



99
100
101
# File 'lib/fastlane/actions/backup_xcarchive.rb', line 99

def self.author
  ['dral3x']
end

.available_optionsObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/fastlane/actions/backup_xcarchive.rb', line 61

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :xcarchive,
                                 description: 'Path to your xcarchive file. Optional if you use the `xcodebuild` action',
                                 default_value: Actions.lane_context[SharedValues::XCODEBUILD_ARCHIVE],
                                 optional: false,
                                 env_name: 'BACKUP_XCARCHIVE_ARCHIVE',
                                 verify_block: proc do |value|
                                   UI.user_error!("Couldn't find xcarchive file at path '#{value}'") if !Helper.test? && !File.exist?(value)
                                 end),
    FastlaneCore::ConfigItem.new(key: :destination,
                                 description: 'Where your archive will be placed',
                                 optional: false,
                                 env_name: 'BACKUP_XCARCHIVE_DESTINATION',
                                 verify_block: proc do |value|
                                   UI.user_error!("Couldn't find the destination folder at '#{value}'") if !Helper.test? && !File.directory?(value) && !File.exist?(value)
                                 end),
    FastlaneCore::ConfigItem.new(key: :zip,
                                 description: 'Enable compression of the archive. Default value `true`',
                                 is_string: false,
                                 default_value: true,
                                 optional: true,
                                 env_name: 'BACKUP_XCARCHIVE_ZIP'),
    FastlaneCore::ConfigItem.new(key: :versioned,
                                 description: 'Create a versioned (date and app version) subfolder where to put the archive. Default value `true`',
                                 is_string: false,
                                 default_value: true,
                                 optional: true,
                                 env_name: 'BACKUP_XCARCHIVE_VERSIONED')
  ]
end

.categoryObject



118
119
120
# File 'lib/fastlane/actions/backup_xcarchive.rb', line 118

def self.category
  :misc
end

.descriptionObject



57
58
59
# File 'lib/fastlane/actions/backup_xcarchive.rb', line 57

def self.description
  "Save your [zipped] xcarchive elsewhere from default path"
end

.example_codeObject



107
108
109
110
111
112
113
114
115
116
# File 'lib/fastlane/actions/backup_xcarchive.rb', line 107

def self.example_code
  [
    'backup_xcarchive(
      xcarchive: "/path/to/file.xcarchive", # Optional if you use the `xcodebuild` action
      destination: "/somewhere/else/file.xcarchive", # Where the backup should be created
      zip: false, # Enable compression of the archive. Defaults to `true`.
      versioned: true # Create a versioned (date and app version) subfolder where to put the archive. Default value `true`
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/fastlane/actions/backup_xcarchive.rb', line 103

def self.is_supported?(platform)
  [:ios, :mac].include? platform
end

.outputObject



93
94
95
96
97
# File 'lib/fastlane/actions/backup_xcarchive.rb', line 93

def self.output
  [
    ['BACKUP_XCARCHIVE_FILE', 'Path to your saved xcarchive (compressed) file']
  ]
end

.run(params) ⇒ Object



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
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fastlane/actions/backup_xcarchive.rb', line 10

def self.run(params)
  # Get params
  xcarchive = params[:xcarchive]
  base_destination = params[:destination]
  zipped = params[:zip]
  versioned = params[:versioned]

  # Prepare destionation folder
  full_destination = base_destination

  if versioned
    date = Time.now.strftime("%Y-%m-%d")
    version = `agvtool what-marketing-version -terse1`
    subfolder = "#{date} #{version.strip}"
    full_destination = File.expand_path(subfolder, base_destination)
  end

  FileUtils.mkdir(full_destination) unless File.exist?(full_destination)

  # Save archive to destination
  if zipped
    Dir.mktmpdir("backup_xcarchive") do |dir|
      UI.message("Compressing #{xcarchive}")
      xcarchive_folder = File.expand_path(File.dirname(xcarchive))
      xcarchive_file = File.basename(xcarchive)
      zip_file = File.join(dir, "#{xcarchive_file}.zip")

      # Create zip
      Actions.sh(%(cd "#{xcarchive_folder}" && zip -r -X "#{zip_file}" "#{xcarchive_file}" > /dev/null))

      # Moved to its final destination
      FileUtils.mv(zip_file, full_destination)

      Actions.lane_context[SharedValues::BACKUP_XCARCHIVE_FILE] = "#{full_destination}/#{File.basename(zip_file)}"
    end
  else
    # Copy xcarchive file
    FileUtils.cp_r(xcarchive, full_destination)

    Actions.lane_context[SharedValues::BACKUP_XCARCHIVE_FILE] = "#{full_destination}/#{File.basename(xcarchive)}"
  end
end