Class: Pindo::Command::Deploy::Cert

Inherits:
Pindo::Command::Deploy show all
Includes:
Pindo::CertHelper, Pindo::Command::DeployOptions, SwarkHelper, XcodeCertHelper
Defined in:
lib/pindo/command/deploy/cert.rb

Constant Summary

Constants inherited from Pindo::Command

Pindo::Command::DEFAULT_OPTIONS, Pindo::Command::DEFAULT_ROOT_OPTIONS

Instance Attribute Summary

Attributes included from Pindo::Command::DeployOptions

#additional_args, #apple_id, #args_adhoc_flag, #args_appconfig, #args_appconfig_dir, #args_appconfig_fullname, #args_apple_id, #args_appstore_flag, #args_array, #args_bundle_id, #args_dev_flag, #args_macos_flag, #args_repo_name, #argv_temp, #bundle_id, #bundle_id_extension, #bundle_id_extensionad, #bundle_id_extensionporn, #bundle_id_imessage, #bundle_id_keyboard, #bundle_id_pushcontent, #bundle_id_pushservice, #bundle_id_siri, #bundle_id_siriui, #bundle_id_watchapp, #bundle_id_watchapp_extension, #bundle_id_widget, #config_json, #deploy_acount_id, #deploy_group_id, #deploy_icloud_id, #deploy_identifier, #deploy_identifier_extension, #deploy_identifier_extensionad, #deploy_identifier_extensionporn, #deploy_identifier_imessage, #deploy_identifier_keyboard, #deploy_identifier_pushcontent, #deploy_identifier_pushservice, #deploy_identifier_siri, #deploy_identifier_siriui, #deploy_identifier_watchapp, #deploy_identifier_watchapp_extension, #deploy_identifier_widget, #deploy_repo_name, #group_id, #icloud_id, #newconfuse_flag, #oldconfuse_flag

Attributes inherited from Pindo::Command

#args_help_flag

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SwarkHelper

#add_swark_authorize_json, #add_swark_entitlement, #check_swark_authorize, #show_swark_authorize_error

Methods included from Pindo::CertHelper

#get_cert_info, #install_certs, #install_provisionfiles, #isMac?, #is_cert_valid?, #select_cert_or_key

Methods included from XcodeCertHelper

#config_infoplist_cert, #config_project_cert, #create_provisioning_info_array, #create_upload_cert_info, #create_upload_provisioning_info, #get_target_name_map, #modify_entitlements_plist, #modify_info_plist_icloud

Methods included from Pindo::Command::DeployOptions

#check_config_version, #get_build_type_args, #get_bundle_id_map, #get_confuse_type_args, #init_deploy_params, #init_develop_params, #print_params_info, #validate!

Methods inherited from Pindo::Command

run, #validate!

Methods included from Funlog::Mixin

#pindo_log_instance

Methods included from Pindoconfig::Mixin

#pindo_single_config

Methods included from Githelper

#add_branch, #add_tag, #add_tag_with_check, #clone_clang_repo, #clone_devclang_repo, #clone_pindo_common_config_repo, #clone_pindo_env_config_repo, #clong_buildconfig_repo, #get_repo_base_name, #getcode_to_dir, #git_addpush_repo, #git_latest_commit_id, #local_branch_exists?, #local_tag_exists?, #prepare_gitenv, #process_need_add_files, #remote_branch_exists?, #remote_tag_exists?, #remove_branch, #remove_tag

Methods included from Executable

capture_command, #executable, execute_command, which, which!

Constructor Details

#initialize(argv) ⇒ Cert

Returns a new instance of Cert.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/pindo/command/deploy/cert.rb', line 44

def initialize(argv)
  @clean_flag = argv.flag?('clean', false)
  @clean_git_flag = argv.flag?('cleangit', false)
  @upload_flag = argv.flag?('upload', false)
  @renew_cert_flag = argv.flag?('renew', false)
  @match_flag = argv.flag?('match', false)

  super

  @build_type = "appstore"
  if  @args_adhoc_flag
    @build_type = "adhoc"
  end
  if  @args_dev_flag
    @build_type = "development"
  end

end

Class Method Details

.optionsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pindo/command/deploy/cert.rb', line 30

def self.options

  [
    ['--dev', '操作dev证书'],
    ['--adhoc', '操作adhoc证书'],
    ['--macos', 'macos平台证书'],
    ['--clean', '删除本地缓存的证书'],
    ['--cleangit', '删除远程仓库中的证书'],
    ['--upload', '生成上传pgyer的证书'],
    ['--match', '生成上传pgyer的证书'],
    ['--renew', '重新生成证书']
  ].concat(super)
end

Instance Method Details

#get_create_cert_match_values(apple_id: nil, bundle_id_array: nil, build_type: nil, platform_type: nil, renew_flag: false) ⇒ Object



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
178
179
180
181
# File 'lib/pindo/command/deploy/cert.rb', line 139

def get_create_cert_match_values(apple_id:nil, bundle_id_array:nil, build_type:nil, platform_type:nil, renew_flag:false)

  if build_type.eql?("appstore") && (apple_id.eql?(pindo_single_config.demo_apple_id))
    raise Informative, "#{apple_id} 是测试账号,不能创建appstore证书!!!"
  end
  if !build_type.eql?("appstore") && !apple_id.eql?(pindo_single_config.demo_apple_id)
    raise Informative, "账号#{apple_id} 不能创建dev或者adhoc证书!!!"
  end

  git_url = pindo_single_config.deploy_cert_giturl
  if @apple_id.eql?(pindo_single_config.demo_apple_id)
    git_url = pindo_single_config.dev_cert_giturl
  end

  force_for_new_devices_flag = true
  if build_type.eql?("appstore")
    force_for_new_devices_flag = false
  end

  if platform_type.downcase.include?("macos") && build_type.eql?("adhoc")
    build_type = "developer_id"
  end

  values = {
    username:apple_id,
    app_identifier: bundle_id_array,
    type: build_type,
    keychain_password:"goodcert1",
    git_url: git_url,
    readonly:!renew_flag,
    force:renew_flag,
    clone_branch_directly:!renew_flag,
    include_mac_in_profiles:true,
    include_all_certificates:true,
    generate_apple_certs:true,
    shallow_clone:!renew_flag,
    git_branch: apple_id,
    platform:platform_type,
    force_for_new_devices:force_for_new_devices_flag
  }
  return values

end

#runObject



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
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
# File 'lib/pindo/command/deploy/cert.rb', line 63

def run
  
    if @clean_flag
      puts "Clear cert at local ..."
      Pindo::Command::Utils::Clearcert::run([])
    end

    if @renew_cert_flag && @clean_git_flag
          pindo_dir = pindo_single_config.pindo_dir
          git_url = pindo_single_config.deploy_cert_giturl
          if @apple_id.eql?(pindo_single_config.demo_apple_id)
            git_url = pindo_single_config.dev_cert_giturl
          end
          cert_repo_dir = getcode_to_dir(reponame:get_repo_base_name(repo_url:git_url), remote_url:git_url, path:pindo_dir, new_branch:@apple_id)
          FileUtils.rm_rf(File.join(cert_repo_dir, "certs"))
          FileUtils.rm_rf(File.join(cert_repo_dir, "profiles"))
          git_addpush_repo(path:cert_repo_dir, message:"remove #{@apple_id} certs")
    end

    bundle_id_array = get_bundle_id_map.values
    provisioning_info_array = nil


    platform_type = "ios"
    if @args_macos_flag
      platform_type = "macos"
    end


    if @renew_cert_flag || @match_flag
      values = get_create_cert_match_values(apple_id:@apple_id, bundle_id_array:bundle_id_array, build_type:@build_type, platform_type:platform_type, renew_flag:@renew_cert_flag)
      config = FastlaneCore::Configuration.create(Match::Options.available_options, values)
      Match::Runner.new.run(config)
      provisioning_info_array = create_provisioning_info_array(build_type:@build_type, platform_type:platform_type)
      pindo_single_config.set_cert_info(dict: provisioning_info_array)
    
    else
      cert_git_url = pindo_single_config.deploy_cert_giturl
      if @apple_id.eql?(pindo_single_config.demo_apple_id)
        cert_git_url = pindo_single_config.dev_cert_giturl
      end
      cert_reponame = cert_git_url.split("/").last.chomp(".git")
      certs_dir = getcode_to_dir(reponame:cert_reponame, remote_url:cert_git_url, path: pindo_single_config.pindo_dir, new_branch:@apple_id)

      install_certs(cert_url:cert_git_url, certs_dir:certs_dir, cert_type:@build_type, platform_type:platform_type)
      bundle_id_map = get_bundle_id_map
      provisioning_info_array = install_provisionfiles(cert_url:cert_git_url, certs_dir:certs_dir, bundle_id_map:bundle_id_map, cert_type:@build_type, platform_type:platform_type)
      pindo_single_config.set_cert_info(dict: provisioning_info_array)
    end

    provisioning_info_array = provisioning_info_array || []
    unless provisioning_info_array.size > 0
      raise Informative, "未找到证书信息"
    end

    @team_id_vaule = provisioning_info_array.first["team_id"]

    #发布机需要给swark注册bundle id
    add_swark_authorize_json

    new_project_dir = Dir.pwd
    new_project_fullname = Dir.glob(File.join(new_project_dir, "/*.xcodeproj")).max_by {|f| File.mtime(f)}
    if !new_project_fullname.nil? && File.exist?(new_project_fullname) && !provisioning_info_array.nil? && provisioning_info_array.size > 0
      new_proj_name = File.basename(new_project_fullname, ".xcodeproj")
      Funlog.instance.fancyinfo_start("正在给Xcode配置证书...")
      config_project_cert(new_proj_name:new_proj_name, new_project_dir:new_project_dir, cert_type:@build_type, platform_type:platform_type, team_id_vaule:@team_id_vaule, provisioning_info_array:provisioning_info_array)
      config_infoplist_cert(new_proj_name:new_proj_name, new_project_dir:new_project_dir, icloud_id:@icloud_id, group_id:@group_id, provisioning_info_array:provisioning_info_array)
      Funlog.instance.fancyinfo_success("Xcode配置证书完成!")
    end

    if @upload_flag
      create_upload_cert_info(apple_id:@apple_id, cert_type:@build_type, platform_type:platform_type)
      create_upload_provisioning_info(apple_id:@apple_id, cert_type:@build_type, platform_type:platform_type, provisioning_info_array:provisioning_info_array)
    end
end