Fastlane automated packaging notes

Install fastlane

github warehouse: https://github.com/fastlane/fastlane

fastlane official website: https://docs.fastlane.tools/

fastlane actions: https://docs.fastlane.tools/actions/

A configuration document: https://www.jianshu.com/p/0a113f754c09

Upload to dandelion: https://www.pgyer.com/doc/view/fastlane

An example of a custom lanes group: https://github.com/thierryxing/Fastfiles/tree/master/fastlane/actions

Main supported operations:

  • Testing
  • Building: creating, compiling a project
  • Screenshots: screenshots
  • Project: actions related to project configuration
  • Code Signing: Project signature related
  • Documentation: exporting documents
  • Uploading your app: upload the app to the appstore
  • Source Control: git control actions
  • Notifications: notification related

install

See the installation tutorial here: https://www.jianshu.com/p/0a113f754c09

It should be noted that in order to automatically update the build version of a project, you must modify: build Settings > versioning > current project version. You must fill in a version number here, and you can fill in any one. Then the Versioning System can select the Versioning System

Export packed files to specified directory

When using gym, you can specify the output "directory

desc "Package project to specified directory"
  lane :package do
    dir="./fastlane/build/Package"
    puts("*************| Package project to catalog |*************")
	updateProjectBuildNumber #Change project build number
  	# Start packing
	gym(
		#ipa name of the output
		scheme: "CarOwners",
		output_name:"Package_CarOwners_#{get_build_number()}",
		silent: false,  # Hide unnecessary building information
		clean:false,		# Whether to clear the previous compilation information true: Yes
		configuration:"Release",	# Specify packaging method, Release or Debug
		export_method:"development",	# Specify the output method used for packaging. Currently, app store, package, ad-hoc, enterprise, development are supported
		buildlog_path: "#{dir}/fastlanelog",  # The log output directory of building ipa by fastlane
		output_directory:"#{dir}",	# Specify output folder
		)
	puts("\n*************| Packaging complete |*************\n")
	puts('output_directory: "#{dir}"')
	notification(title: "Package successful!", message: "Package successful,Please check the console for details!")
  end

Release test version to Dandelion

Release the test version to the dandelion platform. For details, please refer to the documents provided by the dandelion platform: https://www.pgyer.com/doc/view/fastlane

desc "Package application and upload to dandelion platform"
  lane :pgy do |options|
  	updateProjectBuildNumber #Change project build number
  	dir="./fastlane/build/Pgy"
	# Start packing
	gym(
		#ipa name of the output
		scheme: "CarOwners",
		output_name:"#{scheme}_#{get_build_number()}",
		clean:true,		# Whether to clear the previous compilation information true: Yes
		configuration:"Release",	# Specify packaging method, Release or Debug
		export_method:"development",	# Specify the output method used for packaging. Currently, app store, package, ad-hoc, enterprise, development are supported
		output_directory:"#{dir}",	# Specify output folder
		)
    pgyer(api_key: "cd1ac371b28c9d53930d780925b0ba73", 
    	user_key:   "ffb13d5ca261cf0dab6b8c00f61b4063",
    	update_description: options[:desc])		#desc indicates the update description submitted this time
    notification(title: "Published successfully!", 
    	message: "Successfully uploaded to dandelion platform, Let's contact the tester to start the test!😊", 
    	open: "https://www.pgyer.com/czb365")
  end

Publish app to app store

It's very easy to publish to the app store. After packaging, you can directly use action upload to app store to automatically upload to the app store and submit it for approval

desc "Push a new release build to the App Store"
  lane :release do
    dir="./fastlane/build/AppStore"
    gym(workspace: "CarOwners.xcworkspace", 
    scheme: "CarOwners", 
    output_directory:"#{dir}",
	buildlog_path: "#{dir}/fastlanelog",  # The log output directory of building ipa by fastlane
    )
    upload_to_app_store
	    notification(title: "Published successfully!", 
	    message: "Successfully published to appstore, Please check!", 
	    open: "https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa/ra/ng/app/1116025241")
  end

A simple Demo

# 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
#

# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane

