Class: Build::RepoModule

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

Direct Known Subclasses

RepoModuleBinary, RepoModuleSource

Instance Attribute Summary collapse

Attributes inherited from Repo

#branch, #gitlab_helper, #http_url, #last_commit, #page_url, #path, #pusher, #repo_path, #size, #size_format, #ssh_url, #user_email, #user_name

Instance Method Summary collapse

Methods inherited from Repo

#clear, #discard_pull, #git_add_stag, #git_checkout, #git_fetch, #git_pull, #git_push, #git_push_f, #git_push_tags, #git_reset_hard, #git_status, #git_tag_delete_local, #git_tag_delete_origin, #git_tag_local, #git_tag_origin, #push_code

Constructor Details

#initialize(path, ssh_url, branch, pod_name, pod_version, third, build_item) ⇒ RepoModule



16
17
18
19
20
21
22
23
24
# File 'lib/core_blur/repo_module.rb', line 16

def initialize(path, ssh_url, branch, pod_name, pod_version, third, build_item)
  super(path, ssh_url, branch)
  @pod_name = pod_name
  @pod_version = pod_version
  @third = third.to_s.downcase == "true"
  @build_item = build_item
  validate
  analyzer
end

Instance Attribute Details

#build_itemObject

Returns the value of attribute build_item.



6
7
8
# File 'lib/core_blur/repo_module.rb', line 6

def build_item
  @build_item
end

#framework_nameObject

Returns the value of attribute framework_name.



14
15
16
# File 'lib/core_blur/repo_module.rb', line 14

def framework_name
  @framework_name
end

#pod_nameObject

Returns the value of attribute pod_name.



7
8
9
# File 'lib/core_blur/repo_module.rb', line 7

def pod_name
  @pod_name
end

#pod_versionObject

Returns the value of attribute pod_version.



8
9
10
# File 'lib/core_blur/repo_module.rb', line 8

def pod_version
  @pod_version
end

#pod_version_finalObject

Returns the value of attribute pod_version_final.



11
12
13
# File 'lib/core_blur/repo_module.rb', line 11

def pod_version_final
  @pod_version_final
end

#podspec_contentObject

Returns the value of attribute podspec_content.



13
14
15
# File 'lib/core_blur/repo_module.rb', line 13

def podspec_content
  @podspec_content
end

#podspec_json_pathObject

Returns the value of attribute podspec_json_path.



12
13
14
# File 'lib/core_blur/repo_module.rb', line 12

def podspec_json_path
  @podspec_json_path
end

#project_idObject

Returns the value of attribute project_id.



15
16
17
# File 'lib/core_blur/repo_module.rb', line 15

def project_id
  @project_id
end

#snapshotObject

Returns the value of attribute snapshot.



10
11
12
# File 'lib/core_blur/repo_module.rb', line 10

def snapshot
  @snapshot
end

#thirdObject

Returns the value of attribute third.



9
10
11
# File 'lib/core_blur/repo_module.rb', line 9

def third
  @third
end

Instance Method Details

#analyzerObject



47
48
49
# File 'lib/core_blur/repo_module.rb', line 47

def analyzer
  @pod_version_final = self.build_item.snapshot ? pod_version+"-SNAPSHOT" : pod_version
end

#build_binaryObject



50
51
52
# File 'lib/core_blur/repo_module.rb', line 50

def build_binary
  build_item.real_device or build_item.simulator
end

#get_commit_msgObject



86
87
88
89
90
91
# File 'lib/core_blur/repo_module.rb', line 86

def get_commit_msg
  committer = podspec_content["committer"]
  commit_time = podspec_content["commitTime"]
  commit_id = podspec_content["commitID"]
  "#{self.pod_name} #{self.pod_version_final} (#{committer} #{commit_time} #{commit_id})"
end

#git_clone(only_head) ⇒ Object



110
111
112
113
114
115
116
117
118
# File 'lib/core_blur/repo_module.rb', line 110

def git_clone(only_head)
  super
  project_obj = gitlab_helper.fetch_project(pod_name, http_url, can_raise: true)
  unless project_obj
    return
  end
  @project_id = project_obj.id
  puts "查询(#{http_url})项目ID: #{@project_id} 群组ID:#{project_obj.namespace.id}"
end

#git_commit(commit_msg = nil) ⇒ Object



92
93
94
95
# File 'lib/core_blur/repo_module.rb', line 92

def git_commit(commit_msg = nil)
  commit_msg = get_commit_msg
  super commit_msg
end

#git_tagObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/core_blur/repo_module.rb', line 96

def git_tag
  current = Dir.pwd
  Dir.chdir(self.path)
  dir_name = File.basename(self.path)
  puts "\n⏩ 推送版本号tag(#{dir_name})"
  discard_pull
  if self.build_item.snapshot or self.third
    git_tag_delete_local(pod_version_final)
    git_tag_delete_origin(pod_version_final)
  end
  git_tag_local(pod_version_final)
  git_tag_origin(pod_version_final)
  Dir.chdir(current)
end

#update_binaryObject



53
54
55
56
57
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
# File 'lib/core_blur/repo_module.rb', line 53

def update_binary
  source_files_array = Array.new
  if  podspec_content["source_files"].class == Array
    source_files_array = podspec_content["source_files"]
  else
    source_files_array << podspec_content["source_files"]
  end
  sub_specs = podspec_content["subspecs"]
  if sub_specs
    sub_specs.each do |sub_spec|
      if  podspec_content["source_files"].class == Array
        source_files_array = source_files_array + sub_spec["source_files"]
      else
        source_files_array << sub_spec["source_files"]
      end
    end
  end
  have_implementation = false
  source_files_array.each do |source_files|
    source_files_path = "#{self.path}/#{source_files}"
    if FileHelper.have_implementation_files(source_files_path)
      have_implementation = true
      break
    end
  end
  if not have_implementation or pod_name == "MUCDebugPlugins"
    build_item.real_device = false
    build_item.simulator = false
    warn = "当前组件无实现文件或定制为不需要打二进制"
    puts warn
    pusher.push("【⚠️组件不构建二进制提醒】", warn)
  end
end

#validateObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/core_blur/repo_module.rb', line 25

def validate
  if pod_name.empty?or pod_version.empty?
    error = "pod_name pod_version 均不能为空"
    pusher.push("❌ 打包失败", error)
    Process.exit(-1)
  end
  if pod_name == "xxx" or pod_version == "xxx" or ssh_url == "xxx" or branch == "xxx"
    error = "pod_name pod_version ssh_url branch 任一个都不能为xxx"
    pusher.push("❌ 打包失败", error)
    Process.exit(-1)
  end
  if pod_version.include?("SNAPSHOT")
    error = "版本号里不能带SNAPSHOT,如需SNAPSHOT请使用snapshot参数"
    pusher.push("❌ 打包失败", error)
    Process.exit(-1)
  end
  if self.third and self.build_item.snapshot
    error = "三方库不能打SNAPSHOT包"
    pusher.push("❌ 打包失败", error)
    Process.exit(-1)
  end
end