tooot/fastlane/Fastfile

165 lines
4.9 KiB
Ruby

fastlane_version "2.173.0"
skip_docs
ensure_env_vars(
env_vars: ["TOOOT_ENVIRONMENT", "SENTRY_ORGANIZATION", "SENTRY_PROJECT", "SENTRY_AUTH_TOKEN"]
)
VERSIONS = read_json( json_path: "./package.json" )[:versions]
ENVIRONMENT = ENV["TOOOT_ENVIRONMENT"]
VERSION = "#{VERSIONS[:major]}.#{VERSIONS[:minor]}"
RELEASE_CHANNEL = "#{VERSIONS[:major]}-#{ENVIRONMENT}"
BUILD_NUMBER = ENV["GITHUB_RUN_NUMBER"]
GITHUB_REPO = "tooot-app/app"
case ENVIRONMENT
when "development"
GITHUB_RELEASE= ""
when "staging"
GITHUB_RELEASE = "v#{VERSION}-#{VERSIONS[:patch]}"
when "production"
GITHUB_RELEASE = "v#{VERSION}"
end
XCODEPROJ = "./ios/tooot.xcodeproj"
INFO_PLIST = "./ios/tooot/Info.plist"
EXPO_PLIST = "./ios/tooot/Supporting/Expo.plist"
desc "IOS: Prepare app store"
private_lane :prepare_appstore_ios do
set_info_plist_value( path: INFO_PLIST, key: "CFBundleShortVersionString", value: VERSION )
increment_build_number( xcodeproj: XCODEPROJ, build_number: BUILD_NUMBER )
app_store_connect_api_key
end
desc 'IOS: Update expo information'
private_lane :update_expo_ios do
set_info_plist_value( path: EXPO_PLIST, key: "EXUpdatesSDKVersion", value: VERSIONS[:expo] )
set_info_plist_value( path: EXPO_PLIST, key: "EXUpdatesReleaseChannel", value: RELEASE_CHANNEL )
end
desc 'IOS: Upload dSYM'
lane :upload_symbols_ios do
download_dsyms
sentry_upload_dsym(
org_slug: ENV["SENTRY_ORGANIZATION"],
project_slug: ENV["SENTRY_PROJECT"]
)
end
desc "ANDROID: Prepare play store"
private_lane :prepare_playstore_android do
android_set_version_name( version_name: VERSION, gradle_file: "./android/app/build.gradle" )
android_set_version_code( version_code: BUILD_NUMBER, gradle_file: "./android/app/build.gradle" )
end
desc "Create new GitHub release"
private_lane :github_release do |options|
set_github_release(
repository_name: GITHUB_REPO,
name: GITHUB_RELEASE,
tag_name: GITHUB_RELEASE,
description: "No changelog provided",
commitish: git_branch,
is_prerelease: options[:prerelease]
)
end
desc "Expo release"
private_lane :expo_release do
yarn( package_path: "./package.json", flags: "release", command: RELEASE_CHANNEL )
end
desc "Build and deploy iOS app"
private_lane :build_ios do
BUILD_DIRECTORY = "./ios/build"
update_expo_ios
setup_ci
case ENVIRONMENT
when "development"
match( type: "development", readonly: true )
if !is_ci
build_ios_app( export_method: "development", output_directory: BUILD_DIRECTORY )
install_on_device( skip_wifi: true )
end
when "staging"
prepare_appstore_ios
match( type: "appstore", readonly: true )
build_ios_app( export_method: "app-store", include_symbols: true, include_bitcode: true )
upload_to_testflight(
demo_account_required: true,
distribute_external: true,
groups: "内测用户",
changelog: "Ready for testing"
)
upload_symbols_ios
when "production"
prepare_appstore_ios
match( type: "appstore", readonly: true )
build_ios_app( export_method: "app-store" )
end
end
desc "Build and deploy Android app"
private_lane :build_android do
sh("echo #{ENV["ANDROID_KEYSTORE"]} | base64 -d | tee #{File.expand_path('..', Dir.pwd)}/android/tooot.jks >/dev/null", log: false)
case ENVIRONMENT
when "development"
if !is_ci
build_android_app(
task: 'assemble',
build_type: 'release',
project_dir: "./android"
)
adb(
command: "install #{lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH]}"
)
end
when "staging"
prepare_playstore_android
build_android_app(
task: 'clean bundle',
build_type: 'release',
project_dir: "./android",
print_command: false,
print_command_output: false,
properties: {
"expoSDK" => VERSIONS[:expo],
"releaseChannel" => RELEASE_CHANNEL,
"android.injected.signing.store.file" => "#{File.expand_path('..', Dir.pwd)}/android/tooot.jks",
"android.injected.signing.store.password" => ENV["ANDROID_KEYSTORE_PASSWORD"],
"android.injected.signing.key.alias" => ENV["ANDROID_KEYSTORE_ALIAS"],
"android.injected.signing.key.password" => ENV["ANDROID_KEYSTORE_KEY_PASSWORD"],
}
)
upload_to_play_store(
track: "beta",
skip_upload_metadata: true,
skip_upload_changelogs: true,
skip_upload_images: true,
skip_upload_screenshots: true
)
when "production"
end
end
lane :build do
releaseExists = get_github_release(url: GITHUB_REPO, version: GITHUB_RELEASE)
if releaseExists
puts("Release #{GITHUB_RELEASE} exists. Continue with building React Native only.")
else
puts("Release #{GITHUB_RELEASE} does not exist. Create new release as well as new native build.")
build_ios
build_android
case ENVIRONMENT
when "staging"
github_release(prerelease: true)
when "production"
github_release(prerelease: false)
end
end
expo_release
rocket
end