美文网首页
iOS自动化打包到fir平台

iOS自动化打包到fir平台

作者: 含笑州 | 来源:发表于2020-01-02 11:35 被阅读0次

一、背景

为什么写这篇文章呢,主要是因为之前我们公司都是自动化打包到蒲公英网站的,但是后来蒲公英网站对于一些区块链、金融类的app做了限制,没法上传到他们网站上面,之后考虑到用fir.im网站。

二、方法

1.在项目的根目录下放入一个文件夹,里面包含两个文件,如下图所示

2.DevExportOptions.plist里面配置如下:

左边为你的应用的bundle id,右边为你的provisioning profile的文件名

3.PGYArchive脚本中的内容(本脚本用的是shell脚本)

#!/bin/sh

curDir=$(cd.. $(dirname ${BASH_SOURCE[0]});pwd)

today=`date '+%Y%m%d'`

##############检查plist是否正确

plistPath=`find $curDir -name "*Info-PGY.plist" -type f`

rawStr=`grep -A 1 CFBundleVersion\<\/key\> "$plistPath"`

#echo $rawStr

#获取更新说明

appupdateDescription=`grep -A 1 AppUpdateDescription\<\/key\> "$plistPath"`

update=${appupdateDescription##*<string>}

updateDescription=${update%</string>*}

echo "appupdateDescription is:$updateDescription"

#获取当前版本号

delLeftStr=${rawStr##*<string>}

#echo $delLeftStr

delRightStr=${delLeftStr%</string>*}

echo "Previous build version is:$delRightStr"

#和正确版本号比较

currentDate=`date '+%y%m%d'`

#echo currentDate=$currentDate

plistVersionDate=${delRightStr:0:6}

#echo plistVersionDate=$plistVersionDate

todayVersion=01

#日期是否与今天相等

if[ $currentDate == $plistVersionDate ]

then

#echo date equal

plistTodayVersion=${delRightStr:6}

#echo plistTodayVersion=$plistTodayVersion

if[ ! -n"$plistTodayVersion"]

then

echoplist version not valid 

else

todayVersion=$((${plistTodayVersion}+1))

todayVersion=$(printf%02d $todayVersion)

fi 

else

echodate not equal

fi

finalVersion=$currentDate$todayVersion

echo "Now Build version will be:$finalVersion"

#check用户可见版本号 2.0.0.01

shortVersionRawStr=`grep -A 1 CFBundleShortVersionString\<\/key\> "$plistPath"`

delShortLeftStr=${shortVersionRawStr##*<string>}

delShortRightStr=${delShortLeftStr%</string>*}

echo "Previous Short Version is:$delShortRightStr"

#实现多行注释

:<<!

shortVersionStr=${delShortRightStr:0:7}

shortStableVersionStr=${delShortRightStr:7}

if[ ! -n"$shortStableVersionStr"] ;then

echostable short version not valid 

exit 1

else

todayStableShortVersion=$((${shortStableVersionStr}+1))

fi

finalShortVersion=$shortVersionStr$todayStableShortVersion

echo "Now Short Version will be:$finalShortVersion"

read -t 60 -p "Do you want to continue [Y/N]?" answer

case$answerin

Y | y)

  echo -e "\nFine ,continue"

  ;;

N | n)

  echo -e "\nPlease Enter Current Short Version:" 

      readuserInputFinalShortVersion

  finalShortVersion=${userInputFinalShortVersion}

  ;;

*)

if[ ! -n"$answer"];then

echo -e "\nTimeout ,continue"

else

echo -e "\nerror choice"

finalShortVersion="error"

fi

;;

esac

if["$finalShortVersion"x ="error"x ]  ;then

echoshort version not valid 

exit 1

fi

!

sed -i"""s/$delRightStr/$finalVersion/g""$plistPath"

#sed -i "" "s/$delShortRightStr/$finalShortVersion/g" "$plistPath"

echo "success, build version changed!"

##########检查code signing identity是否正确

projFilePath=`find $curDir -name "xxxx(替换成自己的项目名).xcodeproj" -type d`

#echo projFilePath = $projFilePath

##########检查archive 的build configuration是否正确

projNameTmp=${projFilePath##*\/}

projName=${projNameTmp%.*}

echoprojName=$projName

#####################打包

profFolderPath=${projFilePath%/*}

# echo profFolderPath=$profFolderPath

cd"$profFolderPath"

prodPath="$HOME/Desktop/$projName"_pgy_"$finalVersion"

# echo prodPath=$prodPath

archivePath=$prodPath/target.xcarchive

# echo archivePath=$archivePath

echoxcodebuild clean 

xcodebuild clean -workspace $projName.xcworkspace -configuration'PGY'-scheme $projName

echoxcodebuild archive 

xcodebuild archive -workspace $projName.xcworkspace -scheme $projName -configuration'PGY'-archivePath $archivePath

####################转成ipa

exportOptionsPlistPath=$profFolderPath/AutoArchive/DevExportOptions.plist

#[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" && rvm use system

echoxcodebuild exportArchive 

xcodebuild -exportArchive -archivePath $archivePath/ -exportPath $prodPath -allowProvisioningUpdates  -exportOptionsPlist $exportOptionsPlistPath

#因为fir网站上的key和token有有效期会变,所以需要获取key和token用于上传ipa包

result=$(curl -s "POST" "https://api.fir.im/apps" \

-H "Content-Type: application/json" \

-d "{\"type\":\"ios\", \"bundle_id\":\"xxxx(替换成应用的bundle id)\", \"api_token\":\"xxxx(替换成网站上面的api_token)\"}")

#jq常用命令,感兴趣的可以去研究

key=$(echo$result |jq .cert.binary.key)

Newkey=$(echo$key | sed's/"//g')

token=$(echo$result |jq .cert.binary.token)

Newtoken=$(echo$token | sed's/"//g')

#使用curl自动上传至fir

echo "upload to pgy"

#此方法为上传ipa包

curl -F"file=@$prodPath/xxxx(替换成自己的项目名).ipa"\

-F"key=$Newkey"\

-F"token=$Newtoken"\

-F"x:name=xxxx(替换成自己的应用名)"            \

-F"x:version=$delShortRightStr"        \

-F"x:build=$finalVersion"              \

-F "x:release_type=Adhoc"  \

-F"x:changelog=$updateDescription"      \

https://upload.qbox.me

echo "\n\n"

echo "已运行完毕>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"

exit 0

4.执行PGYArchive脚本即可

5.其他说明

如果导入自己项目中报错了,可能jq命令没有执行,这个可能需要自己手动安装下,具体可以参考我的另外一篇文章进行安装:https://www.jianshu.com/p/a094c07c1fae

如果大家觉得有用的话,欢迎点个赞哦

相关文章

网友评论

      本文标题:iOS自动化打包到fir平台

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