Class: Fastlane::Actions::SyncDevicesAction

Inherits:
Action
  • Object
show all
Includes:
Helper::SyncDevicesHelper
Defined in:
lib/fastlane/plugin/sync_devices/actions/sync_devices_action.rb

Overview

Fastlane action to synchronize remote devices on Apple Developer Portal with local devices file.

Class Method Summary collapse

Class Method Details

.authorsArray<String>

Authors of this plugin.

Returns:

  • (Array<String>)

See Also:



77
78
79
# File 'lib/fastlane/plugin/sync_devices/actions/sync_devices_action.rb', line 77

def self.authors
  ['Ryosuke Ito']
end

.available_optionsArray<FastlaneCore::ConfigItem>

Available options of this plugin.

Returns:

  • (Array<FastlaneCore::ConfigItem>)

See Also:



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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/fastlane/plugin/sync_devices/actions/sync_devices_action.rb', line 101

def self.available_options # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
  [
    FastlaneCore::ConfigItem.new(
      key: :dry_run,
      env_name: 'FL_SYNC_DEVICES_DRY_RUN',
      description: 'Do not modify the registered devices but just print what will be done',
      type: Boolean,
      default_value: false,
      optional: true
    ),
    FastlaneCore::ConfigItem.new(
      key: :devices_file,
      env_name: 'FL_SYNC_DEVICES_FILE',
      description: 'Provide a path to a file with the devices to register. ' \
                   'For the format of the file see the examples',
      optional: true,
      verify_block: proc do |value|
        UI.user_error!("Could not find file '#{value}'") unless File.exist?(value)
      end
    ),
    FastlaneCore::ConfigItem.new(
      key: :api_key_path,
      env_names: %w[FL_SYNC_DEVICES_API_KEY_PATH APP_STORE_CONNECT_API_KEY_PATH],
      description: 'Path to your App Store Connect API Key JSON file ' \
                   '(https://docs.fastlane.tools/app-store-connect-api/#using-fastlane-api-key-json-file)',
      optional: true,
      conflicting_options: [:api_key],
      verify_block: proc do |value|
        UI.user_error!("Couldn't find API key JSON file at path '#{value}'") unless File.exist?(value)
      end
    ),
    FastlaneCore::ConfigItem.new(
      key: :api_key,
      env_names: %w[FL_SYNC_DEVICES_API_KEY APP_STORE_CONNECT_API_KEY],
      description: 'Your App Store Connect API Key information ' \
                   '(https://docs.fastlane.tools/app-store-connect-api/#using-fastlane-api-key-hash-option)',
      type: Hash,
      default_value: Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::APP_STORE_CONNECT_API_KEY],
      default_value_dynamic: true,
      optional: true,
      sensitive: true,
      conflicting_options: [:api_key_path]
    ),
    FastlaneCore::ConfigItem.new(
      key: :team_id,
      env_name: 'SYNC_DEVICES_TEAM_ID',
      code_gen_sensitive: true,
      default_value: CredentialsManager::AppfileConfig.try_fetch_value(:team_id),
      default_value_dynamic: true,
      description: "The ID of your Developer Portal team if you're in multiple teams",
      optional: true,
      verify_block: proc do |value|
        ENV['FASTLANE_TEAM_ID'] = value.to_s
      end
    ),
    FastlaneCore::ConfigItem.new(
      key: :team_name,
      env_name: 'SYNC_DEVICES_TEAM_NAME',
      description: "The name of your Developer Portal team if you're in multiple teams",
      optional: true,
      code_gen_sensitive: true,
      default_value: CredentialsManager::AppfileConfig.try_fetch_value(:team_name),
      default_value_dynamic: true,
      verify_block: proc do |value|
        ENV['FASTLANE_TEAM_NAME'] = value.to_s
      end
    ),
    FastlaneCore::ConfigItem.new(
      key: :username,
      env_name: 'DELIVER_USER',
      description: 'Optional: Your Apple ID',
      optional: true,
      default_value: CredentialsManager::AppfileConfig.try_fetch_value(:apple_id),
      default_value_dynamic: true
    )
  ]
end

.categorySymbol

Category of this plugin.

Returns:

  • (Symbol)

See Also:



217
218
219
# File 'lib/fastlane/plugin/sync_devices/actions/sync_devices_action.rb', line 217

def self.category
  :code_signing
end

.descriptionString

Description of this plugin.

Returns:

  • (String)

See Also:



69
70
71
# File 'lib/fastlane/plugin/sync_devices/actions/sync_devices_action.rb', line 69

def self.description
  'Synchronize your devices with Apple Developer Portal.'
end

.detailsString

Detailed description of this plugin.

Returns:

  • (String)

See Also:



85
86
87
88
89
90
91
92
93
# File 'lib/fastlane/plugin/sync_devices/actions/sync_devices_action.rb', line 85

def self.details
  <<~DETAILS
    This will synchronize iOS/Mac devices with the Apple Developer Portal so that you can include them in your provisioning profiles.
    Unlike `register_devices` action, this action may disable, enable or rename devices.
    Maybe it sounds dangerous but actually it does not delete anything, so you can recover the changes by yourself if needed.

    The action will connect to the Apple Developer Portal using AppStore Connect API.
  DETAILS
end

.example_codeArray<String>

Example usages of this plugin.

Returns:

  • (Array<String>)

See Also:



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/fastlane/plugin/sync_devices/actions/sync_devices_action.rb', line 192

def self.example_code
  [
    <<~EX_1,
    <<~EX_2,
    <<~EX_3
      # Just check what will occur
      sync_devices(devices_file: '/path/to/devices.txt', dry_run: true)
    EX_3
  ]
end

.is_supported?(_platform) ⇒ true

Whether if this plugin is supported on the platform.

Parameters:

  • _platform (Symbol)

    unused

Returns:

  • (true)

See Also:



184
185
186
# File 'lib/fastlane/plugin/sync_devices/actions/sync_devices_action.rb', line 184

def self.is_supported?(_platform) # rubocop:disable Naming/PredicateName
  true
end

.run(params) ⇒ void

This method returns an undefined value.

The main entry point of this plugin.

Parameters:

  • params (Hash)

    options passed to this plugin. See available_options for details.

Options Hash (params):

  • :dry_run (Boolean)
  • :devices_file (String)
  • :api_key_path (String, nil)
  • :api_key (Hash, nil)
  • :team_id (String, nil)
  • :team_name (String, nil)
  • :username (String, nil)

See Also:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fastlane/plugin/sync_devices/actions/sync_devices_action.rb', line 29

def self.run(params)
  require 'spaceship/connect_api'

  devices_file = params[:devices_file]
  UI.user_error!('You must pass `devices_file`. Please check the readme.') unless devices_file
  (params)
  new_devices = DevicesFile.load(devices_file)

  UI.message('Fetching list of currently registered devices...')
  current_devices = Spaceship::ConnectAPI::Device.all
  patch = DevicesPatch.new(current_devices, new_devices)
  patch.apply!(dry_run: params[:dry_run])

  UI.success('Successfully synchronized devices.')
end