Skip to content

Instantly share code, notes, and snippets.

@imWildCat
Created August 25, 2021 12:35
Show Gist options
  • Save imWildCat/4c36d239ea0a5f5758058e3ef4ad4200 to your computer and use it in GitHub Desktop.
Save imWildCat/4c36d239ea0a5f5758058e3ef4ad4200 to your computer and use it in GitHub Desktop.
Fastfile
# frozen_string_literal: true
# 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
default_platform(:ios)
# xcode_select '/Applications/Xcode-beta.app'
def build_number_from_rc
build_number = `zsh #{File.expand_path('..', Dir.pwd)}/Scripts/ci/set_and_get_build_number.sh`
build_number = build_number.to_i
puts "Build number (int): #{build_number}"
build_number
end
platform :ios do
def localized_app_information
{
"default": {
feedback_email: 'youappname.app@gmail.com',
marketing_url: 'https://www.youappname.com',
privacy_policy_url: 'https://www.youappname.com/privacy',
description: '...'
},
"zh-Hans": {
feedback_email: 'youappname.app@gmail.com',
marketing_url: 'https://www.youappname.com',
privacy_policy_url: 'https://www.youappname.com/privacy',
description: '...'
}
}
end
def get_change_log
version_number = get_version_number(
xcodeproj: 'Yourappname.xcodeproj',
target: 'Yourappname'
)
# http://git-scm.com/docs/pretty-formats
# <short hash> <commit title>
# changelog_from_git_commits(pretty: '%h %s', match_lightweight_tag: true)
{
'default': {
whats_new: File.read("#{File.expand_path('..', Dir.pwd)}/fastlane/metadata/en-US/version_whats_new.txt")
},
'zh-Hans': {
whats_new: File.read("#{File.expand_path('..', Dir.pwd)}/fastlane/metadata/zh-Hans/version_whats_new.txt")
}
}
end
lane :test_log do
p localized_app_information
p get_change_log
obj = get_change_log[:default][:whats_new]
p obj
end
lane :send_slack_new_tag do
change_log = get_change_log
slack(
message: "App is being released! Please check the schema change (<https://icloud.developer.apple.com/dashboard/#containers/iCloud.app.YourAppTarget>). \n*Changelog:* \n #{change_log}"
)
end
desc 'Build Release'
lane :build_release do
xcode_select '/Applications/Xcode.app'
# Clean up (skipping for now)
# clear_derived_data
# sync_code_signing
increment_build_number(build_number: build_number_from_rc)
build_app(
workspace: 'Yourappname.xcworkspace',
scheme: 'Yourappname',
include_bitcode: true,
archive_path: './tmp/ios_archive',
derived_data_path: './tmp/derived_data',
export_options: {
method: 'app-store',
provisioningProfiles: {
# Profile names can be found at https://developer.apple.com/account/resources/profiles/list
# If they do not exist, you can create it.
# Provisioning profiles are used for mapping codesign certificates between bundle IDs.
'com.YourAppTarget.bundle.id' => ENV['app_YourAppTarget_core_profile'],
'com.YourAppTarget.bundle.id.YourAppTargetShareExtension' => ENV['app_YourAppTarget_core_YourAppTargetShareExtension_profile']
}
}
)
end
desc 'Push a new beta build to TestFlight'
lane :publish_tf do
api_key = app_store_connect_api_key(
key_id: 'your_key_id',
issuer_id: 'your-key-issuer-id',
key_filepath: ENV['APP_STORE_CONNECT_KEY_PATH'],
# duration: 1200, # optional
in_house: false # optional but may be required if using match/sigh
)
xcode_select '/Applications/Xcode.app'
localized_build_info = get_change_log
localized_app_info = localized_app_information
upload_to_testflight(
skip_waiting_for_build_processing: false,
localized_build_info: localized_build_info,
localized_app_info: localized_app_info,
demo_account_required: false,
notify_external_testers: true
)
end
desc 'Make screenshots'
lane :gen_screenshots do
xcode_select '/Applications/Xcode.app'
snapshot(
only_testing: 'YourappnameUITests',
scheme: 'YourappnameUITests',
derived_data_path: "#{File.expand_path('~')}/Library/Developer/Xcode/DerivedData",
test_without_building: false,
headless: true,
disable_slide_to_type: true,
reinstall_app: true,
)
end
desc 'Refine screenshots for App Store'
lane :refine_screenshots do
frameit(
path: "./fastlane/screenshots",
silver: true,
)
end
desc 'App store metadata distribution'
lane :upload_metadata do
upload_to_app_store(
screenshots_path: 'fastlane/screenshots',
overwrite_screenshots: true,
skip_binary_upload: true,
skip_metadata: false,
skip_screenshots: false, # Note: use `false` while uploading screenshots
force: true, # no preview
)
end
desc 'Upload iOS dSYMs to AppCenter'
lane :upload_dsym_app_center do
version = get_version_number(
xcodeproj: 'Yourappname.xcodeproj',
target: 'Yourappname'
)
build_number = get_build_number(
xcodeproj: 'Yourappname.xcodeproj'
)
appcenter_upload(
api_token: ENV['IF_ACENTER_TOKEN'],
owner_name: 'catstudio',
owner_type: 'user', # Default is user - set to organization for appcenter organizations
app_name: 'YourAppTarget-iOS',
file: './Yourappname.app.zip',
dsym: './tmp/ios_archive.xcarchive/dSYMs',
upload_dsym_only: true,
notify_testers: false, # Set to false if you don't want to notify testers of your new release (default: `false`)
build_number: build_number,
version: version
)
end
desc 'Build only'
lane :build_only do
# Build without sign
xcodebuild(archive: false, scheme: 'Yourappname', workspace: 'Yourappname.xcworkspace')
end
lane :tests do
run_tests(workspace: 'Yourappname.xcworkspace',
devices: ['iPhone 12'],
scheme: 'Yourappname',
slack_channel: '#gitlab',
reset_simulator: true,
slack_only_on_failure: true)
end
lane :clean_derived do
clear_derived_data
clear_derived_data(derived_data_path: './tmp/derived_data')
slack(
channel: '#gitlab',
success: true,
message: 'Cleaned derived data and CocoaPods cache because the build failed once.'
)
end
lane :lint do
# swiftlint(
# mode: :lint, # SwiftLint mode: :lint (default) or :autocorrect
# # path: "/path/to/lint", # Specify path to lint (optional)
# # output_file: "swiftlint.result.json", # The path of the output file (optional)
# config_file: '.swiftlint.yml', # The path of the configuration file (optional)
# # files: [# List of files to process (optional)
# # "AppDelegate.swift",
# # "path/to/project/Model.swift"
# # ],
# ignore_exit_status: false # Allow fastlane to continue even if SwiftLint returns a non-zero exit status
# )
swiftformat(
executable: 'Pods/SwiftFormat/CommandLineTool/swiftformat', # Path to the `swiftformat` executable on your machine (optional)
config: './.swiftformat', # Path to configuration file (optional)
dryrun: false, # Run in dry mode (without actually changing any files) (optional)
lint: true # Like `--dryrun`, but returns an error if formatting is needed (optional)
)
end
end
platform :mac do
desc 'Build Mac app'
lane :build do
# clear_derived_data
increment_build_number(build_number: build_number_from_rc)
build_app(
scheme: 'Yourappname',
workspace: 'Yourappname.xcworkspace',
configuration: 'Release',
catalyst_platform: 'macos',
archive_path: './tmp/mac_archive',
derived_data_path: './tmp/derived_data',
skip_package_pkg: true,
export_method: 'developer-id'
)
end
desc 'Notarize macCatalyst'
lane :notarize_mac do
notarize(
package: 'tmp/exported_archive/Yourappname.app',
bundle_id: 'com.YourAppTarget.bundle.id',
print_log: true,
verbose: true
)
end
desc 'Distribute to App Center'
lane :dist_appcenter do
version = get_version_number(
xcodeproj: 'Yourappname.xcodeproj',
target: 'Yourappname'
)
build_number = get_build_number(
xcodeproj: 'Yourappname.xcodeproj'
)
change_log_text = get_change_log[:default][:whats_new]
sign_output = File.read("#{File.expand_path('..', Dir.pwd)}/tmp/exported_archive/sign_out.txt")
ed_signature = /edSignature="(.+)" /.match(sign_output)[1]
puts "ed_signature: #{ed_signature}, sign_output: #{sign_output}"
appcenter_upload(
api_token: ENV['IF_ACENTER_TOKEN'],
owner_name: 'catstudio',
owner_type: 'user', # Default is user - set to organization for appcenter organizations
app_name: 'YourAppTarget',
file: './tmp/exported_archive/Yourappname.app.zip',
dsym: './tmp/mac_archive.xcarchive/dSYMs',
notify_testers: false, # Set to false if you don't want to notify testers of your new release (default: `false`)
build_number: build_number,
version: version,
release_notes: change_log_text,
ed_signature: ed_signature,
)
end
end
if [ -z "$MAC_APPCENTER" ]; then
BUILD_NUMBER=$(git describe --tags | awk -F '-' '{print $2}' | sed "s/rc//g")
else
BUILD_NUMBER=$(git rev-list --no-merges --count HEAD)
fi
gsed -i "s/\(BUILD_VERSION *= *\).*/\1$BUILD_NUMBER/" MainTargerFolder/YourAppVersion.xcconfig
echo -n $BUILD_NUMBER
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment