Class: Build::AutoBuild

Inherits:
Object
  • Object
show all
Defined in:
lib/core_blur/auto_build.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, repo_xcode_package, repo_cocoapods_source, repo_cocoapods_binary) ⇒ AutoBuild

Returns a new instance of AutoBuild.



30
31
32
33
34
35
36
37
38
# File 'lib/core_blur/auto_build.rb', line 30

def initialize(config, repo_xcode_package, repo_cocoapods_source, repo_cocoapods_binary)
  @log = Log.new
  @pusher = Push.instance
  @config = config
  @gitlab_helper = GitLabHelper.instance
  @repo_xcode_package = repo_xcode_package
  @repo_cocoapods_source = repo_cocoapods_source
  @repo_cocoapods_binary = repo_cocoapods_binary
end

Instance Attribute Details

#build_binaryObject

Returns the value of attribute build_binary.



29
30
31
# File 'lib/core_blur/auto_build.rb', line 29

def build_binary
  @build_binary
end

#build_itemObject

Returns the value of attribute build_item.



19
20
21
# File 'lib/core_blur/auto_build.rb', line 19

def build_item
  @build_item
end

#configObject

Returns the value of attribute config.



18
19
20
# File 'lib/core_blur/auto_build.rb', line 18

def config
  @config
end

#gitlab_helperObject

Returns the value of attribute gitlab_helper.



26
27
28
# File 'lib/core_blur/auto_build.rb', line 26

def gitlab_helper
  @gitlab_helper
end

#logObject

Returns the value of attribute log.



27
28
29
# File 'lib/core_blur/auto_build.rb', line 27

def log
  @log
end

#pusherObject

Returns the value of attribute pusher.



28
29
30
# File 'lib/core_blur/auto_build.rb', line 28

def pusher
  @pusher
end

#repo_cocoapods_binaryObject

Returns the value of attribute repo_cocoapods_binary.



23
24
25
# File 'lib/core_blur/auto_build.rb', line 23

def repo_cocoapods_binary
  @repo_cocoapods_binary
end

#repo_cocoapods_sourceObject

Returns the value of attribute repo_cocoapods_source.



22
23
24
# File 'lib/core_blur/auto_build.rb', line 22

def repo_cocoapods_source
  @repo_cocoapods_source
end

#repo_module_binaryObject

Returns the value of attribute repo_module_binary.



25
26
27
# File 'lib/core_blur/auto_build.rb', line 25

def repo_module_binary
  @repo_module_binary
end

#repo_module_sourceObject

Returns the value of attribute repo_module_source.



24
25
26
# File 'lib/core_blur/auto_build.rb', line 24

def repo_module_source
  @repo_module_source
end

#repo_xcode_packageObject

Returns the value of attribute repo_xcode_package.



20
21
22
# File 'lib/core_blur/auto_build.rb', line 20

def repo_xcode_package
  @repo_xcode_package
end

#repo_xcode_shellObject

Returns the value of attribute repo_xcode_shell.



21
22
23
# File 'lib/core_blur/auto_build.rb', line 21

def repo_xcode_shell
  @repo_xcode_shell
end

Instance Method Details

#analyzerObject



75
76
77
78
79
80
81
82
83
# File 'lib/core_blur/auto_build.rb', line 75

def analyzer
  puts "\n🚗🚗🚗 开始 组件:#{repo_module_source.pod_name} 版本:#{repo_module_source.pod_version} 分支/tag:#{repo_module_source.branch}"
  puts "snapshot: #{self.build_item.snapshot}"
  puts "real_device: #{self.build_item.real_device}"
  puts "simulator: #{self.build_item.simulator}"
  puts "force_cover: #{self.build_item.force_cover}"
  puts "publish_shell: #{self.build_item.publish_shell}"
  puts "merge_master: #{self.build_item.merge_master}"
end

#auto_build_updateObject



112
113
114
# File 'lib/core_blur/auto_build.rb', line 112

def auto_build_update
  @build_binary = repo_module_source.build_binary
end

#bindObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/core_blur/auto_build.rb', line 60

def bind
  @repo_xcode_shell.gitlab_helper = gitlab_helper
  @repo_xcode_package.gitlab_helper = gitlab_helper
  @repo_cocoapods_source.gitlab_helper = gitlab_helper
  @repo_cocoapods_binary.gitlab_helper = gitlab_helper
  @repo_module_source.gitlab_helper = gitlab_helper
  @repo_module_binary.gitlab_helper = gitlab_helper
  @repo_xcode_shell.pusher = pusher
  @repo_xcode_package.pusher = pusher
  @repo_cocoapods_source.pusher = pusher
  @repo_cocoapods_binary.pusher = pusher
  @repo_module_source.pusher = pusher
  @repo_module_binary.pusher = pusher
  @gitlab_helper.pusher = pusher
end

#clone_codeObject



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/core_blur/auto_build.rb', line 87

def clone_code
  puts "\n⏩ clone仓库"
  repo_cocoapods_source.git_clone(true)
  repo_cocoapods_binary.git_clone(true)
  if repo_module_source.third
    github_helper = GithubHelper.instance
    if self.build_item.fork
      github_forker = GithubFork.instance
      github_forker.setup(config.module_github_path,repo_module_source.pod_name, github_helper.github_url, repo_module_source.ssh_url)
      github_forker.fork_if_need(repo_cocoapods_source, repo_cocoapods_binary)
    end
  end
  source_only_head = !self.build_item.merge_master
  repo_module_source.git_clone(source_only_head)
  gitlab_helper.create_project_if_need(repo_module_source.pod_name, repo_module_binary.http_url, private:false , description:repo_module_source.http_url)
  repo_module_binary.git_clone(true)
  repo_xcode_package.git_clone(true)
  repo_xcode_shell.git_clone(true)
  log.record_time("clone代码")
end

#cocoapods_updateObject



135
136
137
138
# File 'lib/core_blur/auto_build.rb', line 135

def cocoapods_update
  build_binary ? repo_cocoapods_binary.copy_podspec(repo_module_binary) : nil
  repo_cocoapods_source.copy_podspec(repo_module_source)
end

#merge_masterObject



139
140
141
# File 'lib/core_blur/auto_build.rb', line 139

def merge_master
  gitlab_helper.merge_branch(repo_module_source, "master")
end

#module_binary_updateObject



129
130
131
132
133
134
# File 'lib/core_blur/auto_build.rb', line 129

def module_binary_update
  build_binary ? repo_module_binary.clear : nil
  build_binary ? repo_module_binary.copy_framework(repo_xcode_package, repo_module_source) : nil
  build_binary ? repo_module_binary.copy_resources(repo_xcode_package, repo_module_source): nil
  build_binary ? repo_module_binary.copy_podspec(repo_xcode_package, repo_module_source) :nil
end

#module_source_updateObject



107
108
109
110
111
# File 'lib/core_blur/auto_build.rb', line 107

def module_source_update
  repo_module_source.force_cover_validate(repo_cocoapods_source)
  repo_module_source.update_podspec
  repo_module_source.update_binary
end

#publish_shellObject



153
154
155
# File 'lib/core_blur/auto_build.rb', line 153

def publish_shell
  repo_xcode_shell.publish_shell(repo_module_source)
end

#push_message_logObject



156
157
158
159
160
# File 'lib/core_blur/auto_build.rb', line 156

def push_message_log
  log.end_record_time("🕓 整体")
  pusher.push("【✅组件版本发布成功】", "耗时: #{log.cost_time}秒 包大小: #{repo_module_binary.size_format}")
  log.print_cost
end

#push_productObject



142
143
144
145
146
147
148
149
150
151
152
# File 'lib/core_blur/auto_build.rb', line 142

def push_product
  if build_binary
    repo_module_binary.push_code
    repo_module_binary.git_tag
    repo_cocoapods_binary.push_code
  end
  repo_module_source.git_tag
  repo_cocoapods_source.push_code
  repo_module_source.lock_branch_if_need
  log.record_time("提交产物")
end

#re_pullObject



123
124
125
126
127
128
# File 'lib/core_blur/auto_build.rb', line 123

def re_pull
  puts "\n⏩ 重新拉取仓库"
  repo_cocoapods_binary.git_pull
  repo_cocoapods_source.git_pull
  repo_module_binary.git_pull
end

#run(repo_xcode_shell, repo_module_source, repo_module_binary, build_item, sender = nil) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/core_blur/auto_build.rb', line 39

def run(repo_xcode_shell, repo_module_source, repo_module_binary, build_item, sender = nil)
  @repo_xcode_shell = repo_xcode_shell
  @repo_module_source = repo_module_source
  @repo_module_binary = repo_module_binary
  @build_item = build_item
  @pusher.setup(sender, repo_module_source, repo_xcode_shell)
  bind
  analyzer
  special_analyzer
  clone_code
  module_source_update
  auto_build_update
  xcode_package_update
  re_pull
  module_binary_update
  cocoapods_update
  merge_master
  push_product
  publish_shell
  push_message_log
end

#special_analyzerObject



84
85
86
# File 'lib/core_blur/auto_build.rb', line 84

def special_analyzer
  self.build_item.special_setup(repo_module_source.pod_name)
end

#xcode_package_updateObject



115
116
117
118
119
120
121
122
# File 'lib/core_blur/auto_build.rb', line 115

def xcode_package_update
  repo_xcode_package.copy_yaml_from_repo(repo_xcode_shell)
  repo_xcode_package.generate_local_yaml(repo_module_source)
  repo_xcode_package.pod_update
  log.record_time("pod update")
  repo_xcode_package.archive(repo_module_source)
  log.record_time("构建打包")
end