Files
Sybil-2/ios/fastlane/Fastfile
T

156 lines
4.3 KiB
Ruby
Raw Normal View History

2026-06-05 23:19:14 -07:00
require "shellwords"
default_platform(:ios)
2026-06-26 00:28:27 -07:00
APP_IDENTIFIER = "net.buzzert.sybil2"
SCHEME = "Sybil"
TEAM_ID = "DQQH5H6GBD"
PROFILE_NAME = "Sybil AppStore CI"
2026-06-05 23:19:14 -07:00
IOS_ROOT = File.expand_path("..", __dir__)
PROJECT_FILE = File.join(IOS_ROOT, "Sybil.xcodeproj")
PROJECT_SPEC = File.join(IOS_ROOT, "project.yml")
APP_PROJECT_SPEC = File.join(IOS_ROOT, "Apps/Sybil/project.yml")
2026-06-05 23:19:14 -07:00
def present?(value)
!value.to_s.strip.empty?
end
def ci?
present?(ENV["CI"])
end
2026-06-26 00:28:27 -07:00
def release_version
tag = ENV["SYBIL_VERSION_TAG"]
tag = ENV["GITHUB_REF_NAME"] if !present?(tag)
tag = ENV["GITHUB_REF"].to_s.sub(%r{\Arefs/tags/}, "") if !present?(tag)
2026-06-26 00:28:27 -07:00
tag = sh("git describe --tags --abbrev=0").strip if !present?(tag)
match = tag.to_s.match(%r{\Arelease/ios/v(\d+\.\d+\.\d+)\z})
2026-06-05 23:19:14 -07:00
unless match
UI.user_error!("Release tag must look like release/ios/v1.2.3; got #{tag.inspect}")
2026-06-05 23:19:14 -07:00
end
2026-06-26 00:28:27 -07:00
match[1]
2026-06-05 23:19:14 -07:00
end
# App Store Connect requires CFBundleVersion to be unique and strictly
# increasing app-wide (not just per marketing version), so we derive it from
# the monotonic CI run number rather than querying TestFlight (that query can
# lag behind builds still processing and hand back a colliding value).
def build_number
value = present?(ENV["SYBIL_BUILD_NUMBER"]) ? ENV["SYBIL_BUILD_NUMBER"] : ENV["GITHUB_RUN_NUMBER"]
unless value.to_s.match?(/\A\d+\z/)
UI.user_error!("Build number must come from SYBIL_BUILD_NUMBER/GITHUB_RUN_NUMBER; got #{value.inspect}")
end
value.to_i
end
def stamp_marketing_version(version)
contents = File.read(APP_PROJECT_SPEC)
updated = contents.sub(/^(\s*MARKETING_VERSION:\s*).*/, "\\1\"#{version}\"")
if updated == contents
UI.user_error!("Could not find MARKETING_VERSION in #{APP_PROJECT_SPEC}")
end
File.write(APP_PROJECT_SPEC, updated)
end
2026-06-05 23:19:14 -07:00
platform :ios do
2026-06-26 00:28:27 -07:00
private_lane :app_store_api_key do
app_store_connect_api_key(
key_id: ENV.fetch("APP_STORE_CONNECT_KEY_ID"),
issuer_id: ENV.fetch("APP_STORE_CONNECT_ISSUER_ID"),
key_content: ENV.fetch("APP_STORE_CONNECT_KEY_CONTENT"),
is_key_content_base64: true
)
2026-06-05 23:19:14 -07:00
end
2026-07-11 11:55:04 -07:00
# CI uses a throwaway keychain that is deleted after the lane exits.
private_lane :prepare_ci_keychain do
2026-07-11 11:55:04 -07:00
next nil unless ci?
2026-06-26 00:28:27 -07:00
2026-07-11 11:55:04 -07:00
run_token = "#{Time.now.to_i}_#{Process.pid}"
keychain_name = "fastlane_ci_#{run_token}"
setup_ci(
force: true,
keychain_name: keychain_name,
timeout: 7_200
2026-06-26 00:28:27 -07:00
)
2026-07-11 11:55:04 -07:00
keychain_name
2026-06-26 00:28:27 -07:00
end
private_lane :sync_signing do |options|
match(
2026-06-26 00:28:27 -07:00
type: "appstore",
readonly: options.fetch(:readonly),
app_identifier: APP_IDENTIFIER,
team_id: TEAM_ID,
profile_name: PROFILE_NAME,
git_url: ENV.fetch("MATCH_GIT_URL"),
git_branch: "master",
git_full_name: "Sybil Release Bot",
git_user_email: "james.magahern@me.com",
api_key: options.fetch(:api_key)
)
2026-06-26 00:28:27 -07:00
end
desc "Create or update match signing assets"
lane :setup_signing do
sync_signing(api_key: app_store_api_key, readonly: false)
end
desc "Build and upload to TestFlight"
2026-06-05 23:19:14 -07:00
lane :beta do
2026-07-11 11:55:04 -07:00
ci_keychain_name = nil
2026-06-05 23:19:14 -07:00
2026-07-11 11:55:04 -07:00
begin
ci_keychain_name = prepare_ci_keychain
2026-06-05 23:19:14 -07:00
2026-07-11 11:55:04 -07:00
api_key = app_store_api_key
2026-06-05 23:19:14 -07:00
2026-07-11 11:55:04 -07:00
version = release_version
stamp_marketing_version(version)
sh("xcodegen", "--spec", PROJECT_SPEC)
2026-06-26 00:28:27 -07:00
2026-07-11 11:55:04 -07:00
increment_version_number(version_number: version, xcodeproj: PROJECT_FILE)
increment_build_number(build_number: build_number, xcodeproj: PROJECT_FILE)
2026-06-26 00:28:27 -07:00
2026-07-11 11:55:04 -07:00
sync_signing(api_key: api_key, readonly: true)
sh("security find-identity -v -p codesigning") if ci_keychain_name
build_app(
project: PROJECT_FILE,
scheme: SCHEME,
export_method: "app-store",
codesigning_identity: "Apple Distribution",
xcargs: [
"DEVELOPMENT_TEAM=#{TEAM_ID.shellescape}",
"CODE_SIGN_STYLE=Manual",
"CODE_SIGN_IDENTITY=Apple\\ Distribution",
"PROVISIONING_PROFILE_SPECIFIER=#{PROFILE_NAME.shellescape}"
].join(" "),
export_options: {
signingStyle: "manual",
teamID: TEAM_ID,
provisioningProfiles: {
APP_IDENTIFIER => PROFILE_NAME
}
2026-06-26 00:28:27 -07:00
}
2026-07-11 11:55:04 -07:00
)
2026-06-05 23:19:14 -07:00
2026-07-11 11:55:04 -07:00
upload_to_testflight(
api_key: api_key,
skip_waiting_for_build_processing: true
)
ensure
delete_keychain(name: ci_keychain_name) if ci_keychain_name
end
2026-06-05 23:19:14 -07:00
end
end