app_identifier("com.zm.OCTest") # The bundle identifier of your app
apple_id("*********") # Your Apple email address
itc_team_id("*******") # App Store Connect Team ID
team_id("******") # Developer Portal Team ID
# For more information about the Appfile, see:
# https://docs.fastlane.tools/advanced/#appfile
default_platform(:ios)
# 以下是FastFile的配置示例
platform :ios do
desc "Push a new release build to the App Store"
lane :release do
build_app(scheme: "OCTest")
upload_to_app_store(skip_metadata: true, skip_screenshots: true)
end
end
# 一个lane代表一个CI的配置,可以看到release中包括两个步骤build_app,upload_to_app_store。
# build_app,upload_to_app_store 这俩个步骤是fastlane中已经定义好的action工具
在项目目录下执行fastlane match init,输入仓库地址;在fastlane目录下会生成Matchfile文件,包含match的配置信息
执行这些命令fastlane match development, fastlane match adhoc, fastlane match enterprise,fastlane match appstore,首次执行自动在apple store connect中创建provisioning file,证书并下载加密保存在git仓库,并上传.
其他开发者就可以使用fastlane match命令共享github中的证书和配置文件。
match的参数
type: 同步的配置文件类型: appstore,adhoc,development,enterprise,默认 development
pilot 是可以与 TestFlight 交互的 action, 通过 piolt 你可以上传和发布新版本,添加和删除测试员。
pilot 在与 App store 交互之前需要双因素认证,这样就没有办法做自动化;不过苹果在 App Store Connect API 中提供Json Web Token的认证方法;具体在下面会介绍。
pilot参数
api_key_path : App Store Connect API Key JSON 文件的路径
api_key : App Store Connect API Key, 通过 app_store_connect_api_key action 生成
app_identifier : 上传版本的bundle id
ipa: 上传的ipa文件路径
# pilot 需要提供apple开发者账号信息,以及上传文件目录
lane :github_action_testFlight do
pilot(
username: "18351927991@163.com",
app_identifier: "com.zm.ZLGitHubClient",
changelog: "release to TestFlight",
ipa: "./fastlane/ipa/TestFlight/ZLGitHubClient.ipa"
)
end
app_store_connect_api_key 是用来为其他 action 生成 App Store Connect API token 的 action; match,pilot以及 deliver等 action 都可以使用 App Store Connect API token
key_id
issuer_id
key_filePath: p8文件的路径
key_content: p8文件的内容,未编码直接提供需要将回车替换为
is_key_content_base64: 是否key的内容经过base64编码
in_house: 是app store还是 enterprise
lane :release do
api_key = app_store_connect_api_key(
key_id: "D383SF739",
issuer_id: "6053b7fe-68a8-4acb-89be-165aa6465141",
key_filepath: "./AuthKey_D383SF739.p8",
duration: 1200, # optional
in_house: false, # optional but may be required if using match/sigh
)
# 在piolt中使用app_store_connect_api_key
pilot(api_key: api_key)
end
desc "build one TestFlight release on github action"
lane :github_action_testFlight do
# 生成 app store connect api key
api_key = app_store_connect_api_key(
key_id: ENV['APPSTOREAPIKEYID'],
issuer_id: ENV['APPSTOREAPIISSUERID'],
key_content: ENV['APPSTOREAPIKEY'],
duration: 1200, # optional
in_house: false, # optional but may be required if using match/sigh
)
# 创建 key chain 保存 证书
create_keychain(
name: ENV['MATCH_KEYCHAIN_NAME'],
password: ENV['MATCH_PASSWORD'],
default_keychain: true,
unlock: true,
timeout: 3600,
add_to_search_list: true
)
# 同步发布证书
match(type: "appstore",
readonly: true,
app_identifier: "com.zm.*",
profile_name: "*** AppStore com.zm.*",
keychain_name: ENV['MATCH_KEYCHAIN_NAME'],
keychain_password: ENV['MATCH_PASSWORD'],
git_url: ENV['MATCH_GITHUB_URL'])
# 更新build number
build_num = app_store_build_number(
app_identifier: "com.zm.ZLGitHubClient",
live: false,
api_key: api_key
)
increment_build_number(
build_number: build_num + 1
)
# 构建,打包,签名
gym(workspace: "ZLGitHubClient.xcworkspace",
scheme: "ZLGitHubClient",
export_method: "app-store",
clean: true,
include_symbols: true,
include_bitcode: true,
output_directory: "./fastlane/ipa/TestFlight",
output_name: "ZLGitHubClient.ipa")
# 上传 test
pilot(
api_key: api_key,
app_identifier: "com.zm.ZLGitHubClient",
changelog: "release to TestFlight",
ipa: "./fastlane/ipa/TestFlight/ZLGitHubClient.ipa"
)
参考文档
在早先,访问App Store Connect信息需要双因素认证。而在持续集成的过程中一般无法人机交互(例如github-action),导致持续集成无法完成。在WWDC18中,苹果提出了App Store Connect API,提供另外的认证方式。Fastlane也对App Store Connect API提供了支持,具体查看