mirror of
https://github.com/tryzealot/fastlane-plugin-zealot.git
synced 2026-02-24 09:13:16 +00:00
Merge pull request #6 from tryzealot/feature/zealot_sync_devices-support-api-key-auth
新特性:zealot_sync_devices 支持 Apple API key 授权方式
This commit is contained in:
@@ -202,38 +202,50 @@ end
|
||||
|
||||
### zealot_sync_device
|
||||
|
||||
同步指定 Apple 开发者账号的设备列表信息到 Zealot,主要是为了让使用者更清晰看到每个设备 udid 记录的名称
|
||||
同步指定 Apple 开发者账号的设备列表信息到 Zealot,主要是为了让使用者更清晰看到每个设备 udid 记录的名称,提供两种授权方式:
|
||||
|
||||
- [Apple API Key 授权](https://docs.fastlane.tools/app-store-connect-api/#using-fastlane-api-key-json-file) **强烈推荐**
|
||||
- 密码授权
|
||||
|
||||
#### 参数和返回值
|
||||
|
||||
```
|
||||
+---------------+-----------------------------------+------------------------+---------+
|
||||
| zealot_sync_devices Options |
|
||||
+---------------+-----------------------------------+------------------------+---------+
|
||||
| Key | Description | Env Var | Default |
|
||||
+---------------+-----------------------------------+------------------------+---------+
|
||||
| endpoint | The endpoint of zealot | ZEALOT_ENDPOINT | |
|
||||
| token | The token of user | ZEALOT_TOKEN | |
|
||||
| username | The apple id (username) of Apple | DELIVER_USER | * |
|
||||
| | Developer Portal | | |
|
||||
| team_id | The ID of your Developer Portal | ZEALOT_APPLE_TEAM_ID | * |
|
||||
| | team if you're in multiple teams | | |
|
||||
| team_name | The name of your Developer | ZEALOT_APPLE_TEAM_NAME | * |
|
||||
| | Portal team if you're in | | |
|
||||
| | multiple teams | | |
|
||||
| platform | The platform to use (optional) | ZEALOT_APPLE_PLATFORM | ios |
|
||||
| verify_ssl | Should verify SSL of zealot | ZEALOT_VERIFY_SSL | true |
|
||||
| | service | | |
|
||||
| timeout | Request timeout in seconds | ZEALOT_TIMEOUT | |
|
||||
| fail_on_error | Should an error http request | ZEALOT_FAIL_ON_ERROR | false |
|
||||
| | cause a failure? (true/false) | | |
|
||||
+---------------+-----------------------------------+------------------------+---------+
|
||||
+---------------+-----------------------------------------------------------------------------+------------------------+---------+
|
||||
| zealot_sync_devices Options |
|
||||
+---------------+-----------------------------------------------------------------------------+------------------------+---------+
|
||||
| Key | Description | Env Var(s) | Default |
|
||||
+---------------+-----------------------------------------------------------------------------+------------------------+---------+
|
||||
| endpoint | The endpoint of zealot | ZEALOT_ENDPOINT | |
|
||||
| token | The token of user | ZEALOT_TOKEN | |
|
||||
| username | The apple id (username) of Apple Developer Portal | ZEALOT_USERNAME | * |
|
||||
| api_key_path | Path to your App Store Connect API Key JSON file | ZEALOT_API_PATH | |
|
||||
| | (https://docs.fastlane.tools/app-store-connect-api/#using-fastlane-api-key | | |
|
||||
| | -json-file) | | |
|
||||
| api_key | Your App Store Connect API Key information | ZEALOT_API_KEY | * |
|
||||
| | (https://docs.fastlane.tools/app-store-connect-api/#using-fastlane-api-key | | |
|
||||
| | -hash-option) | | |
|
||||
| team_id | The ID of your Developer Portal team if you're in multiple teams | ZEALOT_APPLE_TEAM_ID | * |
|
||||
| team_name | The name of your Developer Portal team if you're in multiple teams | ZEALOT_APPLE_TEAM_NAME | * |
|
||||
| platform | The platform to use (optional) | ZEALOT_APPLE_PLATFORM | ios |
|
||||
| verify_ssl | Should verify SSL of zealot service | ZEALOT_VERIFY_SSL | true |
|
||||
| timeout | Request timeout in seconds | ZEALOT_TIMEOUT | |
|
||||
| fail_on_error | Should an error http request cause a failure? (true/false) | ZEALOT_FAIL_ON_ERROR | false |
|
||||
+---------------+-----------------------------------------------------------------------------+------------------------+---------+
|
||||
```
|
||||
|
||||
#### 样例
|
||||
|
||||
```ruby
|
||||
lane :sync do
|
||||
# 使用 Apple API Key 方式授权,无需密码和二次验证
|
||||
zealot_sync_devices(
|
||||
endpoint: "...",
|
||||
token: "...",
|
||||
api_key_path: "/path/to/your/api_key_json_file",
|
||||
team_id: "..."
|
||||
)
|
||||
|
||||
# 使用传统的密码授权
|
||||
zealot_sync_devices(
|
||||
endpoint: "...",
|
||||
token: "...",
|
||||
|
||||
@@ -32,5 +32,5 @@ Gem::Specification.new do |spec|
|
||||
spec.add_development_dependency('rubocop', '0.49.1')
|
||||
spec.add_development_dependency('rubocop-require_tools')
|
||||
spec.add_development_dependency('simplecov')
|
||||
spec.add_development_dependency('fastlane', '>= 2.137.0')
|
||||
spec.add_development_dependency('fastlane', '>= 2.172.0')
|
||||
end
|
||||
|
||||
@@ -13,19 +13,34 @@ module Fastlane
|
||||
def self.run(params)
|
||||
require 'spaceship'
|
||||
|
||||
credentials = CredentialsManager::AccountManager.new(user: params[:username])
|
||||
Spaceship.login(credentials.user, credentials.password)
|
||||
Spaceship.select_team
|
||||
|
||||
UI.message('Fetching list of currently registered devices...')
|
||||
all_platforms = Set[params[:platform]]
|
||||
supported_platforms = all_platforms.select { |platform| self.is_supported?(platform.to_sym) }
|
||||
|
||||
devices = supported_platforms.flat_map { |platform| Spaceship::Device.all(mac: platform == "mac") }
|
||||
if (api_token = Spaceship::ConnectAPI::Token.from(hash: params[:api_key], filepath: params[:api_key_path]))
|
||||
UI.message('Creating authorization token for App Store Connect API')
|
||||
Spaceship::ConnectAPI.token = api_token
|
||||
|
||||
devices = supported_platforms.flat_map do |platform|
|
||||
Spaceship::ConnectAPI::Device.all(filter: { platform: platform == 'ios' ? 'IOS' : 'MAC_OS'})
|
||||
end
|
||||
else
|
||||
username = params[:username]
|
||||
UI.message("Login to App Store Connect (#{username})")
|
||||
credentials = CredentialsManager::AccountManager.new(user: username)
|
||||
Spaceship.login(credentials.user, credentials.password)
|
||||
UI.message('Login successful')
|
||||
Spaceship.select_team
|
||||
|
||||
# Fetches all devices includes macOS.
|
||||
|
||||
devices = supported_platforms.flat_map { |platform| Spaceship::Device.all(mac: platform == 'mac') }
|
||||
end
|
||||
|
||||
UI.message('Fetching list of currently registered devices...')
|
||||
|
||||
print_table(build_table_data(params, devices), title: 'zealot_sync_devices')
|
||||
|
||||
UI.verbose("Syncing devices to #{params[:endpoint]} ...")
|
||||
UI.message("Syncing devices to #{params[:endpoint]} ...")
|
||||
failed_devices = []
|
||||
devices.each do |device|
|
||||
begin
|
||||
@@ -39,7 +54,7 @@ module Fastlane
|
||||
|
||||
failed = failed_devices.size
|
||||
successed = devices.size - failed
|
||||
UI.success "Successful Synced devices. success: #{successed}, failed: #{failed}"
|
||||
UI.success "Successful Synced devices, success: #{successed}, failed: #{failed}"
|
||||
UI.verbose "Failed devices: #{failed_devices}"
|
||||
end
|
||||
|
||||
@@ -66,11 +81,28 @@ module Fastlane
|
||||
end,
|
||||
type: String),
|
||||
FastlaneCore::ConfigItem.new(key: :username,
|
||||
env_name: 'DELIVER_USER',
|
||||
env_name: 'ZEALOT_USERNAME',
|
||||
description: 'The apple id (username) of Apple Developer Portal',
|
||||
default_value_dynamic: true,
|
||||
optional: true,
|
||||
type: String),
|
||||
FastlaneCore::ConfigItem.new(key: :api_key_path,
|
||||
env_name: 'ZEALOT_API_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_name: 'ZEALOT_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: 'ZEALOT_APPLE_TEAM_ID',
|
||||
description: 'The ID of your Developer Portal team if you\'re in multiple teams',
|
||||
@@ -79,7 +111,7 @@ module Fastlane
|
||||
optional: true,
|
||||
type: String,
|
||||
verify_block: proc do |value|
|
||||
ENV["FASTLANE_TEAM_ID"] = value.to_s
|
||||
ENV['FASTLANE_TEAM_ID'] = value.to_s
|
||||
end),
|
||||
FastlaneCore::ConfigItem.new(key: :team_name,
|
||||
env_name: 'ZEALOT_APPLE_TEAM_NAME',
|
||||
@@ -89,7 +121,7 @@ module Fastlane
|
||||
optional: true,
|
||||
type: String,
|
||||
verify_block: proc do |value|
|
||||
ENV["FASTLANE_TEAM_NAME"] = value.to_s
|
||||
ENV['FASTLANE_TEAM_NAME'] = value.to_s
|
||||
end),
|
||||
FastlaneCore::ConfigItem.new(key: :platform,
|
||||
env_name: 'ZEALOT_APPLE_PLATFORM',
|
||||
@@ -121,6 +153,12 @@ module Fastlane
|
||||
|
||||
def self.example_code
|
||||
[
|
||||
'zealot_sync_devices(
|
||||
endpoint: "...",
|
||||
token: "...",
|
||||
api_key_path: "...",
|
||||
team_id: "..."
|
||||
)',
|
||||
'zealot_sync_devices(
|
||||
endpoint: "...",
|
||||
token: "...",
|
||||
|
||||
Reference in New Issue
Block a user