脚本代码如下 复制下保存在upload.sh文件中
在终端 cd到项目的根目录执行:
len-iMac:~ len$ sh ./upload.sh
注意:
脚本中一些账号和token等相关需要替换成自己的。其他不需要动
ExportOptionsCS.plist于ExportOptionsZS.plist是打包测试与正式环境需要的配置文件,如果不知道,可以先手动打包,导出文件,文件夹中ExportOptions.plist文件就是需要的。和sh文件放在同一目录下就可以了。
#使用方法
#!/bin/bash
#如果当前文件已经在根目录,就不需要下面的 cd ..
cd ..
# firToken
fir_token="*********************"
#AppleID/password
AppleID="***@**.com"
password="****"
#打包模式 Debug/Release
development_mode=Release
#工程绝对路径
project_path=$(cd `dirname $0`; pwd)
#工程名 将XXX替换成自己的工程名
project_name=`find . -name *.xcodeproj | awk -F "[/.]" '{print $(NF-1)}'`
#scheme名 将XXX替换成自己的sheme名
scheme_name=$project_name
nowtime=`date +%Y%m%d%H%M%S`
echo $nowtime
#
Archives_path=~/Library/Developer/Xcode/Archives/`date +%Y-%m-%d`
#build文件夹路径
build_path=${project_path}/build
#导出.ipa文件所在路径
ipa_path=~/Desktop/${project_name}${nowtime}
#导出.ipa文件所在路径
exportIpaPath=${ipa_path}
#plist文件所在路径
exportOptionsPlistPath=${project_path}/${project_name}/ExportOptionsCS.plist
echo "Place enter the number you want to export ? [ 1:app-store 2:ad-hoc] "
##
read number
while([[ $number != 1 ]] && [[ $number != 2 ]])
do
echo "Error! Should enter 1 or 2"
echo "Place enter the number you want to export ? [ 1:app-store 2:ad-hoc] "
read number
done
if [ $number == 1 ];
then
development_mode=Release
exportOptionsPlistPath=${project_path}/${project_name}/ExportOptionsZS.plist
## 证书名字
else
development_mode=Release
exportOptionsPlistPath=${project_path}/${project_name}/ExportOptionsCS.plist
fi
echo '///-----------'
echo '/// 正在清理工程'
echo '///-----------'
#xcodebuild \
#clean -configuration ${development_mode} -quiet || exit
xcodebuild \
clean -workspace ${project_path}/${project_name}.xcworkspace \
-scheme ${scheme_name} \
-configuration ${development_mode}|| exit
echo '///--------'
echo '/// 清理完成'
echo '///--------'
echo ''
echo '///-----------'
echo '/// 正在编译工程:'${development_mode}
echo '///-----------'
#xcodebuild \
#archive -workspace ${project_path}/${project_name}.xcworkspace \
#-scheme ${scheme_name} \
#-configuration ${development_mode} \
#-archivePath ${Archives_path}/${project_name}.xcarchive -quiet || exit
xcodebuild archive -workspace ${project_path}/${project_name}.xcworkspace -scheme ${scheme_name} -archivePath ${Archives_path}/${project_name}${nowtime}.xcarchive -allowProvisioningUpdates -quiet || exit
echo '///--------'
echo '/// 编译完成'
echo '///--------'
echo ''
echo '///----------'
echo '/// 开始ipa打包'
echo '///----------'
echo 'xcodebuild -exportArchive -archivePath '${Archives_path}/${project_name}${nowtime}'.xcarchive \-configuration '${development_mode}' \-exportPath '${exportIpaPath}' \-exportOptionsPlist '${exportOptionsPlistPath}''
xcodebuild -exportArchive -archivePath ${Archives_path}/${project_name}${nowtime}.xcarchive \-configuration ${development_mode} \-exportPath ${exportIpaPath} \-exportOptionsPlist ${exportOptionsPlistPath} \-quiet || exit
#如果报Segmentation fault: 11 错误 执行:rvm system
if [ -e $exportIpaPath/$scheme_name.ipa ];
then
echo '///----------'
echo '/// ipa包已导出'
echo '///----------'
open $exportIpaPath
else
echo '///-------------'
echo '/// ipa包导出失败 '
echo '///-------------'
fi
echo '///------------'
echo '/// 打包ipa完成 '
echo '///-----------='
echo ''
echo '///-------------'
echo '/// 开始发布ipa包 '
echo '///-------------'
if [ $number == 1 ];
then
#验证并上传到App Store
# 将-u 后面的XXX替换成自己的AppleID的账号,-p后面的XXX替换成自己的密码
altoolPath="/Applications/Xcode.app/Contents/Applications/Application Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool"
"$altoolPath" --validate-app -f ${exportIpaPath}/${scheme_name}.ipa -u ${AppleID} -p ${password} -t ios --output-format xml
"$altoolPath" --upload-app -f ${exportIpaPath}/${scheme_name}.ipa -u ${AppleID} -p ${password} -t ios --output-format xml
else
fir login -T $fir_token
fir publish $exportIpaPath/$scheme_name.ipa
# 钉钉机器人提醒
curl 'https://oapi.dingtalk.com/robot/send?access_token=********' \
-H 'Content-Type: application/json' \
-d '{
"actionCard": {
"title": "iOS XXX已更新",
"text": "更新内容",
"hideAvatar": "0",
"btnOrientation": "0",
"btns": [
{
"title": "马上下载",
"actionURL": "https://fir.im/***"
}
]
},
"msgtype": "actionCard"
}'
fi
echo "\n\n"
echo "已运行完毕>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
exit 0
网友评论