Class: Lhj::AppVersionInfo
- Inherits:
-
Object
- Object
- Lhj::AppVersionInfo
- Defined in:
- lib/lhj/helper/app_version_info.rb
Overview
version info
Constant Summary collapse
- VERSION_REGEX =
/^(?<begin>[^#]*MARKETING_VERSION\s*=\s*)(?<value>(?<major>[0-9]+)(\.(?<minor>[0-9]+))?(\.(?<patch>[0-9]+))?(?<appendix>(\.[0-9]+)*)?(-(?<prerelease>(.+)))?)(?<end>)/
Class Method Summary collapse
Instance Method Summary collapse
- #branch_name ⇒ Object
- #build_app_version ⇒ Object
- #build_app_version_no ⇒ Object
-
#build_info ⇒ Object
build_app_version (build_app_version_no) (build: build_version).
- #build_updated ⇒ Object
- #build_version ⇒ Object
- #custom_modify ⇒ Object
- #handle_message(m) ⇒ Object
-
#initialize(env, build_number, work_path) ⇒ AppVersionInfo
constructor
A new instance of AppVersionInfo.
- #last_commit_id ⇒ Object
- #modify_code ⇒ Object
- #setup_config ⇒ Object
- #setup_pod_script ⇒ Object
- #setup_shell_script ⇒ Object
- #update_log ⇒ Object
Constructor Details
#initialize(env, build_number, work_path) ⇒ AppVersionInfo
Returns a new instance of AppVersionInfo.
12 13 14 15 16 17 |
# File 'lib/lhj/helper/app_version_info.rb', line 12 def initialize(env, build_number, work_path) @env = env @build_number = build_number @work_path = work_path modify_code end |
Class Method Details
.all_app_version(path) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/lhj/helper/app_version_info.rb', line 73 def self.all_app_version(path) vers = [] Dir.glob("#{path}/*.xcodeproj/*.pbxproj").each do |file| File.readlines(file).each do |l| next unless /MARKETING_VERSION/ =~ l vers << fetch_version(l) end end sort_version_list(vers) end |
.fetch_version(line) ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/lhj/helper/app_version_info.rb', line 85 def self.fetch_version(line) version_match = VERSION_REGEX.match(line) major = version_match[:major].to_i minor = version_match[:minor].to_i || 0 patch = version_match[:patch].to_i || 0 { value: version_match[:value], major: major, minor: minor, patch: patch } end |
.sort_version_list(list) ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'lib/lhj/helper/app_version_info.rb', line 93 def self.sort_version_list(list) list.sort do |a, b| ma = a[:major] <=> b[:major] ma = a[:minor] <=> b[:minor] if ma.zero? ma = a[:patch] <=> b[:patch] if ma.zero? ma end end |
Instance Method Details
#branch_name ⇒ Object
138 139 140 141 142 |
# File 'lib/lhj/helper/app_version_info.rb', line 138 def branch_name Dir.chdir(@work_path) do Lhj::LogHelper.instance.current_branch(@work_path) end end |
#build_app_version ⇒ Object
102 103 104 105 106 |
# File 'lib/lhj/helper/app_version_info.rb', line 102 def build_app_version # app version '1.0.0' vers = AppVersionInfo.all_app_version(@work_path) vers.last[:value] end |
#build_app_version_no ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/lhj/helper/app_version_info.rb', line 112 def build_app_version_no # xcode build version # ${BUILD_NUMBER} of jenkins num = @build_number || '1' if @env == :release num else # "#{@env.to_s}_#{num}" num end end |
#build_info ⇒ Object
build_app_version (build_app_version_no) (build: build_version)
69 70 71 |
# File 'lib/lhj/helper/app_version_info.rb', line 69 def build_info "#{build_app_version} (#{build_app_version_no}) (build: #{build_version})" end |
#build_updated ⇒ Object
133 134 135 136 |
# File 'lib/lhj/helper/app_version_info.rb', line 133 def build_updated time = Time.now time.strftime('%Y-%m-%d %H:%M:%S') end |
#build_version ⇒ Object
124 125 126 127 128 129 130 131 |
# File 'lib/lhj/helper/app_version_info.rb', line 124 def build_version # pu gong ying build number client = Lhj::PgyerShortcut.new(@env) version = 0 version = client.build_version.to_i if client.build_version version += 1 version.to_s end |
#custom_modify ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/lhj/helper/app_version_info.rb', line 162 def custom_modify return if @env != :release Dir["#{@work_path}/**/*.m"].each do |file| str = '' File.open(file) do |f| f.each_line do |line| next if line =~ /todo/ str += line end end File.open(file, 'w+') do |f| f.write(str) end end end |
#handle_message(m) ⇒ Object
151 152 153 154 155 156 157 158 159 160 |
# File 'lib/lhj/helper/app_version_info.rb', line 151 def (m) = m unless .empty? = .gsub('seconds ', '秒').gsub('minutes ', '分钟').gsub('hours ', '小时').gsub('weeks ', '周').gsub('days ', '天').gsub('ago ', '前') Lhj::TeamMemberConfig.config.each do |key, value| = .gsub(key, value) if =~ /#{key}/ end end end |
#last_commit_id ⇒ Object
108 109 110 |
# File 'lib/lhj/helper/app_version_info.rb', line 108 def last_commit_id Lhj::Actions.last_git_commit_hash(true) end |
#modify_code ⇒ Object
19 20 21 22 23 |
# File 'lib/lhj/helper/app_version_info.rb', line 19 def modify_code setup_config setup_shell_script setup_pod_script end |
#setup_config ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/lhj/helper/app_version_info.rb', line 25 def setup_config number = build_app_version_no Dir.chdir(@work_path) do command = %(xcrun agvtool new-version -all #{number}) Actions.sh(command, log: false) end FileUtils.rm_r Dir.glob("#{@work_path}/archive*.zip") end |
#setup_pod_script ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/lhj/helper/app_version_info.rb', line 46 def setup_pod_script project_path = Dir["#{@work_path}/*.xcodeproj"].first project = Xcodeproj::Project.open(project_path) target = project.targets.first Dir.glob("#{@work_path}/**/Pods-#{target.display_name}-frameworks.sh").each do |file| need_modify = false content = '' File.open(file) do |f| f.each_line do |line| if line =~ /source="\$\(readlink "\${source}"\)"/ content += ' source="$(readlink -f "${source}")"' content += "\n" need_modify = true else content += line end end end File.write(file, content) if need_modify end end |
#setup_shell_script ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/lhj/helper/app_version_info.rb', line 34 def setup_shell_script project_path = Dir["#{@work_path}/*.xcodeproj"].first project = Xcodeproj::Project.open(project_path) target = project.targets.first handle_list = target.shell_script_build_phases.select { |s| s.display_name == '[CP] Copy Pods Resources' || s.display_name == '[CP] Embed Pods Frameworks' } handle_list.each do |shell| shell.run_only_for_deployment_postprocessing = '0' shell.build_action_mask = '12' end project.save end |
#update_log ⇒ Object
144 145 146 147 148 149 |
# File 'lib/lhj/helper/app_version_info.rb', line 144 def update_log Dir.chdir(@work_path) do = Lhj::Actions.git_log_last_commits(' %an %ar - %s;', 6, :exclude_merges, 'short', false) () end end |