Last active
August 15, 2018 05:01
-
-
Save yoxisem544/1c5cec0657ecdc0d0937a0c46f32c496 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
ENV["SLACK_URL"] = "https://hooks.slack.com/services/SOME/THING/GENERATE_BY_SLACK" | |
ENV["FASTLANE_USER"] = "<YOUR_APPLE_ID>" | |
ENV["FASTLANE_PASSWORD"] = "<YOUR_APPLE_ID_PASSWORD>" | |
ENV["FASTLANE_ITC_TEAM_NAME"] = "<YOUR_TEAM_NAME>" | |
ENV["FASTLANE_TEAM_ID"] = "<YOUR_TEAM_ID>" | |
ENV["MATCH_GIT_URL"] = "<MATCH_REPO_URL>" | |
ENV["FASTLANE_OUTPUT_DIRECTORY"] = "<LOCATION_YOUR_BUILD_OUTPUT_WILL_BE>" | |
@output_directory = ENV["FASTLANE_OUTPUT_DIRECTORY"] | |
# Who build the lane, can specify this in zshrc or bashrc | |
@build_by = ENV["BUILD_BY"] | |
# git url of match | |
@match_git_url = ENV["MATCH_GIT_URL"] | |
# Configuration to build an app | |
# minimum requirment to pack an app | |
Configuration = Struct.new( | |
:provisioningProfile, # file name of the provisioning profile | |
:buildConfiguration, # configuration name in xcode project | |
:appIdentifier, # the app id for this configuration | |
:exportMethod, # export methods, such as "ad-doc" or "appstore" | |
:productName, # product name of config | |
:scheme, # scheme to build ipa | |
:matchType) # type to use match, type is adhoc, appstore and so on. | |
@alpha = Configuration.new( | |
"match AdHoc io.hello.your-app-dev", | |
"Debug", | |
"io.hello.your-app-dev", | |
"ad-hoc", | |
"Your App Alpha", | |
"Your-App-Dev", | |
"adhoc") | |
@beta = Configuration.new( | |
"match AdHoc io.hello.your-app-beta", | |
"Beta", | |
"io.hello.your-app-beta", | |
"ad-hoc", | |
"Your App Beta", | |
"Your-App-Beta", | |
"adhoc") | |
@release = Configuration.new( | |
"match AppStore io.hello.your-app", | |
"App Store", | |
"io.hello.your-app", | |
"app-store", | |
"Your App", | |
"Your-App-AppStore", | |
"appstore") | |
module ProjectSetting | |
Target = "Your-App" | |
ProjectName = "Your-App.xcodeproj" | |
WorkspaceName = "Your-App.xcworkspace" | |
SDK = "iphoneos" | |
end | |
def match_config(config) | |
match(git_url: @match_git_url, | |
type: config.matchType, | |
app_identifier: config.appIdentifier) | |
end | |
def package(config) | |
# increase build number everytime when packaging a new build | |
increment_build_number | |
# stamp a bage on beta/alpha apps | |
stampBadge(config) | |
build_app( | |
workspace: ProjectSetting::Workspace, | |
scheme: config.scheme, | |
clean: true, | |
output_directory: @output_directory, | |
output_name: "#{config.productName}.ipa", | |
configuration: config.buildConfiguration, | |
silent: true, | |
export_method: config.exportMethod, | |
export_options: { | |
signingStyle: "automatic", # or manual | |
compileBitcode: false, | |
uploadBitcode: false, | |
provisioningProfiles: { | |
config.appIdentifier => config.provisioningProfile | |
} | |
}, | |
sdk: ProjectSetting::SDK | |
) | |
end | |
default_platform(:ios) | |
platform :ios do | |
before_all do | |
cocoapods( | |
clean: true, | |
podfile: "Podfile", | |
try_repo_update_on_error: true | |
) | |
end | |
desc "Submit app to crashlytics for internal Bitwan internal testers." | |
lane :beta do | |
begin | |
match_config(@beta) | |
package(@beta) | |
upload_to_beta("bitcle") | |
notify_deliver_to_beta | |
rescue => e | |
notify_error(e) | |
end | |
end | |
desc "Submit app to crashlytics for internal Bitcle engineer team." | |
lane :alpha do | |
begin | |
match_config(@alpha) | |
package(@alpha) | |
upload_to_beta("bitcle-eng.") | |
notify_deliver_to_beta | |
rescue => e | |
notify_error(e) | |
end | |
end | |
desc "Submit app to testflight for external beta testers." | |
lane :testflight do | |
begin | |
match_config(@release) | |
package(@release) | |
upload_to_testflight | |
notify_deliver_to_testflight | |
rescue => e | |
notify_error(e) | |
end | |
end | |
desc "Submit app to App Store." | |
lane :appstore do | |
begin | |
match_config(@release) | |
package(@release) | |
deliver(force: true) | |
automatic_release(false) | |
notify_deliver_to_appstore | |
rescue => e | |
notify_error(e) | |
end | |
end | |
# interesting things to play with | |
# you will get badge on your app icon on alpha/beta testing app | |
def stampBadge(config) | |
build_number = get_build_number(xcodeproj: ProjectSetting::ProjectName) | |
version = get_version_number(xcodeproj: ProjectSetting::ProjectName) | |
if config == @alpha | |
badge(alpha: true, | |
dark: true, | |
shield: "Ver-#{version} (#{build_number})-orange") | |
elsif config == @beta | |
badge(dark: true, | |
shield: "Ver-#{version} (#{build_number})-orange") | |
end | |
end | |
def upload_to_beta(groups = "") | |
# submit beta test to bitcle-eng. group | |
# group name here should be alias below the group name you type. | |
crashlytics(api_token: "<CRASHLYTICS_API_TOKEN>", | |
build_secret: "<CRASHLYTICS_BUILD_SECRET>", | |
groups: groups) | |
end | |
def notify_deliver_to_appstore | |
slack_message("🙆♂️ Successfully Deliver to App Store! (๑´ㅂ`๑) 🙆♂️", true) | |
end | |
def notify_deliver_to_beta | |
slack_message("🚦 Beta app released! ヽ(✿゚▽゚)ノ 🚦", true) | |
end | |
def notify_deliver_to_testflight | |
slack_message("✈️ Successfully Deliver to TestFlight! (ノ>ω<)ノ ✈️", true) | |
end | |
def notify_error(exception) | |
slack_message("🖕 Something Wrong (メ ゚皿゚)メ 🖕\n#{exception}", false) | |
puts exception.message | |
throw exception # throw error to cause lane to fail | |
end | |
def slack_message(message, success) | |
slack( | |
message: message, | |
channel: "#devops", # Optional, by default will post to the default channel configured for the POST URL. | |
success: success, # Optional, defaults to true. | |
payload: { # Optional, lets you specify any number of your own Slack attachments. | |
"Build Date" => Time.new.to_s, | |
"Built by" => @build_by || "Anonymous", | |
}, | |
default_payloads: [:git_branch, :git_author] | |
) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment