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

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Build

Returns a new instance of Build.



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

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
# 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



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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/pindo/command/deploy/build.rb', line 127

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)

    project_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 !project_build_platform.nil? && project_build_platform.eql?("macosx")
        if provisioning_profile_name.include?("development")
            # Mac development包
            build_type = "development"
            icloud_env = "Development"
        elsif provisioning_profile_name.include?("appstore")
            build_type = "mac-application"
            icloud_env = "Production"
        else 
            build_type = "developer-id"
            icloud_env = "Production"
        end
    else
        if 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
    end

    # 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 !project_build_platform.nil? && project_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



58
59
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/pindo/command/deploy/build.rb', line 58

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?
            PgyerHelper.share_instace.print_app_version_info(
                app_info_obj: app_info_obj,
                app_version_info_obj: result_data["data"]
            )
            if @args_resign_flag
                args = []
                if @args_send_flag
                    args << "--send"
                end
                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::Jps::Resign::run(args)
            else
                # 始终发送给自己
                PgyerHelper.share_instace.send_apptest_msg(
                    app_info_obj: app_info_obj,
                    app_version_info_obj: result_data["data"],
                    receiveType: "self"
                )

                # 如果有 --send 参数,额外发送到测试群
                if @args_send_flag
                    PgyerHelper.share_instace.send_apptest_msg(
                        app_info_obj: app_info_obj,
                        app_version_info_obj: result_data["data"],
                        chatEnv: "DevTest",
                        receiveType: "chat"
                    )
                end
            end
        end
    end
end