美文网首页
fastlane 常用函数

fastlane 常用函数

作者: 我的发 | 来源:发表于2022-01-04 17:49 被阅读0次

fastlane生命周期

  • before_all在执行 lane 之前只执行一次
  • before_each每次执行 lane 之前都会执行一次
  • lane自定义的任务
  • after_each每次执行 lane 之后都会执行一次
  • after_all在执行 lane 成功结束之后执行一次
  • error在执行上述情况任意环境报错都会中止并执行一次

环境变量

从 fastlane 的设计体系上在各个地方都加入了环境变量的支持,每个扩展的参数、以及扩展需要共享给其他扩展和任务读取的数据都是通过环境变量获取,如下是我收集的比较常用的列表(需要写入~/.bash_profile文件):

FASTLANE_USER   credentials_manager Apple 开发者账户名    验证通过后会保存 Keychain
FASTLANE_PASSWORD   credentials_manager Apple 开发者账户密码   验证通过后会保存 Keychain
FASTLANE_TEAM_IDCERT_TEAM_ID    producesigh Apple 团队 ID 
DELIVER_USER<br >PRODUCE_USERNAME   deliverproduce  iTunesConnect 账户名   
DELIVER_PASSWORD    deliver iTunesConnect 账户密码  
MATCH_PASSWORD  match   证书加 / 解密密码  
FASTLANE_XCODE_LIST_TIMEOUT fastlane_core   获取 iOS Scheme 的超时时间 默认 10s

打包环境自我诊断(生成和同步证书)

# 开发环境证书
$ fastlane match development
# 产品环境证书
$ fastlane match appstore
# 内测环境证书
$ fastlane match adhoc

如:


image.png

#设置上传testflight待测功能日志,取gitcommit最新10条记录
 changelog_from_git_commits( #设置上传testflight待测功能日志,取gitcommit最新10条记录
      commits_count: 10,
      pretty: "- (%ae) %s",
      date_format: "short",
      match_lightweight_tag: false,
      merge_commit_filtering: "exclude_merges"
    ) 
# 版本号自增
increment_build_number(xcodeproj: "jianzhimao")
# 项目名称
scheme_name = "jianzhimao"
# Debug但还是指定打包时的配置项,默认为Release / "DEBUG"
configuration = "DEBUG"
# info.plist的路径
plist_path = "/Users/jianzhimao/Desktop/PartTimeCat_iOS/jianzhimao/jianzhimao/jianzhimao-Info.plist"
# version 版本号
#version = get_info_plist_value(path: plist_path, key: "CFBundleShortVersionString")
version = get_version_number(xcodeproj: "jianzhimao.xcodeproj")
# build 版本号
#build = get_info_plist_value(path: plist_path, key: "CFBundleVersion")
build = get_build_number(xcodeproj: "jianzhimao.xcodeproj")
# APP名称
app_name = get_info_plist_value(path: plist_path, key: "CFBundleDisplayName")
#输出文件
outputDir = "/Users/jianzhimao/Desktop/fastlane_build_兼职猫"
#当前时间
currentTime = Time.now.strftime('%Y-%m-%d %H:%M')
#打包的ipa名称
outputName = "v#{version}_build#{build}_#{configuration}_#{currentTime}"

# 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)

platform :iOS do

before_all do

puts "// =========== 准备开车 biuing =========== //"
puts last_git_commit

end

# 还不行
lane :testflightBiu do

 desc "// =========== release biu =========== //"

    gym

#上传至testflight
  upload_to_testflight(ipa: outputName , 
username:”1404565175@qq.com” ,  
notes: "this is review note for the reviewer <3 thank you for reviewing") 
 
end


# fir  还不行
lane :firBiu do

 desc "// =========== fir biu =========== //"

gym

fir_api_token="e698f87eec6c3a9b09b959cab914e4e3" # fir token

firim(firim_api_token: fir_api_token)  #上传至fir
 
end


lane :biu do

 desc "// =========== normal biu =========== //"

# 版本号自增
increment_build_number(xcodeproj: "jianzhimao")
# 项目名称
scheme_name = "jianzhimao"
# Debug但还是指定打包时的配置项,默认为Release / "DEBUG"
configuration = "DEBUG"
# info.plist的路径
plist_path = "/Users/jianzhimao/Desktop/PartTimeCat_iOS/jianzhimao/jianzhimao/jianzhimao-Info.plist"
# version 版本号
#version = get_info_plist_value(path: plist_path, key: "CFBundleShortVersionString")
version = get_version_number(xcodeproj: "jianzhimao.xcodeproj")
# build 版本号
#build = get_info_plist_value(path: plist_path, key: "CFBundleVersion")
build = get_build_number(xcodeproj: "jianzhimao.xcodeproj")
# APP名称
app_name = get_info_plist_value(path: plist_path, key: "CFBundleDisplayName")
#输出文件
outputDir = "/Users/jianzhimao/Desktop/fastlane_build_兼职猫"
#当前时间
currentTime = Time.now.strftime('%Y-%m-%d %H:%M')
#打包的ipa名称
outputName = "v#{version}_build#{build}_#{configuration}_#{currentTime}"

