Class: Fastlane::Actions::BackupXcarchiveAction

Inherits:
Fastlane::Action show all
Defined in:
fastlane/lib/fastlane/actions/backup_xcarchive.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, authors, deprecated_notes, details, lane_context, method_missing, other_action, return_type, return_value, sample_return_value, shell_out_should_use_bundle_exec?, step_text

Class Method Details

.authorObject



110
111
112
# File 'fastlane/lib/fastlane/actions/backup_xcarchive.rb', line 110

def self.author
  ['dral3x']
end

.available_optionsObject



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
92
93
94
95
96
97
98
99
100
101
102
# File 'fastlane/lib/fastlane/actions/backup_xcarchive.rb', line 66

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],
                                 default_value_dynamic: true,
                                 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',
                                 type: Boolean,
                                 default_value: true,
                                 optional: true,
                                 env_name: 'BACKUP_XCARCHIVE_ZIP'),
    FastlaneCore::ConfigItem.new(key: :zip_filename,
                                 description: 'Filename of the compressed archive. Will be appended by `.xcarchive.zip`. Default value is the output xcarchive filename',
                                 default_value_dynamic: true,
                                 optional: true,
                                 env_name: 'BACKUP_XCARCHIVE_ZIP_FILENAME'),
    FastlaneCore::ConfigItem.new(key: :versioned,
                                 description: 'Create a versioned (date and app version) subfolder where to put the archive',
                                 type: Boolean,
                                 default_value: true,
                                 optional: true,
                                 env_name: 'BACKUP_XCARCHIVE_VERSIONED')
  ]
end

.categoryObject



130
131
132
# File 'fastlane/lib/fastlane/actions/backup_xcarchive.rb', line 130

def self.category
  :misc
end

.descriptionObject



62
63
64
# File 'fastlane/lib/fastlane/actions/backup_xcarchive.rb', line 62

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

.example_codeObject



118
119
120
121
122
123
124
125
126
127
128
# File 'fastlane/lib/fastlane/actions/backup_xcarchive.rb', line 118

def self.example_code
  [
    'backup_xcarchive(
      xcarchive: "/path/to/file.xcarchive", # Optional if you use the `xcodebuild` action
      destination: "/somewhere/else/", # Where the backup should be created
      zip_filename: "file.xcarchive", # The name of the backup file
      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
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:



114
115
116
# File 'fastlane/lib/fastlane/actions/backup_xcarchive.rb', line 114

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

.outputObject



104
105
106
107
108
# File 'fastlane/lib/fastlane/actions/backup_xcarchive.rb', line 104

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
52
53
54
55
56
# File 'fastlane/lib/fastlane/actions/backup_xcarchive.rb', line 10

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

  # Prepare destination 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 = if zip_filename
                   File.join(dir, "#{zip_filename}.xcarchive.zip")
                 else
                   File.join(dir, "#{xcarchive_file}.zip")
                 end

      # Create zip
      Actions.sh(%(cd "#{xcarchive_folder}" && zip -r -X -y "#{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