美文网首页
自动打包上传

自动打包上传

作者: 4VZhang | 来源:发表于2018-11-30 16:39 被阅读10次
脚本的使用大大提高工作效率的同时,也满足了项目频繁的打包测试需求!

早些时候,使用shell脚本打包上传到蒲公英分发平台,深知脚本的强大!
前段时间,花了一整天的时间搞出来了一份自动打包上传的shell脚本,在昨晚上线时刻,派上了大用场!虽然和往常一样也熬到了凌晨,但是为修复优化工作争取了可观的开发时间!

#!/bin/sh

#  自动化打包上传.sh
#  Created by FourVZhang on 2018/11.
#  Copyright © 2018年 FourVZhang. All rights reserved.


#上传蒲公英/fir 内测包的描述信息!
updateDescription="自动打包上传测试"

#桌面上用于存放自动打包生成文件的路径
file_upload_path=/Users/FourVZhang/Desktop/AutoBuild/auto-build-upload
#工程绝对路径
project_path=/Users/FourVZhang/xxx_iOS/xxxxxx.xcworkspace
#工程名
project_name=xxxxxx

#打包模式 Debug/Release
development_mode=Debug

#scheme名
scheme_name=xxxxxx

#build文件夹路径
archive_path=${file_upload_path}/archive

#plist 所在路径
exportOptionsPlistPath=${file_upload_path}/exportAppstore.plist

#计时
SECONDS=0

# 如果有,就删除IPA文件夹
if [[ ! -d ${file_upload_path}/IPA ]]; then
mkdir -p ${file_upload_path}/IPA
fi

# 如果有,就删除项目下archive文件夹
if [[ -d ${archive_path} ]]; then
rm -rf ${archive_path} -r
fi



echo '请输入想发布的方式? [1:ad-hoc 2:app-store] '

read number 
    while ([[ $number != 1 ]] && [[ $number != 2 ]]); do
        echo '请输入有效数字 '
        echo '请输入想发布的方式? [1:ad-hoc 2:app-store] '
        read number
    done

    if [[ $number == 1 ]]; then

        development_mode=Debug
        exportOptionsPlistPath=${file_upload_path}/exportAdHoc.plist
        else
        development_mode=Release
        exportOptionsPlistPath=${file_upload_path}/exportAppstore.plist
    fi

#导出.ipa所在路径
exportIPAPath=${file_upload_path}/IPA/${development_mode}


echo '*** 🎉🎉清理工程ing.... **** '
#如果是project使用 -project
#如果是workspace使用 -workspace
xcodebuild \
clean -workspace ${project_path} -scheme ${scheme_name} -configuration ${development_mode} -quiet  || exit

echo '/////////////////////////////////////'
echo '*** 🎉🎉🎉🎉清理完成🎉🎉🎉🎉 **** '
echo '/////////////////////////////////////'

echo '*** 🎉🎉正在编译工程for '${development_mode}
#project  此处用 -project xxx.xcodeproj
#如果是workspace,用 -workspace  xxx.xcworkspace
xcodebuild \
archive -workspace ${project_path} \
-scheme ${scheme_name} \
-configuration ${development_mode} \
-archivePath ${archive_path}/${project_name}.xcarchive \
-quiet || exit
echo '/////////////////////////////////////'
echo '***  🎉🎉🎉🎉🎉编译完成🎉🎉🎉🎉 **** '
echo '/////////////////////////////////////'


echo '*** 🎉🎉正在打包..... ****** '
xcodebuild \
-exportArchive -archivePath ${archive_path}/${project_name}.xcarchive \
-configuration ${development_mode} \
-exportPath ${exportIPAPath} \
-exportOptionsPlist ${exportOptionsPlistPath} \
-quiet || exit

echo '/////////////////////////////////////'
echo '*** 🎉🎉🎉🎉打包完成🎉🎉🎉🎉 ****** '
echo '/////////////////////////////////////'

if [[ -e $exportIPAPath/$scheme_name.ipa ]]; then
    echo '/////////////////////////////////////'
    echo '****  🎉🎉🎉🎉.ipa 文件导出成功,并打开🎉🎉🎉🎉  **** '
    echo '/////////////////////////////////////'
    cd ${exportIPAPath}

else
    echo '***  🎉🎉创建.ipa包失败  ****'

fi



if [[ $number == 2 ]]; then
    echo '***  🎉🎉开始上传ipa包.....  ****'
    #验证并上传到 APP store
    #将 -u 后面的 xxxxx 替换成自己的 apple id 帐号, -p后面的 xxxxx 替换成自己的密码
    altooPath="/Applications/Xcode.app/Contents/Applications/Application Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool"
     #验证app(检验bundle id 以及版本号)
    "$altooPath"    --validate-app \
                    -f ${exportIPAPath}/${scheme_name}.ipa \
                    -u xxxxxx -p xxxxx
     #上传app到appstore
    "$altooPath"    --upload-app  \
                    -f ${exportIPAPath}/${scheme_name}.ipa \
                    -u xxxxxx -p xxxxxx
else
    echo "🎉🎉上传到蒲公英...."
    #蒲公英uesrKey
    pgyerUserKey=xxxxx

    #蒲公英apikey
    pgyerApiKey=xxxxx

    #  上传IPA到蒲公英  file=@$programBag/Payload.ipa
    curl -F "file=@${exportIPAPath}/${scheme_name}.ipa" \
    -F "uKey=$pgyerUserKey" \
    -F "_api_key=$pgyerApiKey" \
    -F "updateDescription=$updateDescription" \
    https://www.pgyer.com/apiv1/app/upload

    echo "****  🎉🎉🎉🎉上传蒲公英成功🎉🎉🎉🎉 *****"
fi
echo "\n\n"
echo ">>>>>>>>>>>>>>>>🎉🎉🎉🎉已运行完毕,耗时${SECONDS}s🎉🎉🎉🎉>>>>>>>>>>>>>>>>>>"
exit 0

如果使用fir可以参考fir平台的文档进行配置即可!
*参考了蒲公英平台的文档和fir平台的文档

altooPath = "/Applications/Xcode.app/Contents/Applications/Application Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool"
引号内的路径是xcode的辅助工具application loader内altool的绝对路径!

application-loader路径.png altool.png

脚本中用到的exportAdhoc.plist文件源码如下:

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>compileBitcode</key>
    <false/>
    <key>method</key>
    <string>ad-hoc</string>
    <key>provisioningProfiles</key>
    <dict>
        <key>bundle id</key>
        <string>项目中adhoc的provisioningProfiles名称</string>
    </dict>
    <key>signingStyle</key>
    <string>manual</string>
    <key>stripSwiftSymbols</key>
    <true/>
    <key>teamID</key>
    <string>ID号</string>
    <key>thinning</key>
    <string>&lt;none&gt;</string>
</dict>
</plist>

脚本中用到的exportAppstore.plist文件源码如下:

<?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>compileBitcode</key>
    <false/>
    <key>method</key>
    <string>app-store</string>
    <key>provisioningProfiles</key>
    <dict>
        <key>bundle id</key>
        <string>项目中appstore的provisioningProfiles名称</string>
    </dict>
    <key>signingStyle</key>
    <string>manual</string>
    <key>stripSwiftSymbols</key>
    <true/>
    <key>teamID</key>
    <string>teamID号</string>
    <key>thinning</key>
    <string>&lt;none&gt;</string>
</dict>
</plist>
file_upload_path.png

相关文章

网友评论

      本文标题:自动打包上传

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