# 开干
gym(
  scheme: scheme_name, #你项目的scheme,
  workspace:"#{scheme_name}.xcworkspace",
  clean: false,  # 在打包前是否先执行clean。
  export_xcargs:"-allowProvisioningUpdates",
  output_directory: outputDir,  # 指定.pa文件的输出目录,默认为当前文件夹。
  output_name: outputName,  # 指定生成的ipa文件的名称,应包含文件扩展名。
  configuration: configuration,  # 指定打包时的配置项,默认为Release。
  silent: true,  # 是否隐藏打包时不需要的信息。
  include_symbols: false,
  include_bitcode: false,
  export_method: "ad-hoc",  # 指定导出ipa时使用的方法,可用选项:app-store, ad-hoc, package, enterprise, development, developer-id
)

end

#--发布AppStore上的版本配置
lane :appstoreBiu do

# 版本号自增
increment_build_number(xcodeproj: "jianzhimao")
# 项目名称
scheme_name = "jianzhimao"
# Debug但还是指定打包时的配置项,默认为Release / "DEBUG"
configuration = "DEBUG"
# info.plist的路径
plist_path = "/Users/jianzhimao/Desktop/PartTimeCat_iOS/jianzhimao/jianzhimao/jianzhimao-Info.plist"
# version 版本号
#version = get_info_plist_value(path: plist_path, key: "CFBundleShortVersionString")
version = get_version_number(xcodeproj: "jianzhimao.xcodeproj")
# build 版本号
#build = get_info_plist_value(path: plist_path, key: "CFBundleVersion")
build = get_build_number(xcodeproj: "jianzhimao.xcodeproj")
# APP名称
app_name = get_info_plist_value(path: plist_path, key: "CFBundleDisplayName")
#输出文件
outputDir = "/Users/jianzhimao/Desktop/fastlane_build_兼职猫"
#当前时间
currentTime = Time.now.strftime('%Y-%m-%d %H:%M')
#打包的ipa名称
outputName = "v#{version}_build#{build}_#{configuration}_#{currentTime}"
    sigh(
        app_identifier: "com.jiuwei.jianzhimao",
    username: "1404565175@qq.com"
    )
   
    gym(
    scheme: scheme_name, #你项目的scheme,
    configuration: "Release",
    silent: true,
    clean: true,
    workspace:"#{scheme_name}.xcworkspace",
    include_bitcode: false,
    output_directory: outputDir,  # 指定.pa文件的输出目录,默认为当前文件夹。
    output_name: outputName,  # 指定生成的ipa文件的名称,应包含文件扩展名。
    export_xcargs: "-allowProvisioningUpdates”,
    )
    deliver(
      submit_for_review: false,
      skip_screenshots: true,
      skip_metadata: true
    )
  end

 lane : testflight_beta do # beta是打包的脚本命令 打包上传时执行 fastlane beta
# 版本号自增
increment_build_number(xcodeproj: "jianzhimao")
# 项目名称
scheme_name = "jianzhimao"
# Debug但还是指定打包时的配置项,默认为Release / "DEBUG"
configuration = "DEBUG"
# info.plist的路径
plist_path = "/Users/jianzhimao/Desktop/PartTimeCat_iOS/jianzhimao/jianzhimao/jianzhimao-Info.plist"
# version 版本号
#version = get_info_plist_value(path: plist_path, key: "CFBundleShortVersionString")
version = get_version_number(xcodeproj: "jianzhimao.xcodeproj")
# build 版本号
#build = get_info_plist_value(path: plist_path, key: "CFBundleVersion")
build = get_build_number(xcodeproj: "jianzhimao.xcodeproj")
# APP名称
app_name = get_info_plist_value(path: plist_path, key: "CFBundleDisplayName")
#输出文件
outputDir = "/Users/jianzhimao/Desktop/fastlane_build_兼职猫"
#当前时间
currentTime = Time.now.strftime('%Y-%m-%d %H:%M')
#打包的ipa名称
outputName = "v#{version}_build#{build}_#{configuration}_#{currentTime}"

    build_app(workspace: "#{scheme_name}.xcworkspace", scheme: scheme_name) # 开始打包-打包时使用的配置文件
    upload_to_testflight #打包完成后-上传到testflight
  end


end


相关文章

网友评论

      本文标题:fastlane 常用函数

      本文链接:https://www.haomeiwen.com/subject/uzqkcrtx.html