Class: Fastlane::Actions::InstallXcodePluginAction

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

Class Method Details

.authorsObject



71
72
73
# File 'fastlane/lib/fastlane/actions/install_xcode_plugin.rb', line 71

def self.authors
  ["NeoNachoSoto", "tommeier"]
end

.available_optionsObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'fastlane/lib/fastlane/actions/install_xcode_plugin.rb', line 45

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :url,
                                 env_name: "FL_XCODE_PLUGIN_URL",
                                 description: "URL for Xcode plugin ZIP file",
                                 verify_block: proc do |value|
                                   UI.user_error!("No URL for InstallXcodePluginAction given, pass using `url: 'url'`") if value.to_s.length == 0
                                   UI.user_error!("URL doesn't use HTTPS") unless value.start_with?("https://")
                                 end),
    FastlaneCore::ConfigItem.new(key: :github,
                                 env_name: "FL_XCODE_PLUGIN_GITHUB",
                                 description: "GitHub repository URL for Xcode plugin",
                                 optional: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("No GitHub URL for InstallXcodePluginAction given, pass using `github: 'url'`") if value.to_s.length == 0
                                   UI.user_error!("URL doesn't use HTTPS") unless value.start_with?("https://")
                                 end)
  ]
end

.categoryObject



86
87
88
# File 'fastlane/lib/fastlane/actions/install_xcode_plugin.rb', line 86

def self.category
  :misc
end

.descriptionObject



41
42
43
# File 'fastlane/lib/fastlane/actions/install_xcode_plugin.rb', line 41

def self.description
  "Install an Xcode plugin for the current user"
end

.example_codeObject



79
80
81
82
83
84
# File 'fastlane/lib/fastlane/actions/install_xcode_plugin.rb', line 79

def self.example_code
  [
    'install_xcode_plugin(url: "https://example.com/clubmate/plugin.zip")',
    'install_xcode_plugin(github: "https://github.com/contentful/ContentfulXcodePlugin")'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:



75
76
77
# File 'fastlane/lib/fastlane/actions/install_xcode_plugin.rb', line 75

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

.outputObject



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

def self.output
end

.return_valueObject



68
69
# File 'fastlane/lib/fastlane/actions/install_xcode_plugin.rb', line 68

def self.return_value
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
28
29
30
31
32
33
34
35
# File 'fastlane/lib/fastlane/actions/install_xcode_plugin.rb', line 4

def self.run(params)
  require 'fileutils'

  if params[:github]
    base_api_url = params[:github].sub('https://github.com', 'https://api.github.com/repos')

    GithubApiAction.run(
      url: File.join(base_api_url, 'releases/latest'),
      http_method: 'GET',
      error_handlers: {
        404 => proc do |result|
          UI.error("No latest release found for the specified GitHub repository")
        end,
        '*' => proc do |result|
          UI.error("GitHub responded with #{response[:status]}:#{response[:body]}")
        end
      }
    ) do |result|
      return nil if result[:json].nil?
      params[:url] = result[:json]['assets'][0]['browser_download_url']
    end
  end

  zip_path = File.join(Dir.tmpdir, 'plugin.zip')
  sh("curl -Lso #{zip_path} #{params[:url]}")
  plugins_path = "#{ENV['HOME']}/Library/Application Support/Developer/Shared/Xcode/Plug-ins"
  FileUtils.mkdir_p(plugins_path)
  Action.sh("unzip -qo '#{zip_path}' -d '#{plugins_path}'")

  UI.success("Plugin #{File.basename(params[:url], '.zip')} installed successfully")
  UI.message("Please restart Xcode to use the newly installed plugin")
end