Class: Pindo::SwarkHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/pindo/module/build/swark_helper.rb

Overview

Swark 授权辅助类负责 Swark 授权检查、权限配置等操作

Class Method Summary collapse

Class Method Details

.add_swark_authorize_json(build_type:, config_json:, team_id:, bundle_id:, deploy_repo_name:) ⇒ Object

添加 Swark 授权配置文件

Parameters:

  • build_type (String)

    构建类型(dev/adhoc/appstore)

  • config_json (Hash)

    配置 JSON 对象

  • team_id (String)

    Team ID

  • bundle_id (String)

    Bundle ID

  • deploy_repo_name (String)

    部署仓库名称



96
97
98
99
100
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
# File 'lib/pindo/module/build/swark_helper.rb', line 96

def self.add_swark_authorize_json(
    build_type:,
    config_json:,
    team_id:,
    bundle_id:,
    deploy_repo_name:
)
    return unless build_type == "appstore" &&
                 config_json &&
                 config_json['project_info'] &&
                 config_json['project_info']['xcode_build_type'] &&
                 config_json['project_info']['xcode_build_type'].include?("swark")

    app_config_dir = Pindo::GitHandler.clong_buildconfig_repo(repo_name: deploy_repo_name)
    swark_authorize_file = File.join(app_config_dir, "swark_authorize.json")

    if File.exist?(swark_authorize_file)
        swark_authorize_json = JSON.parse(File.read(swark_authorize_file))
        if swark_authorize_json && swark_authorize_json['swark_authorize_status']
            puts "swark already authorize success !!! "
            return
        end
    end

    # 创建或更新授权文件
    swark_authorize_json = {}
    swark_authorize_json['swark_authorize_teamid'] = team_id
    swark_authorize_json['swark_authorize_bundleid'] = bundle_id
    swark_authorize_json['swark_authorize_status'] = false

    File.open(swark_authorize_file, "w") do |f|
        f.write(JSON.pretty_generate(swark_authorize_json))
    end

    Pindo::GitHandler.git_addpush_repo(path: app_config_dir, message: "add swark authorize json")
end

.add_swark_entitlement(entitlements_plist_path:, bundle_id_dict:, config_json:, team_id:, bundle_id:) ⇒ Object

添加 Swark 权限配置到 entitlements

Parameters:

  • entitlements_plist_path (String)

    entitlements.plist 文件路径

  • bundle_id_dict (Hash)

    Bundle ID 字典

  • config_json (Hash)

    配置 JSON 对象

  • team_id (String)

    Team ID

  • bundle_id (String)

    Bundle ID



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/pindo/module/build/swark_helper.rb', line 68

def self.add_swark_entitlement(
    entitlements_plist_path:,
    bundle_id_dict:,
    config_json:,
    team_id:,
    bundle_id:
)
    return unless config_json &&
                 config_json['project_info'] &&
                 config_json['project_info']['xcode_build_type'] &&
                 config_json['project_info']['xcode_build_type'].include?("swark")

    return unless File.exist?(entitlements_plist_path)

    entitlements_plist_dict = Xcodeproj::Plist.read_from_path(entitlements_plist_path)

    key_value = team_id + "." + bundle_id
    entitlements_plist_dict['keychain-access-groups'] = [key_value]

    Xcodeproj::Plist.write_to_path(entitlements_plist_dict, entitlements_plist_path)
end

.check_swark_authorize(config_json:, buid_type:, deploy_identifier:) ⇒ Object

检查 Swark 授权状态

Parameters:

  • config_json (Hash)

    配置 JSON 对象

  • buid_type (String)

    构建类型(dev/adhoc/appstore)

  • deploy_identifier (String)

    部署标识符



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/pindo/module/build/swark_helper.rb', line 16

def self.check_swark_authorize(config_json:, buid_type:, deploy_identifier:)
    return unless config_json &&
                 config_json['project_info'] &&
                 config_json['project_info']['xcode_build_type'] &&
                 config_json['project_info']['xcode_build_type'].include?("swark")

    require 'pindo/config/pindoconfig'
    app_config_dir = File.join(File.expand_path(Pindoconfig.instance.pindo_dir), deploy_identifier)
    swark_authorize_file = File.join(app_config_dir, "swark_authorize.json")

    if File.exist?(swark_authorize_file)
        swark_authorize_json = JSON.parse(File.read(swark_authorize_file))
        unless swark_authorize_json && swark_authorize_json['swark_authorize_status']
            show_swark_authorize_error(
                swark_authorize_json: swark_authorize_json,
                buid_type: buid_type
            )
        end
    end
end

.show_swark_authorize_error(swark_authorize_json:, buid_type:) ⇒ Object

显示 Swark 授权错误信息

Parameters:

  • swark_authorize_json (Hash)

    Swark 授权配置 JSON

  • buid_type (String)

    构建类型



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/pindo/module/build/swark_helper.rb', line 40

def self.show_swark_authorize_error(swark_authorize_json:, buid_type:)
    puts "++++ +++ Need authorize !!! ++++"
    puts "+++ Need authorize !!! ++++"
    puts "+++ Need authorize !!! +++++"
    puts " =========================="
    puts

    puts "方法一:"
    command = "     1. swark authorize "
    command += swark_authorize_json["swark_authorize_teamid"] + "." + swark_authorize_json["swark_authorize_bundleid"]
    puts command
    puts "     2. 修改swark_authorize.json 中的 swark_authorize_status = true 并且提交"
    puts

    puts "方法二:"
    puts "      pindo deploy quswark"

    if buid_type.downcase.to_s.include?("appstore")
        raise Informative, "Need swark authorize !!!"
    end
end