Skip to content

Instantly share code, notes, and snippets.

@lalkrishna
Last active March 14, 2022 15:28
Show Gist options
  • Save lalkrishna/a3a8aa7b6d9b1f922f234f01f8dc957d to your computer and use it in GitHub Desktop.
Save lalkrishna/a3a8aa7b6d9b1f922f234f01f8dc957d to your computer and use it in GitHub Desktop.
Fastfile configuration for take enterprise build iOS ipa and upload to diawi.
# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
# https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
# https://docs.fastlane.tools/plugins/available-plugins
#
# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane
platform :ios do
projectname = "xxxx"
defaultNotifyEmail = "hi@lalkrishna.dev"
# BUILD APP-STORE and DISTRIBUTE via TESTFLIGHT
desc "Upload build to testflight"
lane :beta_testflight do |options|
# xcode_select("/Applications/Xcode-beta.app")
if !options[:scheme]
UI.important "No Scheme value provided. continuing in manual mode."
UI.important "Please call 'beta_testflight scheme:(value)' with valid scheme for automation."
end
build_app(
scheme: options[:scheme],
silent: true
)
upload_to_testflight
end
# BUILD AD-HOC and DISTRIBUTE via DIAWI
# Example Call in terminal: fastlane ios build_adhoc_and_upload_diawi email:xxxxxx@gmail.com comment:comment
lane :build_adhoc_and_upload_diawi do |options|
@ipaPath = build_adhoc_ipa(buildDir: build_Directory, scheme: options[:scheme])
upload_file_diawi(email: options[:email], comment: options[:comment])
end
# Usage: `build_Directory version:"0.1.1(2)"`, returns "../../IPA/projectname v0.1.1(2)"
# Usage: `build_Directory` will returns Path for current version and build number.
lane :build_Directory do |options|
versionBuild = options[:version]
if !versionBuild
version = get_version_number(xcodeproj: "#{projectname}.xcodeproj", target: "xxxxx")
buildNumber = get_build_number(xcodeproj: "#{projectname}.xcodeproj")
versionBuild = "#{version}(#{buildNumber})"
end
File.expand_path("../../IPA/") + "/#{projectname} v#{versionBuild}/"
end
desc "Creates ad-hoc build and save it in buildDir."
# Usage: build_adhoc_ipa buildDir:`path to ipa dir`
lane :build_adhoc_ipa do |options|
if !options[:buildDir]
UI.user_error! "Missing parameter 'buildDir'"
end
buildDir = build_Directory
if !options[:scheme]
UI.important "No Scheme value provided. continuing in manual mode."
UI.important "Please call 'beta_testflight scheme:(value)' with valid scheme for automation."
end
# xcode_select("/Applications/Xcode-beta.app")
build_app(
scheme: options[:scheme],
silent: true,
output_directory: buildDir,
export_method: "ad-hoc"
)
# buildDir + "/#{projectname}.ipa"
lane_context[SharedValues::IPA_OUTPUT_PATH]
end
desc "Upload and notify via email."
# Usage: `upload_file_diawi path:#{path} email:x@x.com comment:`comment goes`
lane :upload_file_diawi do |options|
if !@ipaPath && !options[:path]
UI.user_error! "Value for ipaPath must set before calling this lane. OR pass 'path' explicitly."
end
puts "#{@ipaPath}" + ".#{options[:path]}."
callback_email = (options[:email] ? options[:email] : defaultNotifyEmail)
# IMPORTANT step: run `fastlane add_plugin diawi` .
diawi(
token: "dZeGRUkeMcG6s4uzckarT62MUXZ8oGe0JiJCEOmC11", # https://dashboard.diawi.com/profile/api > Generate token.
file: (@ipaPath ? @ipaPath : options[:path]),
comment: "#{options[:comment]}",
callback_emails: callback_email
)
diawiLink = lane_context[SharedValues::UPLOADED_FILE_LINK_TO_DIAWI]
UI.success "IPA Uploaded to Diawi: #{diawiLink}. Shared to #{callback_email}. Comment: #{options[:comment]}"
# Post MacOS notification
notification(
title: "IPA Uploaded to Diawi: #{diawiLink}",
subtitle: "Shared to #{callback_email}.",
message: "#{options[:comment]}",
open: diawiLink
)
end
# error block is executed when a error occurs
error do |lane, exception|
notification(subtitle: "Fastlane Error", message: exception.to_s)
end
end
default_platform(:ios)
platform :ios do
desc "enterprise line will generate Enterprise build to `Build` folder."
# Example Call in terminal: fastlane enterprise email:"xxxxx@xxx.com" comment:"my comment"
lane :enterprise do |options|
# add actions here: https://docs.fastlane.tools/actions
# Raises an exception if there are uncommitted git changes
ensure_git_status_clean
version = get_version_number(xcodeproj: "xxxx.xcodeproj", target: "xxxx")
buildNumber = get_build_number(xcodeproj: "xxxx.xcodeproj")
#version = lane_context[SharedValues::VERSION_NUMBER]
#lane_context[SharedValues::BUILD_NUMBER]
versionBuild = "#{version}(#{buildNumber})"
puts("Current build: v#{versionBuild})")
#short sha of last commit
shortsha = lane_context[SharedValues::BUILD_NUMBER_REPOSITORY]
puts(shortsha)
#path for storing IPA file in filesystem
buildDir = File.expand_path("../../Build/") + "/#{shortsha}-v#{versionBuild}/"
build_app(
scheme: "scheme_xxxx",
silent: true,
clean: true,
output_directory: buildDir,
output_name: "ipa_xxxxx.ipa",
export_method: "enterprise", #Describes how Xcode should export the archive. Available options: app-store, validation, ad-hoc, package, enterprise, development, developer-id, and mac-application. The list of options varies based on the type of archive. Defaults to development.
)
comment = options[:comment]
callback = "xxx@xxx.com" #setting Default Callback Email for Diawi.
if options[:email]
callback = options[:email]
end
puts("CallbackEmail: #{callback}")
diawi(
token: "xxxxxxxxxxxxxxxxxxxxxxx", # https://dashboard.diawi.com/profile/api > Generate token.
file: buildDir + "/ipa_xxxxx.ipa",
comment: "#{shortsha} - #{comment}",
callback_emails: callback
)
diawiLink = lane_context[SharedValues::UPLOADED_FILE_LINK_TO_DIAWI]
puts(diawiLink)
# Post MacOS notification
notification(subtitle: "Finished Fastlane", message: "IPA Uploaded to Diawi: " + diawiLink)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment