Xcode11打包shell

很久没更新了。来更新一波。shell打包上传到AppStore,用于版本发布或者TestFlight

scheme 是外部传入的参数。
帐号是苹果的帐号,密码要去生成一个app专用密码,不是登陆用的密码。
通过https://itunes.apple.com/lookup接口获取当前商店的版本,然后加1。
需要安装jq解析json,build id直接用的时间戳
第一次运行可能会报xcode-select的问题 一般这样就可以了

sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

下面是代码

#!/bin/bash -l
set -e
cd $(dirname $0)
echo | pwd

#外部传入的scheme
SHCEME=$1
ACCOUNT=xxxxxxxxx
PASSWORD=xxxx-xxxx-xxxx-xxxx

#更新pod
pod install

#workspace
WORKSPACE=xxxx.xcworkspace
TIME_STAMP=`date "+%Y%m%d%H%M%S"`
ArchivePath=JenkinsPackage/${SHCEME}_${TIME_STAMP}.xcarchive
PackagePath=JenkinsPackage/${SHCEME}_${TIME_STAMP}
IPAPATH=$(pwd)/${PackagePath}/${SHCEME}.ipa
EXPORT_OPTIONS=ExportOptions_Release.plist
 
#获取版本号 需要安装jq解析json xxxxx自己的appid
VERSION=$(curl 'https://itunes.apple.com/lookup?id=xxxxxx' | jq '.results[0].version')
VERSION=`echo $VERSION |sed 's/\"//g' | awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{if(length($NF+1)>length($NF))$(NF-1)++; $NF=sprintf("%0*d", length($NF), ($NF+1)%(10^length($NF))); print}'`

echo $SHCEME
echo $VERSION
echo $TIME_STAMP
echo $IPAPATH
#修改版本号
agvtool new-marketing-version ${VERSION}
agvtool new-version -all ${TIME_STAMP}

#archive
xcodebuild archive -workspace ${WORKSPACE} -scheme ${SHCEME} -archivePath ${ArchivePath} -allowProvisioningUpdates
#export
xcodebuild -exportArchive -archivePath ${ArchivePath} -exportPath ${PackagePath} -exportOptionsPlist ${EXPORT_OPTIONS} -allowProvisioningUpdates
#发布至App Store
xcrun altool --validate-app -f ${IPAPATH} -u ${ACCOUNT} -p ${PASSWORD} -t ios --output-format normal
xcrun altool --upload-app -f ${IPAPATH} -u ${ACCOUNT} -p ${PASSWORD} -t ios --output-format normal

export的参数 根据自己需要配置
ExportOptions_Release.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>teamID</key>
    <string>xxxxxxxxx</string>
</dict>
</plist>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容