Skip to content

Instantly share code, notes, and snippets.

@huynguyencong
Created January 13, 2021 08:15
Show Gist options
  • Save huynguyencong/4259376fa6ceaa68464cffb132bd065a to your computer and use it in GitHub Desktop.
Save huynguyencong/4259376fa6ceaa68464cffb132bd065a to your computer and use it in GitHub Desktop.
Build iOS app and deliver it to an app manager with Fastlane
# 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
# Please set these environment variables:
# APP_MANAGER_API_KEY: for upload file to company's app manager
# FASTLANE_USER, FASTLANE_SESSION: for get_certificates, get_provisioning_profile
# For Github action, FASTLANE_SESSION doesn't work, use FASTLANE_PASSWORD instead.
# Should get_certificates because certificate generating limit. Should copy it to CI runner manually.
default_platform(:ios)
team_id = 'my_team_id'
app_manager_key = ENV['APP_MANAGER_API_KEY']
adhoc_ipa_name = 'CICDDemo-Adhoc'
adhoc_app_id = 'com.nch.Test'
adhoc_scheme = 'CICDDemo'
adhoc_app_manager_version_name_prefix = 'CICDDemo Adhoc'
adhoc_app_manager_app_id = '606'
app_store_app_id = 'com.nch.Test'
app_store_ipa_name = 'CICDDemo-AppStore'
app_store_scheme = 'CICDDemo'
platform :ios do
desc "Testing"
lane :test do
run_tests(scheme: 'CICDDemo')
end
desc "Build Adhoc and upload to App Manager"
lane :adhoc do
build_adhoc
upload_adhoc
end
desc "Build Adhoc"
lane :build_adhoc do
get_certificates(team_id: team_id)
get_provisioning_profile(app_identifier: adhoc_app_id, adhoc: 'true', team_id: team_id)
build_app(scheme: adhoc_scheme, export_method: 'ad-hoc', output_name: adhoc_ipa_name, include_bitcode: false)
end
desc "Build App Store"
lane :build_appstore do
get_certificates(team_id: team_id)
get_provisioning_profile(app_identifier: app_store_app_id, team_id: team_id)
build_app(scheme: app_store_scheme, export_method: 'app-store', output_name: app_store_ipa_name)
end
desc "Upload adhoc"
lane :upload_adhoc do
upload_app_manager(ipa_path: "#{adhoc_ipa_name}.ipa", version_name_prefix: adhoc_app_manager_version_name_prefix, app_manager_app_id: adhoc_app_manager_app_id)
end
desc "Upload to company's App Manager"
lane :upload_app_manager do |options|
ipa_path = options[:ipa_path]
version_name_prefix = options[:version_name_prefix]
app_manager_app_id = options[:app_manager_app_id]
version = get_ipa_info_plist_value(
key: "CFBundleShortVersionString",
ipa: ipa_path
)
version_name = "#{version_name_prefix} #{version}"
puts "Uploading IPA file to company's App Manager, IPA path: #{ipa_path}, version name: #{version_name}, App Manager app id: #{app_manager_app_id}."
sh "curl -F binary=@../#{ipa_path} \
-F api_token=#{app_manager_key} \
-F platform='iOS' \
-F version_number='#{version_name}' \
https://app.mycompany.net/api/v1/apps/#{app_manager_app_id}/versions"
puts "Uploaded to company's App Manager"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment