Class: Fastlane::Actions::AppStoreConnectApiKeyAddToRemoteAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/yalantis_ci/actions/app_store_connect_api_key_add_to_remote.rb

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



106
107
108
# File 'lib/fastlane/plugin/yalantis_ci/actions/app_store_connect_api_key_add_to_remote.rb', line 106

def self.authors
  ["Dima Vorona", "Yalantis"]
end

.available_optionsObject



58
59
60
61
62
63
64
65
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
103
104
# File 'lib/fastlane/plugin/yalantis_ci/actions/app_store_connect_api_key_add_to_remote.rb', line 58

def self.available_options
  [
    FastlaneCore::ConfigItem.new(
      key: :git_repo_url,
      env_name: "APP_STORE_CONNECT_API_KEY_GIT_REPO_URL",
      description: "Git repo URL where AppStore Connect's Api Key should be stored in",
      type: String
    ),
    FastlaneCore::ConfigItem.new(
      key: :git_repo_branch,
      env_name: "APP_STORE_CONNECT_API_KEY_GIT_REPO_BRANCH",
      description: "Git repo branch where AppStore Connect's Api Key should be stored in",
      type: String,
      default_value: 'master'
    ),
    FastlaneCore::ConfigItem.new(
      key: :key_filepath,
      env_name: "APP_STORE_CONNECT_API_KEY_KEY_FILEPATH",
      description: "The path to the key p8 file",
      optional: true,
      conflicting_options: [:key_content],
      verify_block: proc do |value|
        UI.user_error!("Couldn't find key p8 file at path '#{value}'") unless File.exist?(File.expand_path(value))
      end
    ),
    FastlaneCore::ConfigItem.new(
      key: :key_id,
      env_name: "APP_STORE_CONNECT_API_KEY_KEY_ID",
      description: "The key ID",
    ),
    FastlaneCore::ConfigItem.new(
      key: :key_content,
      env_name: "APP_STORE_CONNECT_API_KEY_KEY",
      description: "The content of the key p8 file",
      sensitive: true,
      optional: true,
      conflicting_options: [:key_filepath]
    ),
    FastlaneCore::ConfigItem.new(
      key: :is_key_content_base64,
      env_name: "APP_STORE_CONNECT_API_KEY_IS_KEY_CONTENT_BASE64",
      description: "Whether :key_content is Base64 encoded or not",
      type: Boolean,
      default_value: false
    )
  ]
end

.descriptionObject



54
55
56
# File 'lib/fastlane/plugin/yalantis_ci/actions/app_store_connect_api_key_add_to_remote.rb', line 54

def self.description
  "Add/Update AppStore Connect API Key to the remote git repo"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/fastlane/plugin/yalantis_ci/actions/app_store_connect_api_key_add_to_remote.rb', line 110

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

.run(options) ⇒ Object



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
42
43
44
45
46
47
48
# File 'lib/fastlane/plugin/yalantis_ci/actions/app_store_connect_api_key_add_to_remote.rb', line 8

def self.run(options)
  git_repo_url = options[:git_repo_url]
  git_repo_branch = options[:git_repo_branch]
  key_filepath = options[:key_filepath]
  key_id = options[:key_id]
  key_content = options[:key_content]
  is_key_content_base64 = options[:is_key_content_base64]

  if key_content.nil? && key_filepath.nil?
    UI.user_error!(":key_content or :key_filepath is required")
  end

  Helper::GitHelper.clone_repo_in_tmp(repo_url: git_repo_url, branch: git_repo_branch, create_branch: true) do |dir|
    target_filename = "#{key_id}.p8"
    target_filepath = File.join(dir, target_filename)

    if key_filepath.nil? == false
      FileUtils.cp(File.expand_path(key_filepath), target_filepath)
    else
      File.open(target_filepath, 'w') do |file|
        if is_key_content_base64 
          file.write(Base64.decode64(key_content))
        else
          file.write(key_content)
        end
      end
    end

    repo_status = Actions.sh("git status --porcelain")
    repo_clean = repo_status.empty?

    if repo_clean 
      UI.message("Skipping key #{key_id} update since it contents remains the same")
    else 
      UI.message("Adding / updating #{key_id}")

      Actions.sh("git add #{target_filename} && git commit -m '[AppStore Connect API Key] Add/Update #{target_filename} key'")
      Actions.sh("git push -f #{git_repo_url} #{git_repo_branch}")    
    end
  end
end