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



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

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

.available_optionsObject



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

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



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

def self.category
  :misc
end

.descriptionObject



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

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

.example_codeObject



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

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:



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

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

.outputObject



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

def self.output
end

.return_valueObject



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

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
36
# File 'fastlane/lib/fastlane/actions/install_xcode_plugin.rb', line 4

def self.run(params)
  require 'fileutils'
  require 'tmpdir'

  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')
  Action.sh("curl", "-L", "-s", "-o", 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