用vapor在本地电脑运行一个服务,请求接口后调用特定脚本执行自动打包的流程.
中间遇到几个问题,在此记录一下
vapor 中执行脚本的代码如下
func shell(_ args: String...) {
let taskQueue = DispatchQueue.global(qos: DispatchQoS.QoSClass.background)
taskQueue.async {
let task = Process()
let path = Config.workingDirectory().appending("Sources/App/FastlaneScript.command")
task.launchPath = path
task.arguments = args
task.launch()
task.waitUntilExit()
print(task.terminationStatus)
}
}
开始一直报错,错误信息如下:
cannot access xxx.command (脚本)
因为开始写的传入脚本路径的方法是这样
let path = Bundle.main.path(forResource: "FastlaneScript.command", ofType:"command")
又是各种百度谷歌,原因是找到了: 在vapor 中不存在Bundle 这用概念,直接用框架封装的Config 类来寻找文件路径;
SO 上答者的原话
That's right. A Bundle is a macOS-specific folder format that wraps a binary executable along with various other resources to represent an application. Vapor, on macOS and on Linux, simply produces the binary executable and therefore has no concept of a Bundle. – tobygriffin
然后用brew 安装 ngrok,做一个反向代理,让服务能在公网直接方法.
ngrok http 5000 # 端口可以按实际情况写,找一个本地空闲的端口即可
执行结果
我直接方法如图的地址,返回一个这个提示:
Failed to complete tunnel connection
The connection to **[http://ce90f0d2.ngrok.io](http://ce90f0d2.ngrok.io/)** was successfully tunneled to your ngrok client, but the client failed to establish a connection to the local address **[localhost:5000](http://localhost:5000/)**.
Make sure that a web service is running on **[localhost:5000](http://localhost:5000/)** and that it is a valid address.
The error encountered was: **dial tcp [::1]:5000: getsockopt: connection refused**
原因: 请求地址,请求连接本地tcp 的 5000 端口,但是这个端口没有监听的socket ,所以请求被拒绝了. 直接把这个地址绑定到vapor 服务上,运行服务,能正常访问就行了.(https 连接还没看,这个的好好看看:[https://ngrok.com/docs])
前奏完成后,开始执行完成真正的目的:
请求接口,出发调用脚本的事件.但是(最tm可怕的就是但是了),又报错了,报错了,报错,报,错....
手动在终端执行 fastlane beta 能正常打包,用脚本执行fastlane beta 就失败了
脚本内容也很简单
#!/bin/sh
echo "*********************************"
echo "Build Started"
echo "*********************************"
echo "*********************************"
echo "Beginning Build Process"
echo "*********************************"
cd "${1}"
pwd
~/.fastlane/bin/fastlane "${2}"
echo "*********************************"
echo "Script End"
echo "*********************************"
Xcode 中打印的错误结果如下
*** ARCHIVED FAILED ***
exit status 65 xxxx
(此处省略一万字,真有一万字.太尼玛长了,没有耐心看完)
这是一个令人头疼的错误,因为暂时还没有找到原因,继续百度谷歌...
知道原因的可以在评论区告知一下,本人不胜感激啊