fastlane简介:
Git地址:Fastlane文档地址:Fastlane Document
- Fastlane是一整套的客户端CICD工具集合。Fastlane可以非常快速简单的搭建一个自动化发布服务,并且支持Android,iOS,MacOS。
- Fastlane命令执行的底层并不是自己实现的,而是调用其他的插件或者工具执行的。比如说打包,Fastlane中的gym工具只是xcodebuild工具的一个封装,调用的其实还是xcodebuild中的打包命令。
- Fastlane本身没有一套特殊语法,使用的Ruby语言。
- Fastlane的插件工具叫做action,每一个action都对应一个具体的功能
Xcode -> Manager Scheme -> 项目勾选☑️Shared
~ % ruby -v
ruby 2.6.8p205 (2021-07-07 revision 67951) [universal.x86_64-darwin21]
~ % brew install ruby
~ % xcode-select --install
~ % sudo gem install fastlane -NV
Successfully installed fastlane-2.209.1
75 gems installed
~ % brew install fastlane
~ % fastlane -v
fastlane installation at path:
/Library/Ruby/Gems/2.6.0/gems/fastlane-2.209.1/bin/fastlane
-----------------------------
[✔] ?
fastlane 2.209.1
#fastlane
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
sudo gem install bundler:2.1.2
~ % cd ../Desktop/你的项目名
~ % fastlane init
What would you like to use fastlane for?
1.Automate screenshots
2.Automate beta distribution to TestFlight
3.Automate App Store distribution
4.Manual setup - manually setup your project to automate your tasks
你想用fastlane做什么事情:
1 自动截屏。(帮助我们截取App的显示到appstore上的 截图)
2 自动发布beta到TestFlight上,用于内测。
3 自动打包发布到AppStore上。
4 手动设置。
source "https://rubygems.org"
gem "fastlane" #初始化fastlane
gem "cocoapods" #如果项目中采用了cocoapods,需要自己加上
~ % bundle update
参考:MacOS代理设置
#source "https://rubygems.org"
source "https://ruby.taobao.org"
fastlane_version "2.209.1" #指定fastlane使用的最小版本
default_platform(:ios) #支持 ios、android、mac
platform :ios do
before_all do #在执行每个lane之前都会先执行
cocoapods
end
desc "自定义test的描述"
lane :test do #名叫test的lane指令集合
end
desc "自定义beta的描述"
lane :beta do #名叫beta的lane指令集合
end
desc "自定义release的描述"
lane :release do #名叫release的指令集合
end
after_all do |lane| #每个lane执行完之后会执行这里
end
error do |lane, exception| #每个lane执行出错会执行
end
end
~ % fastlane test
[✔] ?
[15:00:01]: fastlane detected a Gemfile in the current directory
[15:00:01]: However, it seems like you didn't use `bundle exec`
[15:00:01]: To launch fastlane faster, please use
[15:00:01]:
[15:00:01]: $ bundle exec fastlane upload_toServer
[15:00:01]:
[15:00:01]: Get started using a Gemfile for fastlane https://docs.fastlane.tools/getting-started/ios/setup/#use-a-gemfile
[15:00:03]: ----------------------------------------
[15:00:03]: --- Step: Verifying fastlane version ---
[15:00:03]: ----------------------------------------
[15:00:03]: Your fastlane version 2.209.1 matches the minimum requirement of 2.209.1 ✅
[15:00:03]: ------------------------------
[15:00:03]: --- Step: default_platform ---
[15:00:03]: ------------------------------
[15:00:03]: Driving the lane 'mac upload_toServer' ?
+------+----------------------------+-------------+
| fastlane summary |
+------+----------------------------+-------------+
| Step | Action | Time (in s) |
+------+----------------------------+-------------+
| 1 | Verifying fastlane version | 0 |
| 2 | default_platform | 0 |
+------+----------------------------+-------------+
[15:00:03]: fastlane.tools finished successfully ?
default_platform(:ios) #支持 ios、android、mac
platform :ios do
desc "项目打包"
lane :beta do
#build_app()主要是编译打包成ipa文件这个过程的相关操作
#gym主要是编译打包成功后,对导出的IPA包的操作,gym中的相关参数可参考build_app中的参数,因为两者的参数基本一致
gym(
scheme:"项目名", # 如果有多个Target,需要指定scheme名
workspace: "项目名.xcworkspace", # 指定项目工作空间,如果项目使用CocoaPods需要加上
clean: true, # 是否编译前clean
configuration: "Debug", # Release或Debug
output_name: "自定义", # 重命名导出包的名字(可不指定,不指定默认项目名,注意若重命名会生成两不同名的包,一个项目名一个自定义名)
output_directory:"./fastlane/build", # 自定义导出包的Copy目录(若无自动创建,可不指定,不指定默认存到Xcode打包路径:/Users/用户名/Library/Developer/Xcode/Archives)
export_xcargs: "-allowProvisioningUpdates",# 启用Xcode的自动管理签名功能,默认是关闭的
export_method:"enterprise", # 打包方式(可选项: app-store, validation, ad-hoc, package, enterprise, development, developer-id and mac-application)
)
end
end
pgyer(
api_key: "你蒲公英的api_key",
user_key: "你蒲公英的user_key"",
update_description: "fix something"
)
firim(
firim_api_token: '你在firim网站登录后,点击头像,可以查看API token。复制到这地方'
)
ftp(
host: 'ftp.domain.com',
username: 'your username',
password: 'your password',
upload: {
src: ipa_src,
dest:"/xxx/"
}
)
参考:scp配置
#!/bin/bash
#上传文件到服务器
IPAPATH="/Users/用户名/Desktop/demo.ipa" #本机ipa存放路径
scp -r $IPAPATH root@xxx.xx.xxx.xxx:/服务器存放地址路径/demo.ipa #-r代表替换,不加也是默认替换
~ % 脚本路径/xx.sh
desc "2.上传包文件到服务器(使用scp方式)"
lane :upload_toServer do
scp(
host: "xxx.xx.xxx.xxx", # 服务器ip地址,如180.10.200.200
username: "root", # 服务器用户名
upload: {
src: "#{$outputDir}/#{$project_abbreviation}.ipa, #原始包文件地址,必须真实存在
dst: "/服务器提供的文件目录/#{$project_abbreviation}.ipa" #服务器上传的包文件地址,同名的话默认每次上传会替换该文件
}
)
end
~ % cd 项目路径
~ % ssh-add
[18:50:51]: fastlane finished with errors
/Library/Ruby/Gems/2.6.0/gems/net-ssh-6.1.0/lib/net/ssh/authentication/ed25519_loader.rb:21:in
`raiseUnlessLoaded': OpenSSH keys only supported if ED25519 is available (NotImplementedError)
net-ssh requires the following gems for ed25519 support:
* ed25519 (>= 1.2, < 2.0)
* bcrypt_pbkdf (>= 1.0, < 2.0)
*
~ % fastlane upload_toServer
[18:52:57]: fastlane.tools finished successfully ?
注意:mac的.app包文件必须打包成dmg再通过scp上传到服务器,否则服务器接收到的是许多文件的列表,而不是.app项目
1.安装dmg插件:官方文档具体可看
~ % fastlane add_plugin dmg
Successfully installed plugins
安装完成后会更新项目中的Gemfile文件和./fastlane/Pluginfile文件
2.fastlane文件里打包dmg官方示例写法:
dmg(path: "/some/myapp/", # required
output_path: "/some/myapp.dmg", # optional, by default will be at the same location as 'myapp' folder
volume_name: "myapp", # optional, by default will be the same as input folder name
filesystem: "hfs+", # optional, default is 'hfs+'
format: "udzo", # optional, default is 'udzo'
size: 10) # in megabytes, optional, by default will be calculated as input folder size + 10%
dmg(
path: "./fastlane/build/demoMac", # 或./fastlane/build/demoMac/
output_path: "./fastlane/build/demoMac.dmg", # 可选,不写默认为 path.dmg
#volume_name: "demoMac", # 可选,不写默认为demoMac
#filesystem: "hfs+", # 可选, 默认 'hfs+'
#format: "udzo", # 可选,默认 'udzo'
)
~ % cd Desktop/MacDemoDMG
~ % hdiutil create -srcdir "MacDemo"/ -format UDRO "MacDemo.dmg"
......................................................................................................................
created: /Users/用户名/Desktop/MacDemoDMG/MacDemo.dmg
# 工程名
$project_name = "Demo-Test"
# 工程名缩写
$project_abbreviation = "Demo"
# 项目scheme名
$scheme_name = "Demo-Appstore"
default_platform(:ios)
platform :ios do
desc "1.内测版(enterprise)Debug打包并上传服务器(方法四scp方式)"
lane :archive do
#打包的ipa存放路径
outputDir = "./fastlane/build"
#打包的ipa名称
outputName = "#{$project_abbreviation}"
# 1.1 打Debug包
gym(
scheme: "#{$scheme_name}", # 如果有多个Target,需要指定scheme名
workspace: "#{$project_name}.xcworkspace", # 如果项目使用CocoaPods需要加上
clean: true, # 是否编译前clean
configuration: "Debug", # Debug或Release
output_directory: outputDir, # 自定义导出包的Copy目录
output_name: outputName, # 重命名导出包的名字,若指定会生成两个包
include_bitcode: true, # 是否开启bitcode,Xcode默认为true
include_symbols: true, # 是否生成符号表,Xcode默认为true
silent: true, # 是否隐藏部分编译细节
export_xcargs: "-allowProvisioningUpdates", # 启用Xcode自动签名
export_method:"enterprise" # 打包方式(app-store, validation, ad-hoc, package, enterprise, development, developer-id and mac-application)
)
# 1.2 上传1.1的已打包好的包文件(亲测上传方式四可行)
#上传方式一:上传ipa到firim服务器,需要先安装firm插件
#firim(
#firim_api_token: '你在firim网站登录后,点击头像,可以查看API token。复制到这地方'
#)
#上传方式二:上传ipa到蒲公英服务器,需要先安装pgyer插件
#pgyer(
#api_key: "你蒲公英的api_key",
#user_key: "你蒲公英的user_key"",
#update_description: "fix something"
#)
#上传方式三:上传到Ftp服务器
#ftp(
#host: 'ftp.domain.com',
#username: 'your username',
#password: 'your password',
#upload: {
#src: ipa_src,
#dest:"/xxx/"
#}
#)
#上传方式四:上传ipa到公司的服务器,使用SSH key,需要让服务器添加公玥
scp(
host: "xxx.xx.xxx.xxx", # 填写你公司的服务器ip地址
username: "root", # 填写你公司的服务器的用户名
upload: {
src: "./fastlane/build/Demo.ipa", # 1.1中打好的ipa包本机所在地址
dst: "/填写服务器提供的目录/Demo.ipa" # 服务器提供的ipa存放路径
}
)
#上传方式五:上传到testflight
#upload_to_testflight
#上传方式六:上传到appstore
#upload_to_app_store
end
end
# 工程名
$project_name = "Demo-Test"
# 工程名缩写
$project_abbreviation = "Demo"
# 项目scheme名
$scheme_name = "Demo-Appstore"
default_platform(:mac)
platform : mac do
desc "1.Release打包并通过scp方式上传到服务器"
lane :archive do
#打包的.app存放路径
outputDir = "./fastlane/build/#{$project_abbreviation}"
# 1.1 编译打包生成.app包文件
gym(
scheme: "#{$scheme_name}", # 如果有多个Target,需要指定scheme名
workspace: "#{$project_name}.xcworkspace", # 如果项目使用CocoaPods需要加上
clean: true, # 是否编译前clean
configuration: "Release", # Debug或Release
output_directory: outputDir, # 自定义导出包的Copy目录,默认存放outputDir/项目名.app
export_xcargs: "-allowProvisioningUpdates", # 启用Xcode自动签名
export_method:"mac-application" # 打包方式(app-store, validation, ad-hoc, package, enterprise, development, developer-id and mac-application)
)
# 1.2 对1.1中已经打包好的.app进行封装,封装成.dmg。
# 注意mac项目必须封装成dmg,否则直接.app上传到服务器是许多个文件列表。
dmg(
path: outputDir, # required
output_path: "#{outputDir}.dmg", # optional
#filesystem: "hfs+", # optional, default is 'hfs+'
#format: "udzo", # optional, default is 'udzo'
)
# 1.3 上传1.2中已经已经封装好的.dmg文件
scp(
host: "xxx.xx.xxx.xxx", # 填写你公司的服务器ip地址
username: "root", # 填写你公司的服务器的用户名
upload: {
src: "./fastlane/build/Demo.dmg", # 1.1中打好的.dmg包本机所在地址
dst: "/填写服务器提供的目录/Demo.dmg" # 服务器提供的.dmg存放路径
}
)
end
end
~ % cd 项目路径
~ % touch ./fastlane/Fastlane.sh
~ % open ./fastlane/Fastlane.sh
在新建的Fastlane.sh脚本(shell)文件里填写内容如下:
#!/bin/bash
ssh-add #若使用sshkey上传服务器,必须加否则会失败
fastlane archive #打包并上传
~ % cd 项目路径
~ % sh ./fastlane/Fastlane.sh
gym: Easily build and sign your app (via gym)
gym is part of fastlane: The easiest way to automate beta deployments and releases for your iOS and Android apps.
What's gym?
gym builds and packages iOS apps for you. It takes care of all the heavy lifting and makes it super easy to generate a signed ipa or app file ?
1、gym可以帮助你编译和打包安卓和iOSapp,它是fastlane的一部分,其中ios程序打包成.ipa包,mac程序打包成.app包。
2、gym工具只是xcodebuild工具的一个封装,gym使用ruby编写,相对于xcodebuild的写法更简单易用1。
+------+---------------------+-------------+
| fastlane summary |
+------+---------------------+-------------+
| Step | Action | Time (in s) |
+------+---------------------+-------------+
| 1 | Verifying fastlane | 0 |
| | version | |
| 2 | default_platform | 0 |
| ? | gym | 52 |
+------+---------------------+-------------+
[10:09:45]: fastlane finished with errors
[!] Error building the application - see the log above
#######################################################################
# fastlane 2.211.0 is available. You are on 2.209.1.
# You should use the latest version.
# Please update using `gem install fastlane`.
#######################################################################
2.211.0 Improvements
~ % gem install fastlane
Fetching fastlane-2.211.0.gem
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.
sudo gem install fastlane -NV
输入开机密码回车即可
~ % fastlane version
~ % fastlane -v
fastlane installation at path:
/Library/Ruby/Gems/2.6.0/gems/fastlane-2.211.0/bin/fastlane
-----------------------------
[✔] ?
fastlane 2.211.0
我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div
我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看rubyzip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
很好奇,就使用rubyonrails自动化单元测试而言,你们正在做什么?您是否创建了一个脚本来在cron中运行rake作业并将结果邮寄给您?git中的预提交Hook?只是手动调用?我完全理解测试,但想知道在错误发生之前捕获错误的最佳实践是什么。让我们理所当然地认为测试本身是完美无缺的,并且可以正常工作。下一步是什么以确保他们在正确的时间将可能有害的结果传达给您? 最佳答案 不确定您到底想听什么,但是有几个级别的自动代码库控制:在处理某项功能时,您可以使用类似autotest的内容获得关于哪些有效,哪些无效的即时反馈。要确保您的提
假设我做了一个模块如下:m=Module.newdoclassCendend三个问题:除了对m的引用之外,还有什么方法可以访问C和m中的其他内容?我可以在创建匿名模块后为其命名吗(就像我输入“module...”一样)?如何在使用完匿名模块后将其删除,使其定义的常量不再存在? 最佳答案 三个答案:是的,使用ObjectSpace.此代码使c引用你的类(class)C不引用m:c=nilObjectSpace.each_object{|obj|c=objif(Class===objandobj.name=~/::C$/)}当然这取决于
我正在尝试使用ruby和Savon来使用网络服务。测试服务为http://www.webservicex.net/WS/WSDetails.aspx?WSID=9&CATID=2require'rubygems'require'savon'client=Savon::Client.new"http://www.webservicex.net/stockquote.asmx?WSDL"client.get_quotedo|soap|soap.body={:symbol=>"AAPL"}end返回SOAP异常。检查soap信封,在我看来soap请求没有正确的命名空间。任何人都可以建议我
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
我想将html转换为纯文本。不过,我不想只删除标签,我想智能地保留尽可能多的格式。为插入换行符标签,检测段落并格式化它们等。输入非常简单,通常是格式良好的html(不是整个文档,只是一堆内容,通常没有anchor或图像)。我可以将几个正则表达式放在一起,让我达到80%,但我认为可能有一些现有的解决方案更智能。 最佳答案 首先,不要尝试为此使用正则表达式。很有可能你会想出一个脆弱/脆弱的解决方案,它会随着HTML的变化而崩溃,或者很难管理和维护。您可以使用Nokogiri快速解析HTML并提取文本:require'nokogiri'h
我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po