Skip to content

Instantly share code, notes, and snippets.

@bbedward
Last active December 22, 2022 14:02
Show Gist options
  • Save bbedward/9f70e98b08938e708f7c3307a4bc706b to your computer and use it in GitHub Desktop.
Save bbedward/9f70e98b08938e708f7c3307a4bc706b to your computer and use it in GitHub Desktop.
CI/CD In Flutter using GitLab and Fastlane Tutorial
# Automatically update fastlane
update_fastlane
default_platform(:ios)
# Default temporary keychain password and name, if not included from environment
TEMP_KEYCHAIN_NAME_DEFAULT = "fastlane_flutter"
TEMP_KEYCHAN_PASSWORD_DEFAULT = "temppassword"
# Remove the temporary keychain, if it exists
def delete_temp_keychain(name)
delete_keychain(
name: name
) if File.exist? File.expand_path("~/Library/Keychains/#{name}-db")
end
# Create the temporary keychain with name and password
def create_temp_keychain(name, password)
create_keychain(
name: name,
password: password,
unlock: false,
timeout: false
)
end
# Ensure we have a fresh, empty temporary keychain
def ensure_temp_keychain(name, password)
delete_temp_keychain(name)
create_temp_keychain(name, password)
end
platform :ios do
desc "Build & sign iOS app"
lane :build_ios do |options|
disable_automatic_code_signing(
path: "./Runner.xcodeproj",
team_id: CredentialsManager::AppfileConfig.try_fetch_value(:team_id),
profile_name: "match AppStore #{CredentialsManager::AppfileConfig.try_fetch_value(:app_identifier)}",
code_sign_identity: "iPhone Distribution"
)
keychain_name = ENV['TEMP_KEYCHAIN_NAME'] || TEMP_KEYCHAIN_NAME_DEFAULT
keychain_password = ENV['TEMP_KEYCHAIN_PASSWORD'] || TEMP_KEYCHAN_PASSWORD_DEFAULT
ensure_temp_keychain(keychain_name, keychain_password)
match(
app_identifier: CredentialsManager::AppfileConfig.try_fetch_value(:app_identifier),
type: "appstore",
readonly: is_ci,
keychain_name: keychain_name,
keychain_password: keychain_password
)
sh "./flutter_test.sh"
sh "./flutter_build.sh --clean"
build_ios_app(
export_options: {
method: "app-store"
}
)
delete_temp_keychain(keychain_name)
end
desc "Upload iOS app to app store"
lane :deploy_ios do |options|
# Upload to test flight or AppStore depending on caller parameters
if options[:testflight]
upload_to_testflight(
skip_submission: true,
ipa: "./Runner.ipa"
)
else
deliver(
skip_metadata: false,
skip_screenshots: true,
submit_for_review: true,
force: true,
ipa: "./Runner.ipa"
)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment