Skip to content

Instantly share code, notes, and snippets.

@ulhas
Created March 20, 2016 02:58
Show Gist options
  • Save ulhas/e8e529d08849b8cda947 to your computer and use it in GitHub Desktop.
Save ulhas/e8e529d08849b8cda947 to your computer and use it in GitHub Desktop.
Fastfile for HyperTrack iOS SDKs
fastlane_version "1.57.0"
require 'fileutils'
default_platform :ios
platform :ios do
desc "Increment framework version"
private_lane :increment_framework_version do |lane|
if !lane[:framework]
raise "No framework specified!".red
end
if !lane[:version]
raise "No version specified!".red
end
framework = lane[:framework]
version = lane[:version]
increment_version_number(
xcodeproj: "#{framework}/#{framework}.xcodeproj",
version_number: version
)
end
desc "Build framework"
private_lane :build_framework do |lane|
if !lane[:framework]
raise "No framework specified!".red
end
framework = lane[:framework]
scheme = "#{framework}-Universal"
configuration = "Production"
workspace = "HyperTrack.xcworkspace"
if lane[:production] != true
configuration = "Staging"
end
xcodebuild(
scheme: scheme,
workspace: workspace,
configuration: configuration
)
end
desc "Zip and copy to right folder"
private_lane :package_framework do |lane|
if !lane[:framework]
raise "No framework specified!".red
end
if !lane[:version]
raise "No version specified!".red
end
framework = lane[:framework]
version = lane[:version]
destination_path = "#{framework}"
framework_path = "#{destination_path}/Frameworks"
source_path = "#{framework}.framework"
zip_file = "#{version}.zip"
FileUtils::mkdir_p "../build/#{framework_path}"
FileUtils::rm_rf "../build/#{framework_path}/#{framework}.framework"
FileUtils::cp_r "../build/#{source_path}", "../build/#{framework_path}"
FileUtils::rm_rf "../build/#{zip_file}"
sh "cd ../build
zip -r -X #{zip_file} #{destination_path}"
end
desc "Deploy/upload framework"
private_lane :deploy_framework do |lane|
if !lane[:framework]
raise "No framework specified!".red
end
if !lane[:version]
raise "No version specified!".red
end
framework = lane[:framework]
version = lane[:version]
file = "build/#{version}.zip"
folder_name = "#{framework}"
if lane[:production] != true
folder_name = "#{framework}-Staging"
end
upload_to_s3(
region: "us-west-2",
bucket: ENV['S3_BUCKET'],
access_key: ENV['S3_ACCESS_KEY'],
secret_access_key: ENV['S3_SECRET_ACCESS_KEY'],
acl: "public-read",
key: "#{folder_name}/#{version}.zip",
file: file
)
end
desc "Updates framework podspec version"
private_lane :update_framework_podspec do |lane|
if !lane[:framework]
raise "No framework specified!".red
end
if !lane[:version]
raise "No version specified!".red
end
framework = lane[:framework]
version = lane[:version]
podspec = "#{framework}.podspec"
if lane[:production] != true
podspec = "#{framework}.dev.podspec"
end
version = version_bump_podspec(
path: podspec,
version_number: version
)
version = version_bump_podspec(
path: "#{framework}.local.podspec",
version_number: version
)
end
desc "Pushes framework podspec to HyperTrack specs"
private_lane :push_framework_podspec do |lane|
if !lane[:framework]
raise "No framework specified!".red
end
framework = lane[:framework]
podspec = "#{framework}.podspec"
if lane[:production] != true
podspec = "#{framework}.dev.podspec"
end
pod_push(
path: podspec,
repo: 'hypertrack',
sources: ['[email protected]:hypertrack/Specs.git', 'https://github.com/CocoaPods/Specs']
)
end
desc "Increments framework number"
desc "Builds framework"
desc "Packages framework"
desc "Deploys framework to s3"
desc "Updates podspec file"
desc "Pushes podspec file to HyperTrack Spec"
lane :release_framework do |lane|
if !lane[:framework]
raise "No framework specified!".red
end
framework = lane[:framework]
production = lane[:production]
version = lane[:version]
increment_framework_version framework: framework, version: version
build_framework framework: framework, production: production
package_framework framework: framework, production: production, version: version
deploy_framework framework: framework, production: production, version: version
update_framework_podspec framework: framework, production: production, version: version
if production == true
push_framework_podspec framework: framework, production: production
end
end
private_lane :git_commit_example_app do |lane|
ensure_git_branch(
branch: 'develop'
)
sh "git commit -am 'Fastlane: Releases HyperTrack Example App Staging #{version}'"
push_to_git_remote(
remote: 'origin',
local_branch: 'develop',
remote_branch: 'develop',
force: true,
)
end
private_lane :private_beta_crashlytics do |lane|
xcodeproj = "Example/HyperTrack iOS Example (Simple)/HyperTrack iOS Example (Simple).xcodeproj"
scheme = "HyperTrack ObjC Example (Staging)"
build_number = Time.new.strftime("%Y.%m.%d.%H.%M.%S")
increment_build_number(
build_number: build_number,
xcodeproj: xcodeproj
)
version = ht_get_current_version_number()
increment_version_number(
xcodeproj: xcodeproj,
version_number: version
)
gym(
scheme: scheme,
use_legacy_build_api: true,
output_directory: "build/"
)
crashlytics(
crashlytics_path: "Pods/Crashlytics/iOS/Crashlytics.framework",
groups: ["testers"]
)
slack(
message: "New HyperTrack Example app available on Beta 🚀",
success: true,
default_payloads: [:git_branch, :git_author, :lane],
payload: {
'Version Number' => version,
'Build Number' => build_number
}
)
end
desc "Releases Example app on Beta"
desc "Commits changes on git"
desc "Pushes to remote"
lane :beta_crashlytics do |lane|
ensure_git_branch(
branch: 'develop'
)
ensure_git_status_clean
private_beta_crashlytics
git_commit_example_app
end
desc "Releases framework on Production"
desc "Creates a release branch"
desc "Commits and pushes changes to remote"
lane :release_production do |lane|
if !lane[:version]
raise "No version specified".red
end
version = lane[:version]
ensure_git_branch(
branch: 'develop'
)
ensure_git_status_clean
# TODO: Add tests here
changelog = prompt(
text: "ChangeLog: ",
multi_line_end_keyword: "END"
)
sh "git flow release start #{version}"
ht_update_version_number(
version_number: version
)
release_framework framework:"HTCommon", production:true, version:version
release_framework framework:"HTTransmitter", production:true, version:version
release_framework framework:"HTConsumer", production:true, version:version
sh "git commit -am 'Fastlane: Releasing all frameworks on Production #{version}'"
sh "git flow release finish #{version}" # TODO: Fix this. Find a way to finish release with providing message.
push_to_git_remote(
remote: 'origin',
local_branch: 'develop',
remote_branch: 'develop',
force: true,
)
push_to_git_remote(
remote: 'origin',
local_branch: 'master',
remote_branch: 'master',
force: true,
)
appledoc(
project_name: "HyperTrack",
project_version: version,
project_company: "HyperTrack, Inc.",
company_id: "io.hypertrack",
create_html: true,
create_docset: false,
install_docset: false,
ignore: ['Pods'],
output: "./docs/",
input: "."
)
slack(
message: "Released new version for HyperTrack SDKs on Production 🚀",
success: true,
default_payloads: [:git_branch, :git_author, :lane],
payload: {
'Version Number' => version
}
)
end
desc "Releases framework on Staging"
desc "Commits and pushes changes to remote"
lane :release_staging do |lane|
ensure_git_branch(
branch: 'develop'
)
ensure_git_status_clean
# TODO: Add tests here
version = ht_get_next_version_number(
version_number: lane[:version],
bump_type: lane[:bump_type]
)
ht_update_version_number(
version_number: version
)
release_framework framework:"HTCommon", production:false, version:version
release_framework framework:"HTTransmitter", production:false, version:version
release_framework framework:"HTConsumer", production:false, version:version
private_beta_crashlytics
sh "git commit -am 'Fastlane: Releasing all frameworks on Staging #{version}'"
# add_git_tag(
# tag: "#{version}"
# )
push_to_git_remote(
remote: 'origin',
local_branch: 'develop',
remote_branch: 'develop',
force: true,
)
slack(
message: "Released new version for HyperTrack SDKs on Staging 🚀",
success: true,
default_payloads: [:git_branch, :git_author, :lane],
payload: {
'Version Number' => version
}
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment