美文网首页
使用Automator自动化iOS打包流程

使用Automator自动化iOS打包流程

作者: 我要在河边钓一整天的鱼 | 来源:发表于2017-08-30 21:59 被阅读179次

    一、新建Automator文件

    1、在其他中找到Automator

    1.png

    2、配置所需要的内容

    2.png

    选择没有输入和指定Xcode

    3.png 4.png

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

    5.png

    添加AppleScript

    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

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    
    <plist version="1.0">
    <dict>
        <key>method</key>
        <string>app-store</string>
        <key>teamID</key>
        <string>XXXX</string>
    </dict>
    </plist>
    

    这里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打包流程

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