ocean_package 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,92 @@
1
+
2
+ module OceanPackage
3
+ class Oss
4
+
5
+ # oss bucket 名称
6
+ attr_accessor :oss_bucket_name
7
+ # oss bucket 路径
8
+ attr_accessor :oss_bucket_path
9
+ # oss endpoint
10
+ attr_accessor :oss_endpoint
11
+
12
+ def initialize(bucket_name, bucket_path, endpoint)
13
+ @oss_bucket_name = bucket_name
14
+ @oss_bucket_path = bucket_path
15
+ @oss_endpoint = endpoint
16
+ end
17
+
18
+ # 最终的 bucket path
19
+ def final_oss_bucket_path
20
+ if @oss_bucket_path.end_with?('/')
21
+ @oss_bucket_path
22
+ else
23
+ @oss_bucket_path + '/'
24
+ end
25
+ end
26
+
27
+ # 文件在 oss 上的路径
28
+ def oss_file_path(name)
29
+ final_oss_bucket_path + name
30
+ end
31
+
32
+ # 校验
33
+ def check
34
+ oss_bucket_name_value = "#{@oss_bucket_name}"
35
+ oss_bucket_path_value = "#{@oss_bucket_path}"
36
+ oss_endpoint_value = "#{@oss_endpoint}"
37
+
38
+ if oss_bucket_name_value.empty? || oss_bucket_path_value.empty? || oss_endpoint_value.empty?
39
+ return false
40
+ end
41
+ return true
42
+ end
43
+
44
+ # 上传文件到 oss 的命令
45
+ def upload_cmd(file_path, name)
46
+ cmd = '${HOME}/ossutilmac64' + ' cp ' + file_path
47
+ cmd += ' '
48
+ cmd += 'oss://' + @oss_bucket_name + oss_file_path(name)
49
+
50
+ Log.info("oss upload_cmd: #{cmd}")
51
+
52
+ cmd
53
+ end
54
+
55
+ # 上传文件到 oss
56
+ # file_path:文件路径
57
+ # name:文件在 oss 上的名称
58
+ # return: 文件的链接 url
59
+ def upload(file_path, name)
60
+
61
+ file_path_value = "#{file_path}"
62
+ name_value = "#{name}"
63
+ if file_path_value.empty? || name_value.empty?
64
+
65
+ Log.error("oss upload file path or name is empty, please check !!!")
66
+
67
+ return ''
68
+ end
69
+
70
+ cmd = upload_cmd(file_path, name)
71
+ res = system(cmd)
72
+ Log.info("oss upload result: #{res}")
73
+
74
+ unless res == true
75
+ Log.error("oss upload fail, please check !!!")
76
+ return ''
77
+ end
78
+
79
+ url = fetch_file_url(name)
80
+
81
+ Log.info("oss file url: #{url}")
82
+
83
+ url
84
+ end
85
+
86
+ # 文件 name 在 oss 上的路径
87
+ def fetch_file_url(name)
88
+ 'https://' + @oss_bucket_name + '.' + @oss_endpoint + oss_file_path(name)
89
+ end
90
+ end
91
+
92
+ end
@@ -0,0 +1,242 @@
1
+
2
+ module OceanPackage
3
+
4
+ class Package
5
+
6
+ # .xcworkspace 文件路径
7
+ attr_accessor :workspace_path
8
+ # scheme 名称
9
+ attr_accessor :scheme
10
+ # 配置信息: Debug, Release
11
+ attr_accessor :configuration
12
+
13
+ # archive 归档路径
14
+ attr_accessor :archive_path
15
+ # 导出ipa包使用的plist文件
16
+ attr_accessor :export_options_plist
17
+
18
+ # 公司名称
19
+ attr_accessor :company_name
20
+ # 本次打包的时间
21
+ attr_accessor :date_time
22
+
23
+ # 开始时间
24
+ attr_accessor :start_time
25
+ # 结束时间
26
+ attr_accessor :end_time
27
+
28
+ def initialize(workspace_path, scheme, configuration, archive_path, company_name, export_options_plist)
29
+ @workspace_path = workspace_path
30
+ @scheme = scheme
31
+ @configuration = configuration
32
+ @archive_path = archive_path
33
+ @company_name = company_name
34
+ @date_time = Time.new.strftime("%Y-%m-%d_%H-%M-%S")
35
+ @export_options_plist = export_options_plist
36
+ end
37
+
38
+ # workspace 的路径
39
+ def final_workspace_path
40
+ "#{@workspace_path}"
41
+ end
42
+
43
+ # 项目的根目录,也就是 .xcworkspace 所在的目录
44
+ def project_root_path
45
+ File.dirname(final_workspace_path)
46
+ end
47
+
48
+ # 项目的名称
49
+ def project_name
50
+ File.basename(final_workspace_path, ".*")
51
+ end
52
+
53
+ # 执行打包相关命令
54
+ def run
55
+ @start_time = Time.now
56
+ check
57
+ clean
58
+ archive
59
+ export
60
+ @end_time = Time.now
61
+ # 返回打包成功的 ipa 文件路径
62
+ ipa_file_path
63
+ end
64
+
65
+ # 一些校验
66
+ def check
67
+
68
+ workspace_path_value = final_workspace_path
69
+ unless workspace_path_value.end_with?(".xcworkspace")
70
+ Log.error("workspace path error, please check !!!")
71
+ exit(1)
72
+ end
73
+
74
+ scheme_value = "#{@scheme}"
75
+ if scheme_value.empty?
76
+ Log.error("please check scheme value !!!")
77
+ exit(1)
78
+ end
79
+
80
+ configuration_value = "#{@configuration}"
81
+ if configuration_value.empty?
82
+ Log.error("please check configuration value !!!")
83
+ exit(1)
84
+ end
85
+ # 有可能项目存在自定义的 configuration,所以不进行校验
86
+
87
+ archive_path_value = "#{@archive_path}"
88
+ if archive_path_value.empty?
89
+ Log.error("please check archive path !!!")
90
+ exit(1)
91
+ end
92
+
93
+ export_options_plist_value = "#{@export_options_plist}"
94
+ if export_options_plist_value.empty?
95
+ Log.error("please check export options plist value !!!")
96
+ exit(1)
97
+ end
98
+
99
+ end
100
+
101
+ # **************************************
102
+ # clean
103
+ # **************************************
104
+
105
+ # clean cmd
106
+ def clean_cmd
107
+ cmd = 'xcodebuild'
108
+ cmd += ' clean'
109
+ cmd += ' -workspace ' + @workspace_path
110
+ cmd += ' -scheme ' + @scheme
111
+ cmd += ' -configuration ' + @configuration
112
+
113
+ Log.divider
114
+ Log.info("clean command: #{cmd}")
115
+ Log.divider
116
+
117
+ cmd
118
+ end
119
+
120
+ # clean
121
+ def clean
122
+ res = system(clean_cmd)
123
+ Log.info("clean result: #{res}")
124
+
125
+ unless res == true
126
+ Log.error("clean fail, please check!!!")
127
+ exit(1)
128
+ end
129
+ end
130
+
131
+ # **************************************
132
+ # archive
133
+ # **************************************
134
+
135
+ # archive 路径,会判断结尾 '/'
136
+ def processed_archive_path
137
+ if @archive_path.end_with?('/')
138
+ @archive_path
139
+ else
140
+ @archive_path + '/'
141
+ end
142
+ end
143
+
144
+ # 最终的打包路径
145
+ def final_archive_path
146
+ path = processed_archive_path
147
+ path += @company_name + '/'
148
+ path += project_name + '/'
149
+ path += @date_time + '/'
150
+
151
+ Log.info("final archive path: #{path}")
152
+
153
+ path
154
+ end
155
+
156
+ # xcarchive 文件路径
157
+ def archive_file_path
158
+ path = final_archive_path
159
+ path += project_name
160
+ path += '.xcarchive'
161
+
162
+ Log.info("archive file path: #{path}")
163
+
164
+ path
165
+ end
166
+
167
+ # archive cmd
168
+ def archive_cmd
169
+ cmd = 'xcodebuild'
170
+ cmd += ' -workspace ' + final_workspace_path
171
+ cmd += ' -scheme ' + @scheme
172
+ cmd += ' -configuration ' + @configuration
173
+ cmd += ' -archivePath ' + archive_file_path
174
+ cmd += ' archive'
175
+
176
+ Log.divider
177
+ Log.info("archive command: #{cmd}")
178
+ Log.divider
179
+
180
+ cmd
181
+ end
182
+
183
+ # archive
184
+ def archive
185
+ res = system(archive_cmd)
186
+
187
+ Log.info("archive result: #{res}")
188
+
189
+ unless res == true
190
+ Log.error("archive fail, please check !!!")
191
+ exit(1)
192
+ end
193
+
194
+ end
195
+
196
+ # **************************************
197
+ # export
198
+ # **************************************
199
+
200
+ def export_cmd
201
+ cmd = 'xcodebuild'
202
+ cmd += ' -exportArchive'
203
+ cmd += ' -archivePath ' + archive_file_path
204
+ cmd += ' -exportPath ' + final_archive_path
205
+ cmd += ' -exportOptionsPlist ' + @export_options_plist
206
+
207
+ Log.divider
208
+ Log.info("export command: #{cmd}")
209
+ Log.divider
210
+
211
+ cmd
212
+ end
213
+
214
+ def export
215
+ res = system(export_cmd)
216
+
217
+ Log.info("export result: #{res}")
218
+
219
+ unless res == true
220
+ Log.error("export fail, please check !!!")
221
+ exit(1)
222
+ end
223
+ end
224
+
225
+ # **************************************
226
+ # ipa
227
+ # **************************************
228
+
229
+ # ipa 文件的路径
230
+ def ipa_file_path
231
+ path = final_archive_path
232
+ path += project_name
233
+ path += '.ipa'
234
+
235
+ Log.info("ipa file path: #{path}")
236
+
237
+ path
238
+ end
239
+
240
+ end
241
+
242
+ end
@@ -0,0 +1,3 @@
1
+ module OceanPackage
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,43 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "ocean_package/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ocean_package"
8
+ spec.version = OceanPackage::VERSION
9
+ spec.authors = ["ocean"]
10
+ spec.email = ["849638313@qq.com"]
11
+
12
+ spec.summary = %q{ocean package}
13
+ spec.description = %q{auto package for iOS}
14
+ spec.homepage = "https://github.com/oceanfive/ocean_package"
15
+ spec.license = "MIT"
16
+
17
+ # # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
+ #
22
+ # spec.metadata["homepage_uri"] = spec.homepage
23
+ # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
24
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
25
+ # else
26
+ # raise "RubyGems 2.0 or newer is required to protect against " \
27
+ # "public gem pushes."
28
+ # end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ # spec.bindir = "exe"
36
+ # spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.executables << 'oceanpackage'
38
+ spec.require_paths = ["lib"]
39
+
40
+ spec.add_development_dependency "bundler", "~> 1.17.2"
41
+ spec.add_development_dependency "rake", "~> 10.0"
42
+ spec.add_development_dependency "minitest", "~> 5.0"
43
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ocean_package
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ocean
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-08-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.17.2
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.17.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description: auto package for iOS
56
+ email:
57
+ - 849638313@qq.com
58
+ executables:
59
+ - oceanpackage
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".idea/.gitignore"
65
+ - ".idea/.rakeTasks"
66
+ - ".idea/dictionaries/ocean.xml"
67
+ - ".idea/inspectionProfiles/Project_Default.xml"
68
+ - ".idea/misc.xml"
69
+ - ".idea/modules.xml"
70
+ - ".idea/ocean_package.iml"
71
+ - ".idea/vcs.xml"
72
+ - ".travis.yml"
73
+ - CODE_OF_CONDUCT.md
74
+ - Gemfile
75
+ - Gemfile.lock
76
+ - LICENSE.txt
77
+ - README.md
78
+ - Rakefile
79
+ - bin/console
80
+ - bin/oceanpackage
81
+ - bin/setup
82
+ - lib/ocean_package.rb
83
+ - lib/ocean_package/command.rb
84
+ - lib/ocean_package/config.rb
85
+ - lib/ocean_package/constants.rb
86
+ - lib/ocean_package/dingtalk.rb
87
+ - lib/ocean_package/fir.rb
88
+ - lib/ocean_package/ipa.rb
89
+ - lib/ocean_package/logger.rb
90
+ - lib/ocean_package/oss.rb
91
+ - lib/ocean_package/package.rb
92
+ - lib/ocean_package/version.rb
93
+ - ocean_package.gemspec
94
+ homepage: https://github.com/oceanfive/ocean_package
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubygems_version: 3.0.3
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: ocean package
117
+ test_files: []