Class: Fastlane::Actions::CocoapodsAction

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

Constant Summary

Constants inherited from Fastlane::Action

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

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



161
162
163
# File 'fastlane/lib/fastlane/actions/cocoapods.rb', line 161

def self.authors
  ["KrauseFx", "tadpol", "birmacher", "Liquidsoul"]
end

.available_optionsObject



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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'fastlane/lib/fastlane/actions/cocoapods.rb', line 70

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :repo_update,
                                 env_name: "FL_COCOAPODS_REPO_UPDATE",
                                 description: "Add `--repo-update` flag to `pod install` command",
                                 is_string: false,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :clean_install,
                                 env_name: "FL_COCOAPODS_CLEAN_INSTALL",
                                 description: "Execute a full pod installation ignoring the content of the project cache",
                                 is_string: false,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :silent,
                                 env_name: "FL_COCOAPODS_SILENT",
                                 description: "Execute command without logging output",
                                 is_string: false,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :verbose,
                                 env_name: "FL_COCOAPODS_VERBOSE",
                                 description: "Show more debugging information",
                                 is_string: false,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :ansi,
                                 env_name: "FL_COCOAPODS_ANSI",
                                 description: "Show output with ANSI codes",
                                 is_string: false,
                                 default_value: true),
    FastlaneCore::ConfigItem.new(key: :use_bundle_exec,
                                 env_name: "FL_COCOAPODS_USE_BUNDLE_EXEC",
                                 description: "Use bundle exec when there is a Gemfile presented",
                                 is_string: false,
                                 default_value: true),
    FastlaneCore::ConfigItem.new(key: :podfile,
                                 env_name: "FL_COCOAPODS_PODFILE",
                                 description: "Explicitly specify the path to the Cocoapods' Podfile. You can either set it to the Podfile's path or to the folder containing the Podfile file",
                                 optional: true,
                                 is_string: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("Could not find Podfile") unless File.exist?(value) || Helper.test?
                                 end),
    FastlaneCore::ConfigItem.new(key: :error_callback,
                                 description: 'A callback invoked with the command output if there is a non-zero exit status',
                                 optional: true,
                                 is_string: false,
                                 type: :string_callback,
                                 default_value: nil),
    FastlaneCore::ConfigItem.new(key: :try_repo_update_on_error,
                                 env_name: "FL_COCOAPODS_TRY_REPO_UPDATE_ON_ERROR",
                                 description: 'Retry with --repo-update if action was finished with error',
                                 optional: true,
                                 is_string: false,
                                 default_value: false,
                                 type: Boolean),
    FastlaneCore::ConfigItem.new(key: :deployment,
                                 env_name: "FL_COCOAPODS_DEPLOYMENT",
                                 description: 'Disallow any changes to the Podfile or the Podfile.lock during installation',
                                 optional: true,
                                 is_string: false,
                                 default_value: false,
                                 type: Boolean),
    FastlaneCore::ConfigItem.new(key: :allow_root,
                                 env_name: "FL_COCOAPODS_ALLOW_ROOT",
                                 description: 'Allows CocoaPods to run as root',
                                 optional: true,
                                 is_string: false,
                                 default_value: false,
                                 type: Boolean),

    # Deprecated
    FastlaneCore::ConfigItem.new(key: :clean,
                                 env_name: "FL_COCOAPODS_CLEAN",
                                 description: "(Option renamed as clean_install) Remove SCM directories",
                                 deprecated: true,
                                 is_string: false,
                                 default_value: true),
    FastlaneCore::ConfigItem.new(key: :integrate,
                                 env_name: "FL_COCOAPODS_INTEGRATE",
                                 description: "(Option removed from cocoapods) Integrate the Pods libraries into the Xcode project(s)",
                                 deprecated: true,
                                 is_string: false,
                                 default_value: true)
  ]
  # Please don't add a version parameter to the `cocoapods` action. If you need to specify a version when running
  # `cocoapods`, please start using a Gemfile and lock the version there
  # More information https://docs.fastlane.tools/getting-started/ios/setup/#use-a-gemfile
