Class: Fastlane::Actions::UnpAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/unp/actions/unp_action.rb

Class Method Summary collapse

Class Method Details

.authorsObject



75
76
77
# File 'lib/fastlane/plugin/unp/actions/unp_action.rb', line 75

def self.authors
  ["Xu Zhen"]
end

.available_optionsObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/fastlane/plugin/unp/actions/unp_action.rb', line 88

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :api_key,
                            env_name: "UNP_AIP_KEY",
                         description: "你到蒲公英账号 api key",
                            optional: false,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :ipa,
                                 env_name: "UNP_IPA",
                                 description: "你所生成的IPA文件的路径。你可以使用环境变量来只想 UNP_IPA",
                                 default_value: Actions.lane_context[SharedValues::IPA_OUTPUT_PATH],
                                 optional: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("找不到.ipa文件'#{value}'") unless File.exist?(value)
                                 end),
    FastlaneCore::ConfigItem.new(key: :update_description,
                                 env_name: "UNP_UPDATE_DESCRIPTION",
                                 description: "设置你app的描述信息",
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :install_type,
                                 env_name: "UNP_INSTALL_TYPE",
                                 description: "设置你安装app的类型,值为(1,2,3,默认为1 公开安装)",
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :install_date,
                                 env_name: "UNP_INSTALL_DATE",
                                 description: "设置安装有效期,值为:1 设置有效时间, 2 长期有效,如果不填写不修改上一次的设置",
                                 optional: true,
                                 type: String)
  ]
end

.descriptionObject



71
72
73
# File 'lib/fastlane/plugin/unp/actions/unp_action.rb', line 71

def self.description
  "应用上传到蒲公英, 详情查看 https://www.pgyer.com"
end

.detailsObject



83
84
85
86
# File 'lib/fastlane/plugin/unp/actions/unp_action.rb', line 83

def self.details
  # Optional:
  "将beta 版版本的应用上传到蒲公英,发布测试"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


121
122
123
124
125
126
127
# File 'lib/fastlane/plugin/unp/actions/unp_action.rb', line 121

def self.is_supported?(platform)
  # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
  # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
  #
  [:ios].include?(platform)
  true
end

.return_valueObject



79
80
81
# File 'lib/fastlane/plugin/unp/actions/unp_action.rb', line 79

def self.return_value
  # 返回上传链接
end

.run(params) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/fastlane/plugin/unp/actions/unp_action.rb', line 9

def self.run(params)
  UI.message("The unp plugin is working!")
  # api_host = 'https://www.pgyer.com/apiv2/app/upload'
  api_host = 'https://www.xcxwo.com/apiv2/app/upload'
  api_key = params[:api_key]

  build_file = [
    params[:ipa]
  ].detect { |e| !e.to_s.empty? }

  if build_file.nil?
    UI.user_error!("没有找到需要上传的包")
  end
  UI.message("即将上传 #{build_file}")

  # 上传描述信息
  update_description = params[:update_description]
  if update_description.nil?
    update_description = ''
  end
  install_type = params[:install_type]
  if install_type.nil?
    install_type = '1'
  end

  install_date = params[:install_date]
  if install_date.nil?
    install_date = '2'
  end
  # 开始上传
  conn_options = {
    request: {
      timeout: 1000,
      open_timeout: 300
    }
  }

  pager_client = Faraday.new(nil, conn_options) do |c|
    c.request(:multipart)
    c.request(:url_encoded)
    c.response(:json, content_type: /\bjson$/)
    c.adapter(:net_http)
  end

  params = {
    '_api_key' => api_key,
    'file' => Faraday::UploadIO.new(build_file, 'application/octet-stream'),
    'buildInstallType' => install_type,
    'buildInstallDate' => install_date,
    'buildUpdateDescription' => update_description
  }
  UI.message("开始上传#{build_file}到蒲公英")
  response = pager_client.post(api_host, params)
  info = response.body

  if info['code'] != 0
    UI.user_error!("上传失败#{info['message']}")
  end
  UI.success("上传成功 https://www.pgyer.com/#{info['data']['buildShortcutUrl']}")
  return "https://www.pgyer.com/#{info['data']['buildShortcutUrl']}"
end