Skip to content

Instantly share code, notes, and snippets.

@dtrenz
Created March 5, 2015 22:50
Show Gist options
  • Save dtrenz/f78b48d112a79350b94b to your computer and use it in GitHub Desktop.
Save dtrenz/f78b48d112a79350b94b to your computer and use it in GitHub Desktop.
xcodebuild fastlane action [WIP]
module Fastlane
module Actions
module SharedValues
XCODEBUILD_ARCHIVE = :XCODEBUILD_ARCHIVE
end
# xcodebuild man page:
# https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/xcodebuild.1.html
class XcodebuildAction
ARGS_MAP = {
# actions
analyze: "analyze",
archive: "archive",
build: "build",
clean: "clean",
install: "install",
installsrc: "installsrc",
test: "test",
# parameters
arch: "-arch",
alltargets: "-alltargets",
archive_path: "-archivePath",
configuration: "-configuration",
derivedDataPath: "-derivedDataPath",
destination: "-destination",
export_archive: "-exportArchive",
export_format: "-exportFormat",
export_installer_identity: "-exportInstallerIdentity",
export_path: "-exportPath",
export_profile: "-exportProvisioningProfile",
export_signing_identity: "-exportSigningIdentity",
export_with_original_signing_identity: "-exportWithOriginalSigningIdentity",
project: "-project",
result_bundle_path: "-resultBundlePath",
scheme: "-scheme",
sdk: "-sdk",
skip_unavailable_actions: "-skipUnavailableActions",
target: "-target",
workspace: "-workspace",
xcconfig: "-xcconfig"
}
def self.run(params)
unless Helper.test?
raise "xcodebuild not installed".red if `which xcodebuild`.length == 0
end
# The args we will build with
cli_args = Array[]
if params = params.first
if params.key? :archive_path
# Cache path for later xcodebuild calls
Actions.lane_context[SharedValues::XCODEBUILD_ARCHIVE] = params[:archive_path]
else
# Retrieve path from previous xcodebuild call
params[:archive_path] = Actions.lane_context[SharedValues::XCODEBUILD_ARCHIVE]
end
# If exporting an *.ipa
if params.key? :export_format && (params[:export_format] == "ipa")
# Store the path to the exported *.ipa for other build steps to use
Actions.lane_context[SharedValues::IPA_OUTPUT_PATH] = params[:export_path] + ".ipa"
end
unless params.key? :export_archive
params[:scheme] ||= ENV["SCHEME"]
params[:workspace] ||= ENV["WORKSPACE"]
end
# Maps parameter hash to CLI args
hash_args = hash_to_cli_args(params)
if (hash_args)
cli_args += hash_args
end
end
# Joins args into space delimited string
cli_args = cli_args.join(" ")
command = "xcodebuild #{cli_args}"
Helper.log.debug command
Actions.sh command
end
def self.hash_to_cli_args(hash)
# Maps nice developer param names to CLI arguments
hash.map do |k, v|
v ||= ""
if arg = ARGS_MAP[k]
value = (v != true && v.to_s.length > 0 ? "\"#{v}\"" : "")
"#{arg} #{value}".strip
elsif k == :keychain && v.to_s.length > 0
# If keychain is specified, append as OTHER_CODE_SIGN_FLAGS
"OTHER_CODE_SIGN_FLAGS=\"--keychain #{v}\""
end
end.compact
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment