Class: Pindo::Command::Deploy::Build

Inherits:
Pindo::Command::Deploy show all
Defined in:
lib/pindo/command/deploy/build.rb

Constant Summary

Constants inherited from Pindo::Command

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

Instance Attribute Summary

Attributes inherited from Pindo::Command

#args_help_flag

Class Method Summary collapse

Instance Method Summary collapse

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) ⇒ Build

Returns a new instance of Build.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/pindo/command/deploy/build.rb', line 35

def initialize(argv)

    @args_upload_flag = argv.flag?('upload', false)
    @args_send_flag = argv.flag?('send', false)
    @args_resign_flag = argv.flag?('resign', false)

    @args_proj_name = argv.option('proj')
    @args_cert_id = argv.option('certid')

    if !@args_cert_id.nil? && !@args_cert_id.empty?
        @args_resign_flag = true
    end
    if @args_resign_flag
        @args_send_flag = true
    end

    if @args_send_flag
        @args_upload_flag = true
    end

    super
    @additional_args = argv.remainder!

end

Class Method Details

.optionsObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/pindo/command/deploy/build.rb', line 23

def self.options
    [
        ['--proj', '指定上传到pgyer对应的项目名称(大小写空格忽略),用法:pindo deploy build --proj=aichatv4'],
        ['--upload', '是否上传编译后的ipa, 用法:pindo deploy build --upload'],
        ['--send',  '上传到之后是否发送测试信息,用法:pindo deploy build --send'],
        ['--resign',  '上传到之后是否重签名,用法:pindo deploy build --resign'],
        ['--certid',  '设置重签名的正式id,用法:pindo deploy build --certid=com.test.bundleid'],


    ].concat(super)
end

Instance Method Details

#get_gym_build_values(project_fullname: nil) ⇒ Object



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
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/pindo/command/deploy/build.rb', line 113

def get_gym_build_values(project_fullname:nil)

    if project_fullname.nil?
       raise "请指定要编译的工程"
    end
    project_path = File.dirname(project_fullname)
    proj_name = File.basename(project_fullname, ".xcodeproj")
    project_obj = Xcodeproj::Project.open(project_fullname)

    build_platform = project_obj.root_object.build_configuration_list.get_setting("SDKROOT")["Release"]
    main_target = project_obj.targets.select { |target| target.product_type.include?(Xcodeproj::Constants::PRODUCT_TYPE_UTI[:application])  }.first
    provisioning_profile_name = main_target.build_configurations.first.build_settings['PROVISIONING_PROFILE_SPECIFIER'].downcase.split(" ")



    build_type = "app-store"
    icloud_env = "Production"
    if provisioning_profile_name.include?("direct") && provisioning_profile_name.include?("macos")
        build_type = "developer-id"
        icloud_env = "Production"
    elsif provisioning_profile_name.include?("development") && provisioning_profile_name.include?("macos")
        build_type = "development"
        icloud_env = "Development"
    elsif provisioning_profile_name.include?("adhoc")
        build_type = "ad-hoc"
        icloud_env = "Development"
    elsif provisioning_profile_name.include?("development")
        build_type = "development"
        icloud_env = "Development"
    else
        build_type = "app-store"
        icloud_env = "Production"
    end

    if build_type.eql?("app-store") || build_type.eql?("ad-hoc")
        if File.exist?(File.join(project_path, "Unity/Data/Raw/SettingsPluginFlag.txt"))
            raise Informative, "Unity代码包含测试模板,请重新导出Unity代码"
        end
    end


    app_ipaname_temp = main_target.build_configurations.first.build_settings['INFOPLIST_KEY_CFBundleDisplayName'] || main_target.display_name
    app_ipaname_temp = app_ipaname_temp.gsub(/ /, '');
    app_ipaname_temp = app_ipaname_temp.gsub(/\'/, '');

    values = {
        project: "#{proj_name}.xcodeproj",
        scheme:"#{proj_name}",
        configuration: "Release",
        clean: true,
        export_method: build_type,
        output_directory:"./build/",
        output_name: "#{app_ipaname_temp}.ipa"
      }


    if !build_platform.nil? && build_platform.eql?("macosx")
        values[:output_name] = nil
        values[:destination] = "generic/platform=macosx"
    end

    if File.exist?(File.join(project_path, "Podfile"))
        values[:workspace] = "#{proj_name}.xcworkspace"
        values[:project] = nil
    end

    values[:export_options] ||={}
    values[:export_options][:compileBitcode] = false
    values[:export_options][:stripSwiftSymbols] = true
    values[:export_options][:uploadSymbols] = false

    if !@deploy_icloud_id.nil?
        values[:export_options][:iCloudContainerEnvironment] = icloud_env
    end

    return values

end

#runObject



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
105
106
107
108
109
110
# File 'lib/pindo/command/deploy/build.rb', line 60

def run

    app_info_obj = nil
    if @args_upload_flag
        proj_name = @args_proj_name
        app_info_obj = PgyerHelper.share_instace.prepare_upload(working_directory:Dir.pwd, proj_name:proj_name)
    end

    new_project_dir = Dir.pwd
    project_fullname = Dir.glob(File.join(new_project_dir, "/*.xcodeproj")).max_by {|f| File.mtime(f)}

    if File.exist?(File.join(new_project_dir, "build"))
        FileUtils.rm_rf(File.join(new_project_dir, "build"))
    end

    gym_options = get_gym_build_values(project_fullname:project_fullname)

    config = FastlaneCore::Configuration.create(Gym::Options.available_options, gym_options)
    Gym::Manager.new.work(config)



    pindo_new_project_dir = Dir.pwd
    build_path = File.join(pindo_new_project_dir, "build", "*.ipa")
    ipa_file_upload = Dir.glob(build_path).max_by {|f| File.mtime(f)}

    if !ipa_file_upload.nil? && !app_info_obj.nil?
        description = nil
        result_data = PgyerHelper.share_instace.start_upload(app_info_obj:app_info_obj, ipa_file_upload:ipa_file_upload, description:description)
        if !result_data.nil? && !result_data["data"].nil? && !result_data["data"]["id"].nil?
            msg_data = PgyerHelper.share_instace.make_msg_data(app_info_obj:app_info_obj, app_version_info_obj:result_data["data"])
            PgyerHelper.share_instace.print_app_version_info(msg_data:msg_data)
            if @args_send_flag
                if @args_resign_flag
                    args = []
                    args << "--send"
                    if !@args_cert_id.nil? && !@args_cert_id.empty?
                        args << "--certid=#{@args_cert_id}"
                    end
                    if !@args_proj_name.nil? && !@args_proj_name.empty?
                        args << "--proj=#{@args_proj_name}"
                    end

                    Pindo::Command::Pgyer::Resign::run(args)
                else
                    PgyerHelper.share_instace.send_apptest_wechat_msg(msg_data:msg_data)
                end
            end
        end
    end
end