iOS配置shell脚本自动打包上传到蒲公英


转载请注明出处:
http://blog.csdn.net/bluewindaa/article/details/73650089


前言

在Mac上配置使用脚本进行自动打包,网上搜了好多文章,自己又琢磨了一段时间,总算捣鼓好了,现在写出来总结一下。


准备工作

1.从仓库拉取代码到本地,假设文件夹名为Test (下文提到的文件夹都指该目录)

2.将打包使用到的脚本test.sh文件放入到文件夹中

3.如果是8.3以后的XCode,需从旧的Xcodecopy一份打包时要用到的PackageApplication放到如下目录中:

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/

注:不添加会打包失败,提示

xcrun: error: unable to find utility "PackageApplication", not a developer tool or in PATH

4.然后执行命令

sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer/
chmod +x /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/PackageApplication




PackageApplication下载地址:

链接: https://pan.baidu.com/s/1nuCSmpz 密码: 4gkq


开始

脚本一共分为如下几部分:路径、证书配置;拉取最新代码;打包;导出ipa;上传蒲公英;发送邮件


1.路径、证书配置

echo "\n**********************************************\n"
echo "schemes: Test0 Test1 "
echo "configuration: Debug Release"
echo "\n**********************************************\n"
SCHEMENAME=$1
CONFIGURATION=$2
BRANCHNAME=develop
DATE=`date +%Y%m%d_%H%M`
HOMEPATH=/Users/Cecilia/Desktop
SOURCEPATH=/Users/Cecilia/Desktop/DoubleTeacherMode
IPAPATH=$HOMEPATH/iOS打包/$BRANCHNAME/$DATE
IPANAME=$SCHEMENAME.ipa
Test0AdHocProvisioningProfile="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
Test0ReleaseProvisioningProfile="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
Test0DebugProvisioningProfile="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
Test1AdHocProvisioningProfile="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
Test1ReleaseProvisioningProfile="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
Test1DebugProvisioningProfile="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
Test0ReleaseCodeSignIdentity="iPhone Distribution: xxxxxxxxxxx network technology co., LTD (xxxxxxxxxx)"
Test0DebugCodeSignIdentity="iPhone Developer: xxx (xxxxxxxxxx)"
Test1ReleaseCodeSignIdentity="iPhone Distribution: xxxxxxxxxx technology co., LTD (xxxxxxxxxx)"
Test1DebugCodeSignIdentity="iPhone Developer: xxx (xxxxxxxxxx)"
if [[ $SCHEMENAME == "Test0" && $CONFIGURATION == "Release" ]]; then
	CODE_SIGN_IDENTITY="$doubleTeacherReleaseCodeSignIdentity"
	PROVISIONING_PROFILE="$doubleTeacherAdHocProvisioningProfile"
elif [[ $SCHEMENAME = "Test0" && $CONFIGURATION = "Debug" ]]; then
    CODE_SIGN_IDENTITY="$doubleTeacherDebugCodeSignIdentity"
    PROVISIONING_PROFILE="$doubleTeacherDebugProvisioningProfile"
elif [[ $SCHEMENAME = "Test1" && $CONFIGURATION = "Release" ]]; then
    CODE_SIGN_IDENTITY="$qiFengReleaseCodeSignIdentity"
    PROVISIONING_PROFILE="$qiFengAdHocProvisioningProfile"
elif [[ $SCHEMENAME = "Test1" && $CONFIGURATION = "Debug" ]]; then
    CODE_SIGN_IDENTITY="$qiFengDebugCodeSignIdentity"
    PROVISIONING_PROFILE="$qiFengDebugProvisioningProfile"
fi


2.拉取最新代码

echo "请输入远程电脑密码(输入密码后,按回车即可)"
read macPassword
# git update
git checkout $BRANCHNAME
if [ $? -ne 0 ]; then    
	exit 1
fi
git pull
#pod update --verbose --no-repo-update
if [ $? -ne 0 ]; then    
	 exit 1