end

.call_error_callback(params, result) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'fastlane/lib/fastlane/actions/cocoapods.rb', line 56

def self.call_error_callback(params, result)
  if params[:error_callback]
    Dir.chdir(FastlaneCore::FastlaneFolder.path) do
      params[:error_callback].call(result)
    end
  else
    UI.shell_error!(result)
  end
end

.categoryObject



179
180
181
# File 'fastlane/lib/fastlane/actions/cocoapods.rb', line 179

def self.category
  :building
end

.descriptionObject



66
67
68
# File 'fastlane/lib/fastlane/actions/cocoapods.rb', line 66

def self.description
  "Runs `pod install` for the project"
end

.detailsObject



165
166
167
# File 'fastlane/lib/fastlane/actions/cocoapods.rb', line 165

def self.details
  "If you use [CocoaPods](http://cocoapods.org) you can use the `cocoapods` integration to run `pod install` before building your app."
end

.example_codeObject



169
170
171
172
173
174
175
176
177
# File 'fastlane/lib/fastlane/actions/cocoapods.rb', line 169

def self.example_code
  [
    'cocoapods',
    'cocoapods(
      clean_install: true,
      podfile: "./CustomPodfile"
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:



157
158
159
# File 'fastlane/lib/fastlane/actions/cocoapods.rb', line 157

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

.pod_version(params) ⇒ Object



47
48
49
# File 'fastlane/lib/fastlane/actions/cocoapods.rb', line 47

def self.pod_version(params)
  use_bundle_exec?(params) ? `bundle exec pod --version` : `pod --version`
end

.pod_version_at_least(at_least_version, params) ⇒ Object



51
52
53
54
# File 'fastlane/lib/fastlane/actions/cocoapods.rb', line 51

def self.pod_version_at_least(at_least_version, params)
  version = pod_version(params)
  return Gem::Version.new(version) >= Gem::Version.new(at_least_version)
end

.run(params) ⇒ Object

rubocop:disable Metrics/PerceivedComplexity



5
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
40
41
# File 'fastlane/lib/fastlane/actions/cocoapods.rb', line 5

def self.run(params)
  Actions.verify_gem!('cocoapods')
  cmd = []

  unless params[:podfile].nil?
    if params[:podfile].end_with?('Podfile')
      podfile_folder = File.dirname(params[:podfile])
    else
      podfile_folder = params[:podfile]
    end
    cmd << ["cd '#{podfile_folder}' &&"]
  end

  cmd << ['bundle exec'] if use_bundle_exec?(params)
  cmd << ['pod install']

  cmd << '--no-clean' unless params[:clean]
  cmd << '--no-integrate' unless params[:integrate]
  cmd << '--clean-install' if params[:clean_install] && pod_version_at_least("1.7", params)
  cmd << '--allow-root' if params[:allow_root] && pod_version_at_least("1.10", params)
  cmd << '--repo-update' if params[:repo_update]
  cmd << '--silent' if params[:silent]
  cmd << '--verbose' if params[:verbose]
  cmd << '--no-ansi' unless params[:ansi]
  cmd << '--deployment' if params[:deployment]

  Actions.sh(cmd.join(' '), error_callback: lambda { |result|
    if !params[:repo_update] && params[:try_repo_update_on_error]
      cmd << '--repo-update'
      Actions.sh(cmd.join(' '), error_callback: lambda { |retry_result|
        call_error_callback(params, retry_result)
      })
    else
      call_error_callback(params, result)
    end
  })
end

.use_bundle_exec?(params) ⇒ Boolean

Returns:



43
44
45
# File 'fastlane/lib/fastlane/actions/cocoapods.rb', line 43

def self.use_bundle_exec?(params)
  params[:use_bundle_exec] && shell_out_should_use_bundle_exec?
end