ocean_package 0.6.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 278a62419d25e625a28732bf86bf529dc840f3720733f550e1bc135e260c5289
4
- data.tar.gz: a7852fbf63ee4f5b54e3ba8406f8e30618690e5c60e97f189bbc57b54e8dcf08
3
+ metadata.gz: 9b372a1a30d54bb10b757aecbf207cea5f235f7144e0a7e020f8b24f73ba48fc
4
+ data.tar.gz: b95ed7d2ba0abeb4aa9f6c02f2e39e60270526e631ee24a536f2ce6f4520bd0f
5
5
  SHA512:
6
- metadata.gz: e4cd1de69f766edfae7040fc5c2e3f4536e07987efafc5ec4d7e78228ae58283a3fe4b2df306777518aebd5edd10aa7f4b1cab61a74079137d1742675e9fdf6a
7
- data.tar.gz: 2f1d0110f5a0ba8fa7f0de52ea2c4b64eda35c42803ffa21f8a3f7e90f15ef260aa38042c42da3088765da8586bc21b03599214a8d748fa5ebe16287d47931f3
6
+ metadata.gz: 6dfc40afd770778ea67c6424e63b549a43240b843b4d738c186cff7730852f64af6baa7e5fdb726e7add2993f4e86ec058e1d9e39747155007c38fc418441cdd
7
+ data.tar.gz: dddfa48f512062b1f6ed3e331a9f9da28fad466bb4d7af4a687a84199f69eb471ec60e9dbea45293a1b3ac262da3a245d17280c1b04e9dd3a9909086d5810dc3
@@ -16,11 +16,13 @@
16
16
  <orderEntry type="library" scope="PROVIDED" name="claide (v1.0.3, ruby-2.6.3-p62) [gem]" level="application" />
17
17
  <orderEntry type="library" scope="PROVIDED" name="concurrent-ruby (v1.1.6, ruby-2.6.3-p62) [gem]" level="application" />
18
18
  <orderEntry type="library" scope="PROVIDED" name="dingbot (v0.2.3, ruby-2.6.3-p62) [gem]" level="application" />
19
+ <orderEntry type="library" scope="PROVIDED" name="faraday (v1.0.1, ruby-2.6.3-p62) [gem]" level="application" />
19
20
  <orderEntry type="library" scope="PROVIDED" name="httparty (v0.18.1, ruby-2.6.3-p62) [gem]" level="application" />
20
21
  <orderEntry type="library" scope="PROVIDED" name="mime-types (v3.3.1, ruby-2.6.3-p62) [gem]" level="application" />
21
22
  <orderEntry type="library" scope="PROVIDED" name="mime-types-data (v3.2020.0512, ruby-2.6.3-p62) [gem]" level="application" />
22
- <orderEntry type="library" scope="PROVIDED" name="minitest (v5.11.3, ruby-2.6.3-p62) [gem]" level="application" />
23
+ <orderEntry type="library" scope="PROVIDED" name="minitest (v5.12.0, ruby-2.6.3-p62) [gem]" level="application" />
23
24
  <orderEntry type="library" scope="PROVIDED" name="multi_xml (v0.6.0, ruby-2.6.3-p62) [gem]" level="application" />
25
+ <orderEntry type="library" scope="PROVIDED" name="multipart-post (v2.1.1, ruby-2.6.3-p62) [gem]" level="application" />
24
26
  <orderEntry type="library" scope="PROVIDED" name="rake (v10.5.0, ruby-2.6.3-p62) [gem]" level="application" />
25
27
  <orderEntry type="library" scope="PROVIDED" name="semantic_logger (v4.7.1, ruby-2.6.3-p62) [gem]" level="application" />
26
28
  </component>
data/Gemfile CHANGED
@@ -9,3 +9,4 @@ gem 'claide', '~> 1.0', '>= 1.0.3'
9
9
  gem 'dingbot'
10
10
  gem 'CFPropertyList'
11
11
  gem 'semantic_logger'
12
+ gem 'faraday'
data/Gemfile.lock CHANGED
@@ -1,7 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ocean_package (0.6.0)
4
+ ocean_package (0.11.0)
5
+ CFPropertyList
6
+ dingbot
7
+ faraday
8
+ multipart-post
9
+ semantic_logger
5
10
 
6
11
  GEM
7
12
  remote: https://rubygems.org/
@@ -11,6 +16,8 @@ GEM
11
16
  concurrent-ruby (1.1.6)
12
17
  dingbot (0.2.3)
13
18
  httparty
19
+ faraday (1.0.1)
20
+ multipart-post (>= 1.2, < 3)
14
21
  httparty (0.18.1)
15
22
  mime-types (~> 3.0)
16
23
  multi_xml (>= 0.5.2)
@@ -19,6 +26,7 @@ GEM
19
26
  mime-types-data (3.2020.0512)
20
27
  minitest (5.11.3)
21
28
  multi_xml (0.6.0)
29
+ multipart-post (2.1.1)
22
30
  rake (10.5.0)
23
31
  semantic_logger (4.7.1)
24
32
  concurrent-ruby (~> 1.0)
@@ -31,6 +39,7 @@ DEPENDENCIES
31
39
  bundler (~> 1.17.2)
32
40
  claide (~> 1.0, >= 1.0.3)
33
41
  dingbot
42
+ faraday
34
43
  minitest (~> 5.0)
35
44
  ocean_package!
36
45
  rake (~> 10.0)
data/README.md CHANGED
@@ -30,11 +30,20 @@ or
30
30
  - `ossutil`, [链接](https://help.aliyun.com/document_detail/120075.html?spm=a2c4g.11186623.2.45.6e491c7akyZ5HE)
31
31
 
32
32
 
33
+ ```
34
+ sudo gem install dingbot
35
+ sudo gem install semantic_logger
36
+ sudo gem install multipart-post
37
+ ```
38
+
33
39
 
34
40
  ## Usage
35
41
 
42
+ > 打包 - 上传到 fir 或 蒲公英平台 - 发送消息到钉钉群
43
+
44
+
36
45
  ```
37
- oceanpackage --workspace-path=/Users/ocean/Desktop/code/iOS/MyApp.xcworkspace --scheme=MyApp --configuration=Debug --archive-path=/Users/ocean/Documents/myipas --export-options-plist=/Users/ocean/Desktop/code/iOS/Company/MyApp/AdHocExportOptions.plist --company-name=MyCompany --fir-token=fir平台的token --change-log=测试一下 --oss-bucket-name=bucket名称 --oss-bucket-path=bucket路径 --oss-endpoint=oss的endpoint --ding-token=钉钉群机器人token --at-mobiles=需要@的人手机号
46
+ oceanpackage --workspace-path=/Users/ocean/Desktop/code/iOS/MyApp.xcworkspace --scheme=MyApp --configuration=Debug --archive-path=/Users/ocean/Documents/myipas --export-options-plist=/Users/ocean/Desktop/code/iOS/Company/MyApp/AdHocExportOptions.plist --company-name=MyCompany --fir-token=fir平台的token --pgy-api-key=蒲公英平台的apikey --change-log=测试一下 --oss-bucket-name=bucket名称 --oss-bucket-path=bucket路径 --oss-endpoint=oss的endpoint --ding-token=钉钉群机器人token --at-mobiles=需要@的人手机号 --extra-export-params="-allowProvisioningUpdates,IPHONEOS_DEPLOYMENT_TARGET=11.0"
38
47
  ```
39
48
 
40
49
  - `--workspace-path`: `.xcworkspace` 文件路径
@@ -44,13 +53,32 @@ oceanpackage --workspace-path=/Users/ocean/Desktop/code/iOS/MyApp.xcworkspace --
44
53
  - `--export-options-plist`: 打包用到的 `export-options` plist 文件路径
45
54
  - `--company-name`: 公司名称,可以不填
46
55
  - `--fir-token`: fir 平台的 token
56
+ - `--pgy-api-key`: 蒲公英平台的 api key
47
57
  - `--change-log`: 更新描述
48
58
  - `--oss-bucket-name`: `oss bucket` 名称
49
59
  - `--oss-bucket-path`: `oss bucket` 路径
50
60
  - `--oss-endpoint`: `oss` 的 `endpoint`
51
61
  - `--ding-token`: 钉钉群机器人的`token`
52
62
  - `--at-mobiles`: 钉钉群需要 @ 的人手机号,多个用 `,` 拼接
63
+ - `--extra-export-params`: 打包的额外参数,多个用 `,` 拼接,例如 `"-allowProvisioningUpdates,IPHONEOS_DEPLOYMENT_TARGET=11.0"`
64
+ - `--open-finder`: 打包完成是否打开对应的文件目录,`--no-open-finder`表示`false`, `--open-finder` 表示 `true`
65
+
66
+
67
+ > 指定 ipa 文件
53
68
 
69
+ - 上传到蒲公英平台命令格式如下:
70
+
71
+ ```
72
+ oceanpackage --configuration=Debug --ipa-file-path=/Users/ocean/Documents/myipas/test.ipa --company-name=company2 --pgy-api-key=蒲公英平台apikey --change-log=测试一下 --oss-bucket-name=bucket名称 --oss-bucket-path=bucket路径 --oss-endpoint=oss的endpoint --ding-token=钉钉群机器人token --at-mobiles=需要@的人手机号
73
+ ```
74
+
75
+ > 只用到上传ipa
76
+
77
+ ```
78
+ oceanpackage --ipa-file-path=${ipa_file_path} \
79
+ --pgy-api-key=${pgy_api_key} \
80
+ --change-log="${update_desc}" \
81
+ ```
54
82
 
55
83
  ## Development
56
84
 
data/lib/ocean_package.rb CHANGED
@@ -2,6 +2,10 @@ require 'fileutils'
2
2
  require 'dingbot'
3
3
  require 'cfpropertylist'
4
4
  require 'semantic_logger'
5
+ require 'multipart_post'
6
+ require 'net/http/post/multipart'
7
+ require 'json'
8
+ require 'find'
5
9
 
6
10
  # 注意:这里使用 require_relative 来引用文件
7
11
  require_relative 'ocean_package/version'
@@ -14,28 +18,19 @@ require_relative 'ocean_package/dingtalk'
14
18
  require_relative 'ocean_package/ipa'
15
19
  require_relative 'ocean_package/logger'
16
20
  require_relative 'ocean_package/package'
21
+ require_relative 'ocean_package/pgy'
17
22
 
18
23
  module OceanPackage
19
24
  require 'claide'
20
25
 
21
26
  def self.run(argvs)
22
- puts "====="
27
+ puts "=========ARGV========="
23
28
  puts ARGV
24
- puts "====="
29
+ puts "=========ARGV========="
25
30
 
26
31
  command = OceanPackage::Command.new(argvs)
27
32
  command.run
28
33
 
29
-
30
- # # command = OceanPackage::Command.new(config)
31
- #
32
- # argv = CLAide::ARGV.new(ARGV)
33
- # if !argv.arguments.include?("oceanpackage")
34
- # puts "不包含命令 oceanpackage"
35
- # exit 1
36
- # end
37
- #
38
- # puts "包含命令 oceanpackage"
39
34
  end
40
35
 
41
36
  end
@@ -6,6 +6,8 @@ module OceanPackage
6
6
  attr_accessor :package
7
7
  # fir 平台
8
8
  attr_accessor :fir
9
+ # 蒲公英平台
10
+ attr_accessor :pgy
9
11
  # oss 对象
10
12
  attr_accessor :oss
11
13
  # ding ding
@@ -20,6 +22,9 @@ module OceanPackage
20
22
  # @ 的手机号
21
23
  attr_accessor :at_mobiles
22
24
 
25
+ # 自定义的ipa文件路径
26
+ attr_accessor :custom_ipa_file_path
27
+
23
28
  def initialize(params = [])
24
29
  argv = CLAide::ARGV.new(params)
25
30
 
@@ -32,7 +37,8 @@ module OceanPackage
32
37
  scheme = argv.option("scheme", "")
33
38
  Log.info("scheme: #{scheme}")
34
39
 
35
- configuration = argv.option("configuration", OceanPackage::Constants::DEFAULT_CONFIGURATION)
40
+ # 默认配置改为空,防止包环境错误
41
+ configuration = argv.option("configuration", "")
36
42
  Log.info("configuration: #{configuration}")
37
43
 
38
44
  archive_path = argv.option("archive-path", OceanPackage::Constants::DEFAULT_ARCHIVE_PATH)
@@ -44,7 +50,21 @@ module OceanPackage
44
50
  export_options_plist = argv.option("export-options-plist", "")
45
51
  Log.info("export_options_plist: #{export_options_plist}")
46
52
 
47
- @package = OceanPackage::Package.new(workspace_path, scheme, configuration, archive_path, company_name, export_options_plist)
53
+ ##### 自定义的 ipa 文件 #####
54
+ ipa_file_path = argv.option("ipa-file-path", "")
55
+ Log.info("ipa_file_path: #{ipa_file_path}")
56
+ @custom_ipa_file_path = ipa_file_path
57
+
58
+ extra_export_params = argv.option("extra-export-params", "")
59
+ Log.info("extra-export-params: #{extra_export_params}")
60
+
61
+ open_finder = argv.flag?("open-finder", false )
62
+ Log.info("open-finder: #{open_finder}")
63
+
64
+ # 自定义ipa文件,使用该文件作为 archive path
65
+ tmp_archive_path = has_custom_ipa_file ? File.dirname("#{ipa_file_path}") : archive_path
66
+ Log.info("tmp_archive_path: #{tmp_archive_path}")
67
+ @package = OceanPackage::Package.new(workspace_path, scheme, configuration, tmp_archive_path, company_name, export_options_plist, extra_export_params, open_finder)
48
68
 
49
69
  fir_token = argv.option("fir-token", "")
50
70
  Log.info("fir_token: #{fir_token}")
@@ -54,7 +74,12 @@ module OceanPackage
54
74
  Log.info("change_log: #{change_log}")
55
75
 
56
76
  fir_log_path = @package.final_archive_path + 'fir.log'
57
- @fir = OceanPackage::Fir.new(fir_token, final_change_log, @package.ipa_file_path, fir_log_path)
77
+ @fir = OceanPackage::Fir.new(fir_token, final_change_log, final_ipa_file_path, fir_log_path)
78
+
79
+ ##### 蒲公英 #####
80
+ pgy_api_key = argv.option("pgy-api-key", "")
81
+ @pgy = OceanPackage::Pgy.new(pgy_api_key, final_change_log, final_ipa_file_path)
82
+ Log.info("pgy_api_key: #{pgy_api_key}")
58
83
 
59
84
  ##### oss #####
60
85
  oss_bucket_name = argv.option("oss-bucket-name", "")
@@ -87,8 +112,22 @@ module OceanPackage
87
112
  end
88
113
  end
89
114
 
115
+ # 是否设置了自定义的ipa文件
116
+ def has_custom_ipa_file
117
+ "#{@custom_ipa_file_path}".empty? ? false : true
118
+ end
119
+
120
+ # 最终的ipa文件路径
121
+ def final_ipa_file_path
122
+ has_custom_ipa_file ? "#{@custom_ipa_file_path}" : @package.ipa_file_path
123
+ end
124
+
125
+ # 运行
90
126
  def run
91
- package.run
127
+ # 没有自定义ipa文件,需要执行打包命令
128
+ unless has_custom_ipa_file
129
+ package.run
130
+ end
92
131
  upload
93
132
  send_ding_talk_msg
94
133
  finished
@@ -96,9 +135,22 @@ module OceanPackage
96
135
 
97
136
  # 上传 ipa 文件
98
137
  def upload
99
- upload_to_fir
138
+ can_fir = fir.check
139
+ can_pgy = pgy.check
140
+ if can_fir
141
+ Log.info("publish platform: fir")
142
+ upload_to_fir
143
+ elsif can_pgy
144
+ Log.info("publish platform: pgy")
145
+ upload_to_pgy
146
+ else
147
+ Log.info("publish platform: none, exit")
148
+ exit(1)
149
+ end
100
150
  end
101
151
 
152
+ # ------ fir 平台 -------
153
+
102
154
  # 上传到 fir 平台
103
155
  def upload_to_fir
104
156
  fir.run
@@ -112,6 +164,13 @@ module OceanPackage
112
164
  @qr_code_url = oss.upload(path, name)
113
165
  end
114
166
 
167
+ # ------ pgy 平台 -------
168
+ def upload_to_pgy
169
+ pgy.run
170
+ @qr_code_url = pgy.get_qr_code_url
171
+ @ipa_download_link = pgy.get_download_url
172
+ end
173
+
115
174
  # 总共时间,单位 秒 s
116
175
  def compute_total_time
117
176
  time1 = package.start_time
@@ -130,7 +189,7 @@ module OceanPackage
130
189
 
131
190
  # web hook 消息内容
132
191
  def make_web_hook_message
133
- ipa = OceanPackage::Ipa.new(package.ipa_file_path)
192
+ ipa = OceanPackage::Ipa.new(final_ipa_file_path)
134
193
  ipa.run
135
194
 
136
195
  # markdown 格式
@@ -145,7 +204,9 @@ module OceanPackage
145
204
  content += "下载链接: [点我](#{@ipa_download_link})" + "\n\n"
146
205
  content += "![二维码](#{@qr_code_url})"
147
206
 
207
+ Log.divider
148
208
  Log.info("web hook message: \n#{content}")
209
+ Log.divider
149
210
 
150
211
  content
151
212
  end
@@ -8,7 +8,6 @@ module OceanPackage
8
8
  DEFAULT_CONFIGURATION = "Debug"
9
9
  DEFAULT_COMPANY_NAME = "YourCompanyName"
10
10
  DEFAULT_ARCHIVE_PATH = "#{Dir.home}/Documents/Ipas/"
11
-
12
11
  end
13
12
 
14
13
  end
@@ -170,7 +170,7 @@ module OceanPackage
170
170
  f.each_line do |line|
171
171
  line_s = "#{line}"
172
172
  if line_s =~ pattern
173
- release_id = line_s.split(' ').last
173
+ path = line_s.split(' ').last
174
174
  break
175
175
  end
176
176
  end
@@ -17,6 +17,12 @@ module OceanPackage
17
17
  logger = Logger.new(STDOUT)
18
18
  logger.info("=========")
19
19
  end
20
+
21
+ # 换行
22
+ def Log.new_line
23
+ logger = Logger.new(STDOUT)
24
+ logger.info("\n")
25
+ end
20
26
  end
21
27
  end
22
28
 
@@ -9,6 +9,8 @@ module OceanPackage
9
9
  attr_accessor :scheme
10
10
  # 配置信息: Debug, Release
11
11
  attr_accessor :configuration
12
+ # 额外的打底参数,比如对buildsettings进行重写
13
+ attr_accessor :extra_export_params
12
14
 
13
15
  # archive 归档路径
14
16
  attr_accessor :archive_path
@@ -25,7 +27,12 @@ module OceanPackage
25
27
  # 结束时间
26
28
  attr_accessor :end_time
27
29
 
28
- def initialize(workspace_path, scheme, configuration, archive_path, company_name, export_options_plist)
30
+ # ipa 最大保存的数目
31
+ attr_accessor :ipa_max_retain_number
32
+ # 打包完成是否打开文件夹
33
+ attr_accessor :open_finder
34
+
35
+ def initialize(workspace_path, scheme, configuration, archive_path, company_name, export_options_plist, extra_export_params, open_finder)
29
36
  @workspace_path = workspace_path
30
37
  @scheme = scheme
31
38
  @configuration = configuration
@@ -33,6 +40,12 @@ module OceanPackage
33
40
  @company_name = company_name
34
41
  @date_time = Time.new.strftime("%Y-%m-%d_%H-%M-%S")
35
42
  @export_options_plist = export_options_plist
43
+ @extra_export_params = extra_export_params
44
+
45
+ @ipa_max_retain_number = 3
46
+ @open_finder = open_finder
47
+ # 预设置开始时间
48
+ @start_time = Time.now
36
49
  end
37
50
 
38
51
  # workspace 的路径
@@ -53,13 +66,22 @@ module OceanPackage
53
66
  # 执行打包相关命令
54
67
  def run
55
68
  @start_time = Time.now
69
+ # 检查必须参数
56
70
  check
71
+ # 清理历史的ipa
72
+ clean_history_ipa
73
+ # clean 项目
57
74
  clean
75
+ # 打包项目
58
76
  archive
77
+ # 导出 ipa 包
59
78
  export
60
79
  @end_time = Time.now
61
80
  # 返回打包成功的 ipa 文件路径
62
81
  ipa_file_path
82
+ if @open_finder
83
+ open_ipa_file_path
84
+ end
63
85
  end
64
86
 
65
87
  # 一些校验
@@ -98,6 +120,51 @@ module OceanPackage
98
120
 
99
121
  end
100
122
 
123
+ # **************************************
124
+ # clean history
125
+ # **************************************
126
+
127
+ def clean_history_ipa
128
+ path = final_archive_path_company_pro
129
+
130
+ sub_paths = Array.new
131
+ Dir.each_child(path) do |x|
132
+ unless "#{x}".eql?(".DS_Store")
133
+ sub_paths.push("#{x}")
134
+ end
135
+ end
136
+
137
+ if sub_paths.length > @ipa_max_retain_number
138
+ Log.divider
139
+ Log.info("clean history ipas: begin =======")
140
+
141
+ count = sub_paths.length - @ipa_max_retain_number
142
+ deleted_paths = sub_paths.first(count)
143
+
144
+ deleted_paths.each do |p|
145
+ new_path = path + p
146
+ Log.info(new_path)
147
+ delete_directory(new_path)
148
+ end
149
+
150
+ Log.info("clean history ipas: end =======")
151
+ Log.divider
152
+ end
153
+ end
154
+
155
+ def delete_directory(dirPath)
156
+ if File.directory?(dirPath)
157
+ Dir.foreach(dirPath) do |subFile|
158
+ if subFile != '.' and subFile != '..'
159
+ delete_directory(File.join(dirPath, subFile));
160
+ end
161
+ end
162
+ Dir.rmdir(dirPath)
163
+ else
164
+ File.delete(dirPath)
165
+ end
166
+ end
167
+
101
168
  # **************************************
102
169
  # clean
103
170
  # **************************************
@@ -141,15 +208,29 @@ module OceanPackage
141
208
  end
142
209
  end
143
210
 
211
+ # 最终的打包路径,包含了公司,项目名称
212
+ def final_archive_path_company_pro
213
+ path = processed_archive_path
214
+ unless "#{@company_name}".empty?
215
+ path += @company_name + '/'
216
+ end
217
+ unless "#{project_name}".empty?
218
+ path += project_name + '/'
219
+ end
220
+
221
+ path
222
+ end
223
+
144
224
  # 最终的打包路径
145
225
  def final_archive_path
146
- path = processed_archive_path
147
- path += @company_name + '/'
148
- path += project_name + '/'
226
+ path = final_archive_path_company_pro
149
227
  path += @date_time + '/'
150
228
 
151
229
  Log.info("final archive path: #{path}")
152
230
 
231
+ # 不存在,需要进行创建,外部传入了 ipa 文件的情况
232
+ FileUtils.mkdir_p(path)
233
+
153
234
  path
154
235
  end
155
236
 
@@ -204,6 +285,17 @@ module OceanPackage
204
285
  cmd += ' -exportPath ' + final_archive_path
205
286
  cmd += ' -exportOptionsPlist ' + @export_options_plist
206
287
 
288
+ unless "#{@extra_export_params}".empty?
289
+ # 分割
290
+ params = "#{@extra_export_params}".split(",")
291
+ # 再拼接
292
+ joined_string = params.join(" ")
293
+
294
+ unless joined_string.empty?
295
+ cmd += ' ' + joined_string
296
+ end
297
+ end
298
+
207
299
  Log.divider
208
300
  Log.info("export command: #{cmd}")
209
301
  Log.divider
@@ -239,6 +331,13 @@ module OceanPackage
239
331
  # 也可以在该目录下查找 ipa 后缀的文件
240
332
  end
241
333
 
334
+ # 打开所在目录
335
+ def open_ipa_file_path
336
+ path = final_archive_path
337
+ open_cmd = "open #{path}"
338
+ system(open_cmd)
339
+ end
340
+
242
341
  end
243
342
 
244
343
  end
@@ -0,0 +1,149 @@
1
+
2
+ module OceanPackage
3
+ class Pgy
4
+ require 'multipart_post'
5
+ require 'net/http/post/multipart'
6
+ require 'json'
7
+
8
+ # # 用户Key,用来标识当前用户的身份
9
+ # attr_accessor :user_key
10
+ # API Key,用来识别API调用者的身份,如不特别说明,每个接口中都需要含有此参数。
11
+ attr_accessor :api_key
12
+ # # 表示一个App组的唯一Key。
13
+ # attr_accessor :app_key
14
+ # 更新日志
15
+ attr_accessor :change_log
16
+ # ipa文件包路径
17
+ attr_accessor :ipa_file_path
18
+
19
+ # 短链接
20
+ attr_accessor :short_url
21
+ # 二维码链接
22
+ attr_accessor :qr_code_url
23
+
24
+ # 初始化
25
+ def initialize(api_key, change_log, ipa_file_path)
26
+ @api_key = api_key
27
+ @change_log = change_log
28
+ @ipa_file_path = ipa_file_path
29
+ @short_url = ""
30
+ @qr_code_url = ""
31
+ end
32
+
33
+ # 校验
34
+ def check
35
+
36
+ # user_key_value = "#{@user_key}"
37
+ # if user_key_value.empty?
38
+ # Log.error("pgy user key is empty, please check !!!")
39
+ # return false
40
+ # end
41
+
42
+ api_key_value = "#{@api_key}"
43
+ if api_key_value.empty?
44
+ Log.error("pgy api key is empty, please check !!!")
45
+ return false
46
+ end
47
+
48
+ # app_key_value = "#{@app_key}"
49
+ # if app_key_value.empty?
50
+ # Log.error("pgy app key is empty, please check !!!")
51
+ # return false
52
+ # end
53
+
54
+ ipa_file_path_value = "#{@ipa_file_path}"
55
+ if ipa_file_path_value.empty?
56
+ Log.error("ipa file path is empty, please check !!!")
57
+ return false
58
+ end
59
+
60
+ return true
61
+ end
62
+
63
+ # 运行
64
+ def run
65
+ unless check
66
+ return
67
+ end
68
+ publish
69
+ end
70
+
71
+ # 上传
72
+ def publish
73
+ url = URI.parse('https://www.pgyer.com/apiv2/app/upload')
74
+ File.open("#{@ipa_file_path}") do |ipa|
75
+
76
+ # 构建必要的参数
77
+ ipa_file_name = Time.new.strftime("%Y-%m-%d_%H-%M-%S") + ".ipa"
78
+ require_params = {
79
+ "file" => UploadIO.new(ipa, "multipart/form-data", ipa_file_name),
80
+ "_api_key" => "#{@api_key}",
81
+ "buildUpdateDescription" => "#{@change_log}",
82
+ }
83
+
84
+ # 构造请求
85
+ req = Net::HTTP::Post::Multipart.new(url.path, require_params)
86
+
87
+ # 网络http
88
+ net = Net::HTTP.new(url.host, url.port)
89
+ # 这里需要设置,否则会有 EPIPE: Broken pipe 错误
90
+ net.use_ssl = true
91
+ net.verify_mode = OpenSSL::SSL::VERIFY_NONE
92
+ net.set_debug_output($stdout)
93
+
94
+ # 发起请求
95
+ res = net.start do |http|
96
+ http.use_ssl = true
97
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
98
+ http.request(req)
99
+ end
100
+
101
+ Log.divider
102
+ Log.info(res)
103
+
104
+ # 具体参考 https://www.pgyer.com/doc/view/api#paramInfo
105
+ case res
106
+ when Net::HTTPSuccess
107
+ # 响应是字符串类型,需要转为json进行处理
108
+ json_value = JSON.parse(res.body)
109
+ Log.divider
110
+ Log.info('pgy upload response: ')
111
+ Log.info(json_value)
112
+ # 成功
113
+ data = json_value["data"]
114
+ short_url = data["buildShortcutUrl"]
115
+ qr_code_url = data["buildQRCodeURL"]
116
+ @short_url = short_url
117
+ @qr_code_url = qr_code_url
118
+ Log.error(@short_url)
119
+ Log.error(@qr_code_url)
120
+ else
121
+ # 失败
122
+ Log.error("pgy publish fail, please check !!!")
123
+ exit(1)
124
+ end
125
+ end
126
+ end
127
+
128
+ # 获取下载链接
129
+ def get_download_url
130
+ # 需要有固定的前缀
131
+ url = "https://www.pgyer.com/" + @short_url
132
+
133
+ Log.divider
134
+ Log.info(url)
135
+
136
+ url
137
+ end
138
+
139
+ # 获取二维码链接
140
+ def get_qr_code_url
141
+ url = "#{@qr_code_url}"
142
+
143
+ Log.divider
144
+ Log.info(url)
145
+
146
+ url
147
+ end
148
+ end
149
+ end
@@ -1,3 +1,3 @@
1
1
  module OceanPackage
2
- VERSION = "0.6.0"
2
+ VERSION = "0.12.0"
3
3
  end
@@ -37,6 +37,12 @@ Gem::Specification.new do |spec|
37
37
  spec.executables << 'oceanpackage'
38
38
  spec.require_paths = ["lib"]
39
39
 
40
+ spec.add_dependency 'dingbot'
41
+ spec.add_dependency 'CFPropertyList'
42
+ spec.add_dependency 'semantic_logger'
43
+ spec.add_dependency 'faraday'
44
+ spec.add_dependency 'multipart-post'
45
+
40
46
  spec.add_development_dependency "bundler", "~> 1.17.2"
41
47
  spec.add_development_dependency "rake", "~> 10.0"
42
48
  spec.add_development_dependency "minitest", "~> 5.0"
metadata CHANGED
@@ -1,15 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ocean_package
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ocean
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-06 00:00:00.000000000 Z
11
+ date: 2021-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dingbot
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: CFPropertyList
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: semantic_logger
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: multipart-post
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
13
83
  - !ruby/object:Gem::Dependency
14
84
  name: bundler
15
85
  requirement: !ruby/object:Gem::Requirement
@@ -89,6 +159,7 @@ files:
89
159
  - lib/ocean_package/logger.rb
90
160
  - lib/ocean_package/oss.rb
91
161
  - lib/ocean_package/package.rb
162
+ - lib/ocean_package/pgy.rb
92
163
  - lib/ocean_package/version.rb
93
164
  - ocean_package.gemspec
94
165
  homepage: https://github.com/oceanfive/ocean_package