使用Automator自动化iOS打包流程

一、新建Automator文件

1、在其他中找到Automator

使用Automator自动化iOS打包流程_第1张图片
1.png

2、配置所需要的内容

使用Automator自动化iOS打包流程_第2张图片
2.png

选择没有输入和指定Xcode

使用Automator自动化iOS打包流程_第3张图片
3.png
使用Automator自动化iOS打包流程_第4张图片
4.png

添加变量Destination Path,双击红圈指定到工程所在的目录

使用Automator自动化iOS打包流程_第5张图片
5.png

添加AppleScript

使用Automator自动化iOS打包流程_第6张图片
6.png

3、script中的内容

on run {input, parameters}
    
    tell application "Terminal"
        activate
        do script "cd " & input & " && . BuildScript-AppStore/xcodeArchive.sh"
    end tell
    
    return input
end run

到这Automator的配置就结束了。

二、iOS脚本自动化打包

在上一篇文章中说过动态环境的配置 传送门

将BuildScript-AppStore文件夹放在xcodeproj平级的文件夹下

1、客官先看脚本

#!/bin/sh
#

#rvm system

function failed() {
    echo "Failed: $@" >&2
    exit 1
}

archiveName="XXXX"
projectName="XXXX"
scheme="XXXXX"
configuration="XXXX"
exportOptionsPlist="BuildScript-AppStore/exportOptions.plist"
ipaPath="$PWD/build/${archiveName}/${scheme}.ipa"
appleid="XXX"
applepassword="XXX"

#build clean
xcodebuild clean -project ${projectName} \
                 -configuration ${configuration} \
                 -alltargets || failed "clean error"



#archive
xcodebuild archive -project ${projectName} \
                    -configuration ${configuration} \
                    -scheme ${scheme} \
                    -destination generic/platform=iOS \
                    -archivePath $PWD/build/${archiveName}.xcarchive || failed "archive error"




#Export Complete
xcodebuild -exportArchive -archivePath $PWD/build/${archiveName}.xcarchive \
            -exportOptionsPlist ${exportOptionsPlist} \
            -exportPath ${buildPath}/appStorebuild/${archiveName} \
            -verbose || failed "export error"

#发布到iTunesConnect
altoolPath="/Applications/Xcode.app/Contents/Applications/Application Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool"

#validate
"${altoolPath}" --validate-app -f ${ipaPath} -u "$appleid" -p "$applepassword" -t ios --output-format xml || failed "validate error"

#upload
"${altoolPath}" --upload-app -f ${ipaPath} -u "$appleid" -p "$applepassword" -t ios --output-format xml || failed "upload error"

2、参数说明

archiveName 看你心情写一个名字

projectName 你的xcodeproj名字

在工程根目录下执行 xcodebuild -list可以看到你可以设置的 scheme和 configuration 这两个参数就是上次动态环境配置的scheme 和 Build Configuration

exportOptionsPlist 是配置在打包中的参数,method根据你的需要可以设置为app-store, package, ad-hoc, enterprise, development, and developer-id






    method
    app-store
    teamID
    XXXX


这里plist文件和脚本文件都在BuildScript-AppStore文件内

3.上述脚本是在提交到App Store中的平常在测试中一般放在fir或者蒲公英上

上传蒲公英 【蒲公英官方文档】

curl -F "file=@${ipaPath}" \
     -F "uKey=XXXX" \
     -F "_api_key=XXXXXX" \
     -F "updateDescription=版本描述" \
    https://www.pgyer.com/apiv1/app/upload || failed "提交蒲公英失败"

谢谢观赏

你可能感兴趣的:(使用Automator自动化iOS打包流程)