Skip to content

Commit

Permalink
Merge pull request #5 from gkiki90/apk_info
Browse files Browse the repository at this point in the history
Apk info
  • Loading branch information
viktorbenei committed Nov 13, 2015
2 parents db6243d + 429c922 commit 397466b
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 18 deletions.
31 changes: 27 additions & 4 deletions step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,33 @@ def fail_with_message(message)
else
puts
puts '## Deploying single file'
public_page_url = deploy_file_to_bitrise(options[:deploy_path],
options[:build_url],
options[:api_token]
)
a_public_page_url = ''
if options[:deploy_path].match('.*.ipa')
a_public_page_url = deploy_ipa_to_bitrise(
options[:deploy_path],
options[:build_url],
options[:api_token],
options[:notify_user_groups],
options[:notify_email_list],
options[:is_enable_public_page]
)
elsif options[:deploy_path].match('.*.apk')
a_public_page_url = deploy_apk_to_bitrise(
options[:deploy_path],
options[:build_url],
options[:api_token],
options[:notify_user_groups],
options[:notify_email_list],
options[:is_enable_public_page]
)
else
a_public_page_url = deploy_file_to_bitrise(
options[:deploy_path],
options[:build_url],
options[:api_token]
)
end
public_page_url = a_public_page_url
end

# - Success
Expand Down
79 changes: 66 additions & 13 deletions uploaders/apk_uploader.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
require 'json'

def fail_with_message(message)
puts "\e[31m#{message}\e[0m"
exit(1)
end

def aapt_path
android_home = ENV['ANDROID_HOME']
if android_home.nil? || android_home == ''
fail_with_message('Failed to get ANDROID_HOME env')
end

aapt_files = Dir[File.join(android_home, 'build-tools', '/**/aapt')]
fail_with_message('Failed to find aapt tool') unless aapt_files

latest_build_tool_version = ''
latest_aapt_path = ''
aapt_files.each do |aapt_file|
path_splits = aapt_file.to_s.split('/')
build_tool_version = path_splits[path_splits.count - 2]

latest_build_tool_version = build_tool_version if latest_build_tool_version == ''
if Gem::Version.new(build_tool_version) >= Gem::Version.new(latest_build_tool_version)
latest_build_tool_version = build_tool_version
latest_aapt_path = aapt_file.to_s
end
end

fail_with_message('Failed to find latest aapt tool') if latest_aapt_path == ''
return latest_aapt_path
end

# -----------------------
# --- upload apk
# -----------------------
Expand All @@ -8,13 +39,45 @@ def deploy_apk_to_bitrise(apk_path, build_url, api_token, notify_user_groups, no
puts
puts "# Deploying apk file: #{apk_path}"

# - Analyze the apk / collect infos from apk
puts
puts '=> Analyze the apk'

aapt = aapt_path
infos = `#{aapt} dump badging #{apk_path}`

package_name_version_regex = 'package: name=\'(?<package_name>.*)\' versionCode=\'(?<version_code>.*)\' versionName=\'(?<version_name>.*)\' '
package_name_version_match = infos.match(package_name_version_regex)
package_name = package_name_version_match.captures[0] if package_name_version_match && package_name_version_match.captures
version_code = package_name_version_match.captures[1] if package_name_version_match && package_name_version_match.captures
version_name = package_name_version_match.captures[2] if package_name_version_match && package_name_version_match.captures

app_name_regex = 'application-label:\'(?<min_sdk_version>.*)\''
app_name_match = infos.match(app_name_regex)
app_name = app_name_match.captures[0] if app_name_match && app_name_match.captures

min_sdk_regex = 'sdkVersion:\'(?<min_sdk_version>.*)\''
min_sdk_match = infos.match(min_sdk_regex)
min_sdk = min_sdk_match.captures[0] if min_sdk_match && min_sdk_match.captures

apk_file_size = File.size(apk_path)
puts " (i) apk_file_size: #{apk_file_size} KB / #{apk_file_size / 1024.0} MB"

apk_info_hsh = {
file_size_bytes: apk_file_size,
app_info: {
app_name: app_name,
package_name: package_name,
version_code: version_code,
version_name: version_name,
min_sdk_version: min_sdk
}
}
puts " (i) apk_info_hsh: #{apk_info_hsh}"

# - Create a Build Artifact on Bitrise
puts
puts '=> Create a Build Artifact on Bitrise'
upload_url, artifact_id = create_artifact(build_url, api_token, apk_path, 'file')
upload_url, artifact_id = create_artifact(build_url, api_token, apk_path, 'android-apk')
fail 'No upload_url provided for the artifact' if upload_url.nil?
fail 'No artifact_id provided for the artifact' if artifact_id.nil?

Expand All @@ -23,23 +86,13 @@ def deploy_apk_to_bitrise(apk_path, build_url, api_token, notify_user_groups, no
puts '=> Upload the apk'
upload_file(upload_url, apk_path)

# !!!
# - Remove this if public page for android implemented on bitrise.io
# !!!
if is_enable_public_page
puts
puts '(!) Public page is not allowed yet, for apk.'
puts '(!) is_enable_public_page = false'
is_enable_public_page = false
end

# - Finish the Artifact creation
puts
puts '=> Finish the Artifact creation'
return finish_artifact(build_url,
api_token,
artifact_id,
'',
JSON.dump(apk_info_hsh),
notify_user_groups,
notify_emails,
is_enable_public_page
Expand Down
1 change: 0 additions & 1 deletion uploaders/ipa_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def deploy_ipa_to_bitrise(ipa_path, build_url, api_token, notify_user_groups, no
puts

ipa_file_size = File.size(ipa_path)
puts " (i) ipa_file_size: #{ipa_file_size} KB / #{ipa_file_size / 1024.0} MB"

info_plist_content = parsed_ipa_infos[:info_plist][:content]
mobileprovision_content = parsed_ipa_infos[:mobileprovision][:content]
Expand Down

0 comments on commit 397466b

Please sign in to comment.