Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fastfile example for Android on Windows
# This is our Android Fastlane template
#
# We are using this plugin: gem 'fastlane-plugin-android_versioning'
# And have a Appfile with json_key_file("***") and package_name("***")
#
require 'git'
require 'fileutils'
default_platform(:android)
platform :android do
desc "Create Test version - CI will deploy it"
lane :createTestVersion do
ensure_git_status_clean()
isOnMasterBranch = currentBranch() == "master"
if !isOnMasterBranch
puts "Not possible to distribute test version from other than 'master' branch. " +
"You are on branch '#{currentBranch()}'."
next
end
if !getAnswer("You are about to make a new test version from master.
Be aware that as a part of the script, we will pull latest version from git. Proceed?")
next
end
testNotes = prompt(text: "Write a message to the testers here: (End with enter)")
emails = prompt(text: "Write a list of emails, to receive the test version: (Separated with comma, end with enter)")
sh("git pull origin master --rebase")
FileUtils.mkdir_p(File.dirname("./data/"))
File.open("./data/MessageToTesters.txt", "w") {|f| f.write(testNotes) }
File.open("./data/EmailsToReceiveTestVersion.txt", "w") {|f| f.write(emails) }
updateVersionNumber(alwaysIncrementBuildNumber: true)
versionNumber = get_version_name(app_project_dir: '**/app')
versionCode = get_version_code(app_project_dir: '**/app')
git_add()
sh("git commit -m \"release: #{versionNumber} (#{versionCode})\"")
sh("git push origin master") # push_to_git_remote() not working on windows
begin
sh("git checkout stage", log: false)
puts "git checkout stage"
rescue => ex
sh("git checkout -b stage")
end
begin
sh("git pull origin stage --rebase", log: false)
puts "git pull origin stage --rebase"
rescue => ex
end
sh("git merge --ff-only master")
sh("git push origin stage")
sh("git checkout master")
puts "The CI will now do the rest in building and distributing the test version."
end
desc "Create Prod version - CI will create ipa"
lane :createProdVersion do
ensure_git_status_clean()
isOnMasterBranch = currentBranch() == "master"
if !isOnMasterBranch
puts "Not possible to make a prod version from other than 'master' branch. " +
"You are on branch '#{currentBranch()}'."
next
end
validate_play_store_json_key
whatIsChanged = prompt(text: "What is new in this version? - in English (End with enter)")
FileUtils.mkdir_p(File.dirname("./data/"))
File.open("./data/WhatIsNewGooglePlay.txt", "w") {|f| f.write(whatIsChanged) }
updateVersionNumber(alwaysIncrementBuildNumber: false)
versionNumber = get_version_name(app_project_dir: '**/app')
versionCode = get_version_code(app_project_dir: '**/app')
git_add()
sh("git commit -m 'release: #{versionNumber} (#{versionCode})'")
sh("git push origin master") # push_to_git_remote() not working on windows
if !getAnswer("You are about to make a new prod version from master with version #{versionNumber} (#{versionCode}). Proceed?")
next
end
sh("git checkout -b release/#{versionNumber}")
sh("git push --delete origin stage")
sh("git branch -D stage")
sh("git push origin release/#{versionNumber}")
puts "The CI will now do the rest in deploying this version to Google Play."
end
desc "CI lane - Build dev version"
lane :ciBuildDev do
sh("chmod +x ./../gradlew")
gradle(task: "clean assembleDevelopment")
end
desc "CI lane - Distribute test version"
lane :ciDeployToTest do
isOnStageBranch = currentBranch() == "stage"
if !isOnStageBranch
puts "Not possible to distribute a test version from other than 'stage' branch. " +
"You are on branch '#{currentBranch()}'."
next
end
messageToTesters = File.read("./data/MessageToTesters.txt")
emailsToReceiveTestVersion = File.read("./data/EmailsToReceiveTestVersion.txt")
buildAndSendToTest("Stage", "Test data.\n\n#{messageToTesters}", emailsToReceiveTestVersion, true)
buildAndSendToTest("ProdTest", "Prod data.\n\n#{messageToTesters}", emailsToReceiveTestVersion, true)
puts "Test version send Crashlytics Beta"
end
desc "CI lane - Deploy to Google Play"
lane :ciDeployToGooglePlay do
currentBranch = currentBranch()
if currentBranch.index("release") != 0
puts "Not possible to build a Appstore ipa from other than a 'release' branch. " +
"You are on branch '#{currentBranch}'."
next
end
versionNumber = get_version_name(app_project_dir: '**/app')
versionCode = get_version_code(app_project_dir: '**/app')
sh("chmod +x ./../gradlew")
gradle(task: "clean bundleProd")
whatIsChanged = File.read("./data/WhatIsNewGooglePlay.txt")
validate_play_store_json_key
download_from_play_store
FileUtils.mkdir_p(File.dirname("./metadata/android/en-GB/changelogs/"))
File.open("./metadata/android/en-GB/changelogs/#{versionCode}.txt", "w") {|f| f.write(whatIsChanged) }
upload_to_play_store(
skip_upload_apk: true,
skip_upload_aab: false,
skip_upload_metadata: false,
skip_upload_images: true,
skip_upload_screenshots: true,
validate_only: false
)
add_git_tag(tag: "#{versionNumber}_#{versionCode}", buildNumber: "")
push_git_tags()
sh("git checkout master")
sh("git merge release/#{versionNumber}")
sh("git push origin master")
sh("git push --delete origin release/#{versionNumber}")
sh("git branch -D release/#{versionNumber}")
end
def buildAndSendToTest(buildType, notes, emails, notifications)
sh("chmod +x ./../gradlew")
gradle(task: "clean")
gradle(task: "assemble", build_type: buildType)
crashlytics(api_token: "***",
build_secret: "***",
notes: notes,
emails: emails,
notifications: notifications)
end
def currentBranch()
branch = git_branch()
if !branch.to_s.empty?
return branch
end
git = Git.open(File.join(File.dirname(__FILE__), '../')) # git_branch() does not seem work on Windows, it will print error with path not found.
return git.current_branch
end
def updateVersionNumber(alwaysIncrementBuildNumber: false)
currentVersion = get_version_name(app_project_dir: '**/app')
input = prompt(
text: "Current version number #{currentVersion}\n\nBump version number \n" +
"1. major\n2. minor\n3. patch\n4. only change build number\n5. no change",
boolean: false,
secure_text: false,
ci_input: "5"
)
bumpType = "none"
case input
when "1"
bumpType = "major"
when "2"
bumpType = "minor"
when "3"
bumpType = "patch"
when "4"
bumpType = "build"
when proc { |x| x != "5" }
raise "Invalid option selected. It has to be a number between 1 and 5"
end
if bumpType != "none"
if bumpType != "build"
increment_version_name(app_project_dir: '**/app', bump_type: bumpType)
end
increment_version_code(app_project_dir: '**/app')
elsif alwaysIncrementBuildNumber
increment_version_code(app_project_dir: '**/app')
end
end
def getAnswer(question)
input = prompt(text: "#{question} (y/n)", boolean: false)
yes = input == "y"
no = input == "n"
if !yes && !no
raise "Invalid option selected. It has to be y or n"
end
return yes
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.