Class: Fastlane::Actions::ZipAction

Inherits:
Fastlane::Action show all
Defined in:
fastlane/lib/fastlane/actions/zip.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, sample_return_value, shell_out_should_use_bundle_exec?, step_text

Class Method Details

.authorsObject



92
93
94
# File 'fastlane/lib/fastlane/actions/zip.rb', line 92

def self.authors
  ["KrauseFx"]
end

.available_optionsObject



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

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :path,
                                 env_name: "FL_ZIP_PATH",
                                 description: "Path to the directory or file to be zipped",
                                 verify_block: proc do |value|
                                   UI.user_error!("Couldn't find file/folder at path '#{File.expand_path(value)}'") unless File.exist?(value)
                                 end),
    FastlaneCore::ConfigItem.new(key: :output_path,
                                 env_name: "FL_ZIP_OUTPUT_NAME",
                                 description: "The name of the resulting zip file",
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :verbose,
                                 env_name: "FL_ZIP_VERBOSE",
                                 description: "Enable verbose output of zipped file",
                                 default_value: true,
                                 type: Boolean,
                                 optional: true)
  ]
end

.categoryObject



76
77
78
# File 'fastlane/lib/fastlane/actions/zip.rb', line 76

def self.category
  :misc
end

.descriptionObject



33
34
35
# File 'fastlane/lib/fastlane/actions/zip.rb', line 33

def self.description
  "Compress a file or folder to a zip"
end

.detailsObject



37
38
# File 'fastlane/lib/fastlane/actions/zip.rb', line 37

def self.details
end

.example_codeObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'fastlane/lib/fastlane/actions/zip.rb', line 61

def self.example_code
  [
    'zip',
    'zip(
      path: "MyApp.app",
      output_path: "Latest.app.zip"
    )',
    'zip(
      path: "MyApp.app",
      output_path: "Latest.app.zip",
      verbose: false
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:



96
97
98
# File 'fastlane/lib/fastlane/actions/zip.rb', line 96

def self.is_supported?(platform)
  true
end

.outputObject



80
81
82
# File 'fastlane/lib/fastlane/actions/zip.rb', line 80

def self.output
  []
end

.return_typeObject



88
89
90
# File 'fastlane/lib/fastlane/actions/zip.rb', line 88

def self.return_type
  :string
end

.return_valueObject



84
85
86
# File 'fastlane/lib/fastlane/actions/zip.rb', line 84

def self.return_value
  "The path to the output zip file"
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
27
# File 'fastlane/lib/fastlane/actions/zip.rb', line 4

def self.run(params)
  UI.message("Compressing #{params[:path]}...")

  params[:output_path] ||= params[:path]

  absolute_output_path = File.expand_path(params[:output_path])

  # Appends ".zip" if path does not end in ".zip"
  unless absolute_output_path.end_with?(".zip")
    absolute_output_path += ".zip"
  end

  absolute_output_dir = File.expand_path("..", absolute_output_path)
  FileUtils.mkdir_p(absolute_output_dir)

  Dir.chdir(File.expand_path("..", params[:path])) do # required to properly zip
    zip_options = params[:verbose] ? "r" : "rq"

    Actions.sh("zip -#{zip_options} #{absolute_output_path.shellescape} #{File.basename(params[:path]).shellescape}")
  end

  UI.success("Successfully generated zip file at path '#{File.expand_path(absolute_output_path)}'")
  return File.expand_path(absolute_output_path)
end