Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fastlane script for Uploading to Slack and Play Store Alpha
default_platform :android
platform :android do
before_all do
ENV["SLACK_URL"] = "https://hooks.slack.com/services/ABC/123/XYZ"
end
######################### PUBLIC LANES #########################
desc "Deploy a new Prod APK version to Play Store Alpha"
lane :alpha do |options|
build(
flavor: "Prod"
)
supply(
track: 'alpha',
skip_upload_metadata: 'true',
skip_upload_images: 'true',
skip_upload_screenshots: 'true',
apk: lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH]
)
end
desc "Deploy a new Dev APK to #mobile-team Slack channel"
lane :dev do |options|
build(
flavor: "Dev"
)
upload_to_slack()
end
desc "Deploy a new Prod APK to #mobile-team Slack channel"
lane :prod do |options|
build(
flavor: "Prod"
)
upload_to_slack()
end
######################### PRIVATE LANES #########################
desc "Build a new APK"
private_lane :build do |options|
gradle(
task: "clean assemble",
flavor: options[:flavor],
build_type: "Release"
)
end
desc "Upload the latest output APK to #mobile-team Slack channel"
private_lane :upload_to_slack do |options|
full_file_path = lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH]
file_name = full_file_path.gsub(/\/.*\//,"")
sh "echo Uploading " + file_name + " to #mobile-team Slack"
sh "curl https://slack.com/api/files.upload -F token=\"xoxp-2847714161-180183158647-249973069941-7bdbe4591d8d450ab8bb6be8b9b78b81\" -F channels=\"mobile-team\" -F title=\"" + file_name + "\" -F filename=\"" + file_name + "\" -F file=@" + full_file_path
end
######################### UTILS #########################
######################### POST #########################
after_all do |lane|
file_name = lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH].gsub(/\/.*\//,"")
slack(
message: "Successfully deployed new App Update! :champagne:",
channel: "@user.name,#channel.name",
default_payloads: [
:git_branch,
:last_git_commit_hash,
:last_git_commit_message
],
payload: {
# Optional, lets you specify any number of your own Slack attachments.
"Build Date" => Time.new.to_s,
"APK" => file_name
},
success: true
)
ifttt(
api_key: "IFTTT_API_KEY",
event_name: "build_success",
value1: lane_context[SharedValues::LANE_NAME],
value2: file_name,
value3: lane_context[SharedValues::VERSION_NUMBER]
)
end
error do |lane, exception|
slack(
message: exception.message,
channel: "@vince.intal",
default_payloads: [
:git_branch,
:last_git_commit_hash,
:last_git_commit_message
],
payload: {
"Build Date" => Time.new.to_s
},
success: false
)
ifttt(
api_key: "IFTTT_API_KEY",
event_name: "build_failed",
value1: exception.message
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment