diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 9cdb2fb..e026a27 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -17,38 +17,104 @@ platform :android do + desc "Extract Application Id from gradle file" + def get_application_id(flavor = nil, path = '../app/build.gradle', constant_name = 'applicationId') + application_id = nil + application_id_suffix = nil + toggle_flavors = false + current_flavor = nil + unless File.file?(path) + UI.message(" -> No file exists at path: (#{path})!") + return application_id + end + begin + file = File.new(path, 'r') + while (line = file.gets) + next unless line.include? constant_name + components = line.strip.split(' ') + application_id = components[components.length - 1].tr("\"", '') + UI.message("#{constant_name} = #{application_id}") + break + end + if flavor + file.each do |line| + if line[/^(#.*)?$/] + next + end + #UI.message("Line = #{line.tr("\n",'')}") + if toggle_flavors + current_flavor = line[/(?=\s*)\w+(?=\s+\{)/] + if ! current_flavor + break + end + #UI.message("Flavor = #{current_flavor}") + toggle_flavors = false + next + end + if current_flavor == flavor and line.include? "#{constant_name}Suffix" + components = line.strip.split(' ') + application_id_suffix = components[components.length - 1].tr("\"", '') + UI.message("#{constant_name}Suffix = #{application_id_suffix}") + next + end + if line[/\s*}/] + if current_flavor + current_flavor = nil + toggle_flavors = true + next + end + if toggle_flavors + break + end + next + end + if line[/(?=\s*)productFlavors(?=\s+\{)/] + toggle_flavors = true + next + end + end + end + file.close + rescue => err + UI.error("An exception occurred while reading the gradle file: #{err}") + err + end + return "#{application_id}#{application_id_suffix}" + end + desc "Define flavor name for a branch" def getFlavorName(options) - case options[:fl_branch] - when "production" - return "prd" - when "acceptance" - return "acc" - when "systemtest" - return "systemtest" + flavor = nil + if options and options[:fl_branch] + # Use option if provided + flavor = options[:fl_branch] else - return "dev2" + # Fallback on environment variable if any + if ENV['BRANCH_NAME'] + flavor = ENV['BRANCH_NAME'] + end end + if ! flavor + # Choose default flavor + flavor = 'dev2' + end + return flavor end desc "Define package name for a branch" - def getPackageName(options) - case options[:fl_branch] - when "production" - return "nl.digital_me.dummyandroidapp" - when "acceptance" - return "nl.digital_me.dummyandroidapp.acc" - # when "systemtest" - # return "nl.digital_me.dummy.systemtest" - else - return "nl.digital_me.dummyandroidapp.dev2" - end + def getPackageName(options = nil) + return get_application_id(getFlavorName(options)) end before_all do |lane, options| # ENV["SLACK_URL"] = "https://hooks.slack.com/services/..." end + desc "Display infos about the app" + lane :info do |options| + UI.message("App ID = #{getPackageName(options)}") + end + desc "Runs all the tests" lane :test do |options| gradle(task: "test")