fastlane-plugin-android_channels 0.2.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 78a1d2d5d451df8a32ec9f6f6fe05a80a67c6615158b97dfa371ba5e18ef3d50
4
+ data.tar.gz: '0908ad55264545f787a1f190155a480bff7dd71ba228b06c414a986b823cbb3c'
5
+ SHA512:
6
+ metadata.gz: a2064057157aca710149bae18336e88ebf3070719eae6474f829383dbc6bd60f47f254bc05dccb6b13e9312511bdab11fb7c288abca9de80ad5547ef86d929ef
7
+ data.tar.gz: d2a6405e66c6b538ec4402b6c06f5b9833bf1a5c226c6952178e2773f799dce7283f2529e4d7014e4a3935020a1955f80fce69360b45423ae34e490d065abb97
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 icyleaf <icyleaf.cn@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # android_channels plugin
2
+
3
+ [![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-android_channels)
4
+
5
+ ## Getting Started
6
+
7
+ This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-android_channels`, add it to your project by running:
8
+
9
+ ```bash
10
+ fastlane add_plugin android_channels
11
+ ```
12
+
13
+ ## About android_channels
14
+
15
+ Package unsign apk with channels
16
+
17
+ **Note to author:** Add a more detailed description about this plugin here. If your plugin contains multiple actions, make sure to mention them here.
18
+
19
+ ## Example
20
+
21
+ Check out the [example `Fastfile`](fastlane/Fastfile) to see how to use this plugin. Try it by cloning the repo, running `fastlane install_plugins` and `bundle exec fastlane test`.
22
+
23
+ **Note to author:** Please set up a sample project to make it easy for users to explore what your plugin does. Provide everything that is necessary to try out the plugin in this project (including a sample Xcode/Android project if necessary)
24
+
25
+ ## Run tests for this plugin
26
+
27
+ To run both the tests, and code style validation, run
28
+
29
+ ```
30
+ rake
31
+ ```
32
+
33
+ To automatically fix many of the styling issues, use
34
+ ```
35
+ rubocop -a
36
+ ```
37
+
38
+ ## Issues and Feedback
39
+
40
+ For any other issues and feedback about this plugin, please submit it to this repository.
41
+
42
+ ## Troubleshooting
43
+
44
+ If you have trouble using plugins, check out the [Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/) guide.
45
+
46
+ ## Using _fastlane_ Plugins
47
+
48
+ For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/).
49
+
50
+ ## About _fastlane_
51
+
52
+ _fastlane_ is the easiest way to automate beta deployments and releases for your iOS and Android apps. To learn more, check out [fastlane.tools](https://fastlane.tools).
@@ -0,0 +1,165 @@
1
+ require 'fastlane/action'
2
+ require 'fileutils'
3
+
4
+ require_relative '../helper/android_channels_helper'
5
+
6
+ module Fastlane
7
+ module Actions
8
+ class AndroidChannelsAction < Action
9
+ def self.run(params)
10
+ apk_file = Helper::AndroidChannelsHelper.determine_apk_file!(params)
11
+ channels = Helper::AndroidChannelsHelper.determine_channels!(params)
12
+ output_path = Helper::AndroidChannelsHelper.determine_output_path!(params)
13
+
14
+ signed = Helper::AndroidChannelsHelper.is_signed?(apk_file)
15
+ summary_params = {
16
+ apk_file: apk_file,
17
+ signed: signed,
18
+ channels: channels,
19
+ output_path: output_path,
20
+ }
21
+
22
+ unless signed
23
+ keystore = Helper::AndroidChannelsHelper.determine_keystore!(params)
24
+ apksigner = Helper::AndroidChannelsHelper.determine_apksigner!(params)
25
+ keystore_password = Helper::AndroidChannelsHelper.determine_keystore_password!(params)
26
+ key_alias = params[:key_alias]
27
+ key_password = params[:key_password]
28
+
29
+ summary_params.merge!({
30
+ apksigner: apksigner,
31
+ keystore: keystore,
32
+ keystore_password: keystore_password,
33
+ key_alias: key_alias,
34
+ key_password: key_password
35
+ })
36
+ end
37
+
38
+ FastlaneCore::PrintTable.print_values(
39
+ title: "Summary for android_channels #{AndroidChannels::VERSION}",
40
+ config: summary_params,
41
+ mask_keys: %i[keystore_password key_password]
42
+ )
43
+
44
+ if signed
45
+ UI.verbose "Packaging channel apk ..."
46
+ Helper::AndroidChannelsHelper.write_apk_with_channels(output_path, apk_file, channels)
47
+ else
48
+ UI.verbose "Signing apk ..."
49
+ signed_file = Helper::AndroidChannelsHelper.sign_apk(apksigner, keystore, keystore_password, apk_file, key_alias, key_password)
50
+
51
+ UI.verbose "Packaging channel apk ..."
52
+ Helper::AndroidChannelsHelper.write_apk_with_channels(output_path, signed_file.path, channels)
53
+ signed_file.unlink
54
+ end
55
+
56
+ total = Dir["#{output_path}/*"].size
57
+ UI.success "Packaged done, total: #{total} apk file(s)."
58
+
59
+ output_path
60
+ end
61
+
62
+ def self.description
63
+ "Package unsign apk with channels"
64
+ end
65
+
66
+ def self.authors
67
+ ["icyleaf"]
68
+ end
69
+
70
+ def self.return_value
71
+ 'The output of signed apk path'
72
+ end
73
+
74
+ def self.details
75
+ "Apply for QYER mobile team for now"
76
+ end
77
+
78
+ def self.available_options
79
+ [
80
+ FastlaneCore::ConfigItem.new(key: :apk_file,
81
+ env_name: "ANDROID_CHANNELS_APK_FILE",
82
+ description: "The path of apk file",
83
+ default_value: Dir['**/*'].select{|f|f.end_with?('signed.apk')}.last,
84
+ optional: false,
85
+ type: String),
86
+ FastlaneCore::ConfigItem.new(key: :channels,
87
+ env_name: "ANDROID_CHANNELS_CHANNELS",
88
+ description: "The key password of keystore",
89
+ optional: false,
90
+ type: Array),
91
+ FastlaneCore::ConfigItem.new(key: :output_path,
92
+ env_name: "ANDROID_CHANNELS_OUTPUT_PATH",
93
+ description: "The output path of channels apk files",
94
+ optional: true,
95
+ default_value: "channels_apk",
96
+ type: String),
97
+ FastlaneCore::ConfigItem.new(key: :android_sdk_path,
98
+ env_name: "ANDROID_CHANNELS_ANDROID_SDK_PATH",
99
+ description: "The path of android sdk",
100
+ default_value: ENV["ANDROID_SDK_ROOT"] || ENV["ANDROID_HOME"],
101
+ optional: true,
102
+ type: String),
103
+ FastlaneCore::ConfigItem.new(key: :build_tools_version,
104
+ env_name: "ANDROID_CHANNELS_BUILD_TOOLS_VERSION",
105
+ description: "The version of build tools (by default, always use latest version)",
106
+ optional: true,
107
+ type: String),
108
+ FastlaneCore::ConfigItem.new(key: :keystore,
109
+ env_name: "ANDROID_CHANNELS_KEYSTORE",
110
+ description: "The path of keystore file",
111
+ default_value: Dir['**/*'].select{|f|f.end_with?('.keystore')}.last,
112
+ optional: true,
113
+ type: String),
114
+ FastlaneCore::ConfigItem.new(key: :keystore_password,
115
+ env_name: "ANDROID_CHANNELS_KEYSTORE_PASSWORD",
116
+ description: "The password of keystore",
117
+ optional: true,
118
+ type: String),
119
+ FastlaneCore::ConfigItem.new(key: :key_alias,
120
+ env_name: "ANDROID_CHANNELS_KEY_ALIAS",
121
+ description: "The key alias of keystore",
122
+ optional: true,
123
+ type: String),
124
+ FastlaneCore::ConfigItem.new(key: :key_password,
125
+ env_name: "ANDROID_CHANNELS_KEY_PASSWORD",
126
+ description: "The key password of keystore",
127
+ optional: true,
128
+ type: String),
129
+ FastlaneCore::ConfigItem.new(key: :clean,
130
+ env_name: "ANDROID_CHANNELS_CLEAN",
131
+ description: "Should the signed files to be clean before signing it?",
132
+ optional: true,
133
+ default_value: false,
134
+ type: Boolean)
135
+ ]
136
+ end
137
+
138
+ def self.is_supported?(platform)
139
+ [:android].include?(platform)
140
+ end
141
+
142
+ def self.category
143
+ :building
144
+ end
145
+
146
+ def self.example_code
147
+ [
148
+ 'android_channels(
149
+ apk_file: "app-signed.apk",
150
+ channels: ["xiaomi", "huawei", "qq"],
151
+ output_path: "/tmp/output_path",
152
+ )',
153
+ 'android_channels(
154
+ apk_file: "app-unsigned.apk",
155
+ signed: false,
156
+ channels: ["xiaomi", "huawei", "qq"],
157
+ keystore: "release.keystore",
158
+ keystore_password: "p@ssword",
159
+ clean: true
160
+ )'
161
+ ]
162
+ end
163
+ end
164
+ end
165
+ end
@@ -0,0 +1,145 @@
1
+ require 'fastlane_core/ui/ui'
2
+ require 'shellwords'
3
+ require 'tempfile'
4
+ require 'zip'
5
+
6
+ module Fastlane
7
+ UI = FastlaneCore::UI unless Fastlane.const_defined?("UI")
8
+
9
+ module Helper
10
+ module AndroidChannelsHelper
11
+ def self.sign_apk(apksigner, keystore, keystore_password, apk_file, key_alias = nil, key_password = nil)
12
+ signed_file = Tempfile.new([File.basename(apk_file.sub("unsigned", "signed")), File.extname(apk_file)])
13
+ FileUtils.cp(apk_file, signed_file.path)
14
+
15
+ command_args = [apksigner.shellescape, "sign", "--ks-pass", "pass:#{keystore_password}", "--ks", keystore.shellescape]
16
+ command_args << "--ks-key-alias" << key_alias unless key_alias.to_s.empty?
17
+ command_args << "--key-pass" << "pass:#{key_password}" unless key_password.to_s.empty?
18
+ command_args << signed_file.path
19
+ Action.sh(command_args.join(" "), print_command: FastlaneCore::Globals.verbose?)
20
+
21
+ signed_file
22
+ end
23
+
24
+ def self.write_apk_with_channels(output_path, apk, channels)
25
+ Zip.warn_invalid_date = false
26
+ with_channel_file do |file|
27
+ channels.each do |name|
28
+ write_channel_to_apk(output_path, apk, name, file.path)
29
+ end
30
+ end
31
+ end
32
+
33
+ def self.write_channel_to_apk(output_path, signed_file, name, channel_file)
34
+ output_file = File.join(output_path, "#{name}.apk")
35
+ FileUtils.cp(signed_file, output_file)
36
+
37
+ Zip::File.open(output_file, Zip::File::CREATE) do |zip_file|
38
+ zip_file.add("META-INF/cztchannel_#{name}", channel_file)
39
+ end
40
+ rescue Zip::EntryExistsError => ex
41
+ UI.build_failure!([ex.message].concat(ex.backtrace).join("\n"))
42
+ end
43
+
44
+ def self.with_channel_file(filename = "android_channel", &block)
45
+ Tempfile.open(filename) do |file|
46
+ yield file
47
+ end
48
+ end
49
+
50
+ def self.determine_apk_file!(params)
51
+ apk_file = find_file(params[:apk_file])
52
+ UI.user_error!("Not found apk file: #{params[:apk_file]}") unless apk_file
53
+ apk_file
54
+ end
55
+
56
+ def self.is_signed?(apk_file)
57
+ Zip.warn_invalid_date = false
58
+ Zip::File.open(apk_file, Zip::File::CREATE) do |zip_file|
59
+ file = zip_file.find_entry("META-INF/MANIFEST.MF")
60
+ if file
61
+ encrypt_keys = 0
62
+ file.get_input_stream do |io|
63
+ io.each_line do |line|
64
+ return true if encrypt_keys >= 2
65
+ encrypt_keys += 1 if line.start_with?("Name:")
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ false
72
+ end
73
+
74
+ def self.determine_keystore!(params)
75
+ keystore = find_file(params[:keystore])
76
+ UI.user_error!("Not found keystore file: #{params[:keystore]}") unless keystore
77
+ keystore
78
+ end
79
+
80
+ def self.determine_channels!(params)
81
+ channels = params[:channels]
82
+ UI.user_error!("Empty channels") if channels.size.zero?
83
+ channels
84
+ end
85
+
86
+ def self.determine_keystore_password!(params)
87
+ password = params[:keystore_password]
88
+ UI.user_error!("Missing keystore_password") unless password
89
+ password
90
+ end
91
+
92
+ def self.determine_output_path!(params)
93
+ output_path = params[:output_path]
94
+ if Dir.exist?(output_path)
95
+ if params[:clean]
96
+ FileUtils.rm_rf(output_path)
97
+ else
98
+ UI.user_error!("output path was exists: #{File.expand_path(output_path)}。 \nyou can use `clean:true` to force clean.")
99
+ end
100
+ end
101
+
102
+ FileUtils.mkdir_p(output_path)
103
+ output_path
104
+ end
105
+
106
+ def self.determine_apksigner!(params)
107
+ android_sdk_path = params[:android_sdk_path]
108
+ build_tools_version = params[:build_tools_version]
109
+ UI.user_error!("Not found android SDK path: #{android_sdk_path}") unless android_sdk_path
110
+
111
+ build_tools_path = build_tools_path(android_sdk_path, build_tools_version)
112
+ apksigner_path(build_tools_path)
113
+ end
114
+
115
+ def self.find_file(default_file)
116
+ return default_file if File.file?(default_file)
117
+
118
+ Dir['**/*'].each do |file|
119
+ return file if File.basename(file) == default_file
120
+ end
121
+
122
+ nil
123
+ end
124
+
125
+ def self.build_tools_path(android_sdk_path, version = nil)
126
+ build_tools_path = File.join(android_sdk_path, "build-tools")
127
+ unless version
128
+ latest_path = Dir.glob("#{build_tools_path}/*").inject {|latest, current| File.basename(latest) > File.basename(current) ? latest : current }
129
+ version = File.basename(latest_path)
130
+ end
131
+ path = File.join(build_tools_path, version)
132
+
133
+ UI.user_error!("Not found build tools path: #{build_tools_path}") unless path && Dir.exist?(path)
134
+ path
135
+ end
136
+
137
+ def self.apksigner_path(build_tools_path)
138
+ file = File.join(build_tools_path, "apksigner")
139
+
140
+ UI.user_error!("Not found apksigner: #{params[:android_sdk_path]}") unless file && File.file?(file)
141
+ file
142
+ end
143
+ end
144
+ end
145
+ end
@@ -0,0 +1,5 @@
1
+ module Fastlane
2
+ module AndroidChannels
3
+ VERSION = "0.2.0"
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ require 'fastlane/plugin/android_channels/version'
2
+
3
+ module Fastlane
4
+ module AndroidChannels
5
+ # Return all .rb files inside the "actions" and "helper" directory
6
+ def self.all_classes
7
+ Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))]
8
+ end
9
+ end
10
+ end
11
+
12
+ # By default we want to import all available actions and helpers
13
+ # A plugin can contain any number of actions and plugins
14
+ Fastlane::AndroidChannels.all_classes.each do |current|
15
+ require current
16
+ end
metadata ADDED
@@ -0,0 +1,189 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fastlane-plugin-android_channels
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - icyleaf
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-10-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubyzip
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.2.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.2.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
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: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
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: rspec_junit_formatter
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 0.49.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 0.49.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-require_tools
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: simplecov
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: fastlane
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: 2.107.0
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: 2.107.0
153
+ description:
154
+ email: icyleaf.cn@gmail.com
155
+ executables: []
156
+ extensions: []
157
+ extra_rdoc_files: []
158
+ files:
159
+ - LICENSE
160
+ - README.md
161
+ - lib/fastlane/plugin/android_channels.rb
162
+ - lib/fastlane/plugin/android_channels/actions/android_channels_action.rb
163
+ - lib/fastlane/plugin/android_channels/helper/android_channels_helper.rb
164
+ - lib/fastlane/plugin/android_channels/version.rb
165
+ homepage: https://github.com/icyleaf/fastlane-plugin-android_channels
166
+ licenses:
167
+ - MIT
168
+ metadata: {}
169
+ post_install_message:
170
+ rdoc_options: []
171
+ require_paths:
172
+ - lib
173
+ required_ruby_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ requirements: []
184
+ rubyforge_project:
185
+ rubygems_version: 2.7.3
186
+ signing_key:
187
+ specification_version: 4
188
+ summary: Package unsign apk with channels
189
+ test_files: []