fi
# delete trash files
if [ -e $IPAPATH/* ]; then    
	 mv $IPAPATH/* ~/.Trash    
	 if [ $? -ne 0 ]; then        
	  echo "error:Delete trash files failed!"   
		   exit 1   
	 fi
fi


3.打包

xcodebuild \
-workspace $SOURCEPATH/Test0.xcworkspace \
-scheme $SCHEMENAME \
-configuration $CONFIGURATION \
CODE_SIGN_IDENTITY="$CODE_SIGN_IDENTITY" \
PROVISIONING_PROFILE="$PROVISIONING_PROFILE" \
clean \
build \
-derivedDataPath $IPAPATH


4.导出ipa

xcrun -sdk iphoneos PackageApplication \
-v $IPAPATH/Build/Products/$CONFIGURATION-iphoneos/$SCHEMENAME.app \
-o $IPAPATH/$IPANAME


5.上传蒲公英,uKey和_api_key需到蒲公英官网上获取

curl -F "file=@$IPAPATH/$IPANAME" \
-F "uKey=6a988d155c4870d89f23ab16ada511c6" \
-F "_api_key=41b7a601a124634f7accd9454a1914d5" \
https://qiniu-storage.pgyer.com/apiv1/app/upload


6.发送邮件

cd  $IPAPATH
zipName="tempZipName.zip"
zip -r $zipName $IPAPATH/$IPANAME
export LANG=C.UTF-8
#$echo <123> | sudo -S <command>
# 修改大文件限制
echo $macPassword | sudo -S postconf -e message_size_limit=0
postconf -d | grep size
# echo message_size_limit
# 压缩包路径
zipPath=$IPAPATH/$zipName


echo $macPassword | sudo -S postconf -e message_size_limit=0
postconf -d | grep size

emailTitle="有新包啦"
emailBody="新包已经上传\n 请移步https://www.pgyer.com/xxxx 进行安装"
( echo $emailBody; uuencode $zipPath ipa.zip) | mail -s $emailTitle cecilia_900@163.com
echo "\033[36;1m发送邮件成功 \033[0m"


附上完整的脚本文件

#!/bin/bash
# author Cecilia

echo "\n**********************************************\n"
echo "schemes:  Test0   Test1 "
echo "configuration: Debug  Release"
echo "\n**********************************************\n"


SCHEMENAME=$1
CONFIGURATION=$2
BRANCHNAME=develop

DATE=`date +%Y%m%d_%H%M`
HOMEPATH=/Users/Cecilia/Desktop
SOURCEPATH=/Users/Cecilia/Desktop/Test0


IPAPATH=$HOMEPATH/iOS打包/$BRANCHNAME/$DATE
IPANAME=$SCHEMENAME.ipa


Test0AdHocProvisioningProfile="xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx"
Test0ReleaseProvisioningProfile="xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx"
Test0DebugProvisioningProfile="xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx"


qiFengAdHocProvisioningProfile="xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx"
qiFengReleaseProvisioningProfile="xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx"
qiFengDebugProvisioningProfile="xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx"


Test0ReleaseCodeSignIdentity="iPhone Distribution: xxxxxxxxxx network technology co., LTD (xxxxxxxxxx)"
Test0DebugCodeSignIdentity="iPhone Developer: xxx (xxxxxxxxxx)"


qiFengReleaseCodeSignIdentity="iPhone Distribution: xxxxxxxxxx network technology co., LTD (xxxxxxxxxx)"
qiFengDebugCodeSignIdentity="iPhone Developer: xxx (xxxxxxxxxx)"


if [[ $SCHEMENAME == "Test0" && $CONFIGURATION == "Release" ]]; then
    CODE_SIGN_IDENTITY="$Test0ReleaseCodeSignIdentity"
    PROVISIONING_PROFILE="$Test0AdHocProvisioningProfile"
elif [[ $SCHEMENAME = "Test0" && $CONFIGURATION = "Debug" ]]; then
    CODE_SIGN_IDENTITY="$Test0DebugCodeSignIdentity"
    PROVISIONING_PROFILE="$Test0DebugProvisioningProfile"
elif [[ $SCHEMENAME = "Test1" && $CONFIGURATION = "Release" ]]; then
    CODE_SIGN_IDENTITY="$qiFengReleaseCodeSignIdentity"
    PROVISIONING_PROFILE="$qiFengAdHocProvisioningProfile"
elif [[ $SCHEMENAME = "Test1" && $CONFIGURATION = "Debug" ]]; then
    CODE_SIGN_IDENTITY="$qiFengDebugCodeSignIdentity"
    PROVISIONING_PROFILE="$qiFengDebugProvisioningProfile"
fi


echo "请输入远程电脑密码(输入密码后,按回车即可)"
read macPassword

# git update
git checkout $BRANCHNAME
if [ $? -ne 0 ]; then
    exit 1
fi


git pull
#pod update --verbose --no-repo-update
if [ $? -ne 0 ]; then
    exit 1
fi


# delete trash files
if [ -e $IPAPATH/* ]; then
    mv $IPAPATH/* ~/.Trash
    if [ $? -ne 0 ]; then
        echo "error:Delete trash files failed!"
    exit 1
    fi
fi


#build Test0
xcodebuild \
-workspace $SOURCEPATH/Test0.xcworkspace \
-scheme $SCHEMENAME \
-configuration $CONFIGURATION \
CODE_SIGN_IDENTITY="$CODE_SIGN_IDENTITY" \
PROVISIONING_PROFILE="$PROVISIONING_PROFILE" \
clean \
build \
-derivedDataPath $IPAPATH


if [ -e $IPAPATH ]; then
echo "xcodebuild Successful"
else
echo "xcodebuild failed"
exit 1
fi

#xcrun .ipa
xcrun -sdk iphoneos PackageApplication \
-v $IPAPATH/Build/Products/$CONFIGURATION-iphoneos/$SCHEMENAME.app \
-o $IPAPATH/$IPANAME


if [ -e $IPAPATH/$IPANAME ]; then
echo "\n-------------------\n\n\n"
echo "Configurations! Build Successful"
echo "\n\n\n-------------\n\n"
echo "Current Branch log:"
git log -2
open $IPAPATH
else
echo "\n-------------------\n"
echo "error:Create IPA failed"
echo "Please check the cause of failure and contact developers"
echo "\n-------------------\n"
fi



curl -F "file=@$IPAPATH/$IPANAME" \
-F "uKey=6a988d155c4870d89f23ab16ada511c6" \
-F "_api_key=41b7a601a124634f7accd9454a1914d5" \
https://qiniu-storage.pgyer.com/apiv1/app/upload



cho "\n\n\n\n-------------------\n\n\n\n"
echo "\033[36;1m打包总用时: ${SECONDS}s \033[0m"

cd  $IPAPATH
zipName="tempZipName.zip"
zip -r $zipName $IPAPATH/$IPANAME
export LANG=C.UTF-8
#$echo <123> | sudo -S <command>
# 修改大文件限制
echo $macPassword | sudo -S postconf -e message_size_limit=0
postconf -d | grep size
# echo message_size_limit
# 压缩包路径
zipPath=$IPAPATH/$zipName


echo $macPassword | sudo -S postconf -e message_size_limit=0
postconf -d | grep size

emailTitle="有新包啦"
emailBody="新包已经上传\n 请移步https://www.pgyer.com/xxxx 进行安装"
( echo $emailBody; uuencode $zipPath ipa.zip) | mail -s $emailTitle cecilia_900@163.com
echo "\033[36;1m发送邮件成功 \033[0m"


如果使用过程中有什么问题,欢迎留言。
转载请注明出处,谢谢
















评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值