# Auto append version number
def updateProjectBuildNumber
	currentTime = Time.new.strftime("%Y%m%d")
	build = get_build_number()
	if build.include?"#{currentTime}."
		# =>Calculate iteration version number for current version
		lastStr = build[build.length-2..build.length-1]
		lastNum = lastStr.to_i
		lastNum = lastNum + 1
		lastStr = lastNum.to_s
		if lastNum < 10
			lastStr = lastStr.insert(0,"0")
		end
		build = "#{currentTime}.#{lastStr}"
	else
		# =>build number reset of non current version
		build = "#{currentTime}.01"
	end
	puts("*************| To update build #{build} |*************")
	# =>Change project build number
	increment_build_number(
	build_number: "#{build}"
	)
end


default_platform(:ios)

platform :ios do
  dir="./fastlane/build/AppStore"
  desc "Push a new release build to the App Store"
  lane :release do
    gym(workspace: "CarOwners.xcworkspace", 
    scheme: "CarOwners", 
    output_directory:"#{dir}",
	buildlog_path: "#{dir}/fastlanelog",  # The log output directory of building ipa by fastlane
    )
    upload_to_app_store
    notification(title: "Published successfully!", message: "Successfully published to appstore, Please check!", open: "https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa/ra/ng/app/1116025241")
  end

  desc "Package application and upload to dandelion platform"
  lane :pgy do |options|
  	updateProjectBuildNumber #Change project build number
  	dir="./fastlane/build/Pgy"
	# Start packing
	gym(
		#ipa name of the output
		scheme: "CarOwners",
		output_name:"#{scheme}_#{get_build_number()}",
		clean:true,		# Whether to clear the previous compilation information true: Yes
		configuration:"Release",	# Specify packaging method, Release or Debug
		export_method:"development",	# Specify the output method used for packaging. Currently, app store, package, ad-hoc, enterprise, development are supported
		output_directory:"#{dir}",	# Specify output folder
		)
    pgyer(api_key: "cd1ac371b28c9d53930d780925b0ba73", 
    	user_key:   "ffb13d5ca261cf0dab6b8c00f61b4063",
    	update_description: options[:desc])		#desc indicates the update description submitted this time
    notification(title: "Published successfully!", 
    	message: "Successfully uploaded to dandelion platform, Let's contact the tester to start the test!😊", 
    	open: "https://www.pgyer.com/czb365")
  end

  desc "Package project to specified directory"
  lane :package do
    notification(title: "Pack", subtitle: "Start packing", message: "Packing in progress, Please wait...")
    dir="./fastlane/build/Package"
    puts("*************| Package project to catalog |*************")
	updateProjectBuildNumber #Change project build number
  	# Start packing
	gym(
		#ipa name of the output
		scheme: "CarOwners",
		output_name:"Package_CarOwners_#{get_build_number()}",
		silent: false,  # Hide unnecessary building information
		clean:false,		# Whether to clear the previous compilation information true: Yes
		configuration:"Release",	# Specify packaging method, Release or Debug
		export_method:"development",	# Specify the output method used for packaging. Currently, app store, package, ad-hoc, enterprise, development are supported
		buildlog_path: "#{dir}/fastlanelog",  # The log output directory of building ipa by fastlane
		output_directory:"#{dir}",	# Specify output folder
		)
	puts("\n*************| Packaging complete |*************\n")
	puts('output_directory: "#{dir}"')
	notification(title: "Package successful!", message: "Package successful,Please check the console for details!")
  end

  #Callback after executing lane successfully
  after_all do |lane|
    #Send a desktop notification
    notification(title: "execute success", subtitle: "Execution successful!", message: "lane Executed successfully")
  end

  # If the process is abnormal, it will go here and terminate
  error do |lane, exception|
    puts("#{exception.message}")
    notification(title: "implement#{lane} exception occurred! ", message:" exception occurred, please check the console! ")
  end
end

Please refer to official documents for detailed usage

fastlane official website: https://docs.fastlane.tools/

Other

To install and use the Jenkins tutorial: https://www.jianshu.com/p/41ecb06ae95f

Keywords: github iOS git jenkins

Added by stc7outlaw on Thu, 30 Apr 2020 12:03:09 +0300