ocean_package 0.7.0 → 0.13.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e28f7f81431f3e160d1063694c6e2fcba7cffffdd9f5bb7fae4e7f9c54acb5d1
4
- data.tar.gz: 842dae0c668d80d20ad80d4b5b6fe1e3d0316d75b04ac5fbcb17cdb45afbdacf
3
+ metadata.gz: ceca75b90d4c107d40b58abb14172f059a4edf39575973dd49ca17cdb71d2774
4
+ data.tar.gz: 7aebc168f950e635c47bd41c69434ddded358b012a4cf5fc93ba756786a38289
5
5
  SHA512:
6
- metadata.gz: 2cc5adbe418c1827987f9db8273242ac486ae86f53cbcbc63d06d644067a7a69747d5e8854da81e49232f121842ae95efc5dcd1184ef05f5a560b026bde88678
7
- data.tar.gz: 2e46cd86d32aeeea542c4e9f4122121c70a4386eed5a3a23b097aae00146d846262b39229a2b30f5c4cb3670dc955c9ac888ba1e76c5bea9e2e4b361e3e371af
6
+ metadata.gz: ff1e88a0b70f2728f6994d81a1c9d92939ab852d8081ff40da436129e7d84f3c63c639474a7c8b4c0bec113bfdb79aa5a4dddeb9e5d4131de600a73eee7da1be
7
+ data.tar.gz: 66504e35c19e08d23d9bd2a34dbac17afd1566cc22b4fe57ae1542cba2d6f7a24be8acb696a3607d6a935617f924771ee4835007c07ef1ef4d028f25c25e4f9d
@@ -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.14.4, 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.12.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
@@ -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
 
@@ -172,6 +253,7 @@ module OceanPackage
172
253
  cmd += ' -configuration ' + @configuration
173
254
  cmd += ' -archivePath ' + archive_file_path
174
255
  cmd += ' archive'
256
+ cmd += ' -allowProvisioningUpdates'
175
257
 
176
258
  Log.divider
177
259
  Log.info("archive command: #{cmd}")
@@ -204,6 +286,17 @@ module OceanPackage
204
286
  cmd += ' -exportPath ' + final_archive_path
205
287
  cmd += ' -exportOptionsPlist ' + @export_options_plist
206
288
 
289
+ unless "#{@extra_export_params}".empty?
290
+ # 分割
291
+ params = "#{@extra_export_params}".split(",")
292
+ # 再拼接
293
+ joined_string = params.join(" ")
294
+
295
+ unless joined_string.empty?
296
+ cmd += ' ' + joined_string
297
+ end
298
+ end
299
+
207
300
  Log.divider
208
301
  Log.info("export command: #{cmd}")
209
302
  Log.divider
@@ -239,6 +332,13 @@ module OceanPackage
239
332
  # 也可以在该目录下查找 ipa 后缀的文件
240
333
  end
241
334
 
335
+ # 打开所在目录
336
+ def open_ipa_file_path
337
+ path = final_archive_path
338
+ open_cmd = "open #{path}"
339
+ system(open_cmd)
340
+ end
341
+
242
342
  end
243
343
 
244
344
  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.7.0"
2
+ VERSION = "0.13.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.7.0
4
+ version: 0.13.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-04-25 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