美文网首页iOS开发点滴
脚本快速上传“蒲公英”,分发测试:

脚本快速上传“蒲公英”,分发测试:

作者: 阳光下的叶子呵 | 来源:发表于2022-08-21 14:45 被阅读0次

创建一个.sh类型的脚本,放在项目的根目录就可以,在命令行当前项目文件下 输入,shell.sh点击确定,再输入2点击确定(“2”代表打包上传到第二个平台,即:上传到蒲公英)
(其中包含打包到App Store)

使用:命令行
// 到达项目目录”➜  WeatherAPP git:(v1.0.0) “,然后输入:
sh shell.sh
// 点击确定之后,会出现下边这行:
你想要干到那个平台 ? [ 1:app-store 2:ad-hoc_蒲公英]
// 上传到App Store 选择输入 1,”蒲公英分发平台“ 选择输入 2,
2
注意:if 和 fi 成对出现

当前的shell.sh:(蒲公英 API 2.0) 最新版


#全文搜索【CYC666改】,就是要改的地方

if [ ! -d ./IPADir ];
then
mkdir -p IPADir;
fi

#工程绝对路径
project_path=$(cd `dirname $0`; pwd)

#工程名 将***替换成自己的工程名【CYC666改】
project_name=***

#scheme名 将***替换成自己的sheme名(一般和工程名一样)【CYC666改】
scheme_name=***

#打包模式 Debug/Release
development_mode=Debug

#build文件夹路径
build_path=${project_path}/build

#plist文件所在路径
exportOptionsPlistPath=${project_path}/exportTest.plist

#导出.ipa文件所在路径
exportIpaPath=${project_path}/IPADir/${development_mode}


echo "你想要干到那个平台 ? [ 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}/exportAppstore.plist
else
development_mode=Debug
exportOptionsPlistPath=${project_path}/exportTest.plist
fi



echo '---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'
echo '----------------------------------正在清理工程-----------------------------------'
echo '---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'

xcodebuild \
clean -configuration ${development_mode} -quiet  || 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 ${build_path}/${project_name}.xcarchive  -quiet  || exit


echo '---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'
echo '-----------------------------------编译完成-------------------------------------'
echo '---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'


echo '---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'
echo '----------------------------------开始ipa打包-----------------------------------'
echo '---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'

xcodebuild -exportArchive -archivePath ${build_path}/${project_name}.xcarchive \
-configuration ${development_mode} \
-exportPath ${exportIpaPath} \
-allowProvisioningUpdates YES \
-exportOptionsPlist ${exportOptionsPlistPath} \
-quiet || exit

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 '----------------------------------开始发布ipa包----------------------------------'
echo '---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'

# 当您的结构不匹配时,通常会发生此错误 - 也就是说,您没有匹配的双引号,匹配的单引号,没有关闭控制结构,例如缺少fi一个if,或缺少done一个for。
# 注意:if 和 fi 成对出现
if [ $number == 1 ];then

#验证并上传到App Store
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 mayongcsb@163.com -p Banyunbang012 -t ios --output-format xml
"$altoolPath" --upload-app -f ${exportIpaPath}/${scheme_name}.ipa -u  mayongcsb@163.com -p Banyunbang012 -t ios --output-format xml

    #statements

else
echo '---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'
echo '---------------------------------开始上传蒲公英---------------------------------'
echo '---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'
#以上 (上面那些打包.ipa包、上传App Store)是复制的之前的shell.sh文件的

# 最新的 上传 蒲公英 API 2.0方法:
#!/bin/bash
#
# 通过shell脚本来实现将本地app文件通过API上传到蒲公英
# https://www.pgyer.com/doc/view/api#fastUploadApp
##
# 参数说明:
# $1: api_key  即:蒲公英api_key
# $2: file  即:要上传的文件路径(ipa/apk)
#

readonly api_key="你的蒲公英api_key"
readonly file="${exportIpaPath}/${scheme_name}.ipa"

printHelp() {
#    echo "Usage: $0 api_key file"
#    echo "Example: $0 <your_api_key> <your_apk_or_ipa_path>"
        echo "Usage: $file"
        echo "Example: $0 <api_key> <file>"
}

# check api_key exists
if [ -z "$api_key" ]; then
    echo "api_key is empty" #api_key 是空的(即,没有这个api_key)
    printHelp
    exit 1
fi

# check file exists
if [ ! -f "$file" ]; then
    echo "file not exists"
    printHelp
    exit 1
fi

if [[ $file =~ ipa$ ]]; then
    app_type="ios"
elif [[ $file =~ apk$ ]]; then
    app_type="android"
else
    echo "file type not support"
    printHelp
    exit 1
fi

# ---------------------------------------------------------------
# functions
# ---------------------------------------------------------------

log() {
    echo "[$(date +'%Y-%m-%d %H:%M:%S')] $*"
}

logTitle() {
    log "-------------------------------- $* --------------------------------"
}

execCommand() {
    log "$@"
    result=$(eval $@)
}

# ---------------------------------------------------------------
# 获取上传凭证
# ---------------------------------------------------------------

logTitle "获取凭证"

execCommand "curl -s -F '_api_key=${api_key}' -F 'buildType=${app_type}' http://www.pgyer.com/apiv2/app/getCOSToken"

[[ "${result}" =~ \"endpoint\":\"([\:\_\.\/\\A-Za-z0-9\-]+)\" ]] && endpoint=`echo ${BASH_REMATCH[1]} | sed 's!\\\/!/!g'`
[[ "${result}" =~ \"key\":\"([\.a-z0-9]+)\" ]] && key=`echo ${BASH_REMATCH[1]}`
[[ "${result}" =~ \"signature\":\"([\=\&\_\;A-Za-z0-9\-]+)\" ]] && signature=`echo ${BASH_REMATCH[1]}`
[[ "${result}" =~ \"x-cos-security-token\":\"([\_A-Za-z0-9\-]+)\" ]] && x_cos_security_token=`echo ${BASH_REMATCH[1]}`

if [ -z "$key" ] || [ -z "$signature" ] || [ -z "$x_cos_security_token" ] || [ -z "$endpoint" ]; then
    log "get upload token failed"
    exit 1
fi

# ---------------------------------------------------------------
# 上传文件
# ---------------------------------------------------------------

logTitle "上传文件"

execCommand "curl -s -o /dev/null -w '%{http_code}' --form-string 'key=${key}' --form-string 'signature=${signature}' --form-string 'x-cos-security-token=${x_cos_security_token}' -F 'file=@${file}' ${endpoint}"
if [ $result -ne 204 ]; then
    log "Upload failed"
    exit 1
fi

# ---------------------------------------------------------------
# 检查结果
# ---------------------------------------------------------------

logTitle "检查结果"

for i in {1..60}; do
    execCommand "curl -s http://www.pgyer.com/apiv2/app/buildInfo?_api_key=${api_key}\&buildKey=${key}"
    [[ "${result}" =~ \"code\":([0-9]+) ]] && code=`echo ${BASH_REMATCH[1]}`
    if [ $code -eq 0 ]; then
        log $result
        break
    else
        sleep 1
    fi
done

fi

echo '---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'
echo '------------------------------------上传完成------------------------------------'
echo '---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'

exit 0


之前的shell.sh:(蒲公英API 1.0 即将废弃)

#全文搜索【CYC666改】,就是要改的地方

if [ ! -d ./IPADir ];
then
mkdir -p IPADir;
fi

#工程绝对路径
project_path=$(cd `dirname $0`; pwd)

#工程名 将***替换成自己的工程名【CYC666改】
project_name=***

#scheme名 将***替换成自己的sheme名【CYC666改】
scheme_name=***

#打包模式 Debug/Release
development_mode=Debug

#build文件夹路径
build_path=${project_path}/build

#plist文件所在路径
exportOptionsPlistPath=${project_path}/exportTest.plist

#导出.ipa文件所在路径
exportIpaPath=${project_path}/IPADir/${development_mode}


echo "你想要干到那个平台 ? [ 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}/exportAppstore.plist
else
development_mode=Debug
exportOptionsPlistPath=${project_path}/exportTest.plist
fi



echo '---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'
echo '----------------------------------正在清理工程-----------------------------------'
echo '---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'

xcodebuild \
clean -configuration ${development_mode} -quiet  || 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 ${build_path}/${project_name}.xcarchive  -quiet  || exit


echo '---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'
echo '-----------------------------------编译完成-------------------------------------'
echo '---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'


echo '---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'
echo '----------------------------------开始ipa打包-----------------------------------'
echo '---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'

xcodebuild -exportArchive -archivePath ${build_path}/${project_name}.xcarchive \
-configuration ${development_mode} \
-exportPath ${exportIpaPath} \
-allowProvisioningUpdates YES \
-exportOptionsPlist ${exportOptionsPlistPath} \
-quiet || exit

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 '----------------------------------开始发布ipa包----------------------------------'
echo '---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'

if [ $number == 1 ];then

#验证并上传到App Store
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 mayongcsb@163.com -p Banyunbang012 -t ios --output-format xml
"$altoolPath" --upload-app -f ${exportIpaPath}/${scheme_name}.ipa -u  mayongcsb@163.com -p Banyunbang012 -t ios --output-format xml

    #statements

else
echo '---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'
echo '---------------------------------开始上传蒲公英---------------------------------'
echo '---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'

# #echo "+++++上传到Fir平台+++++"
# # 将XXX替换成自己的Fir平台的token
# fir login -T ebf621981572235f7df35a2
# fir publish $exportIpaPath/$scheme_name.ipa


#上传到蒲公英
#将XXX替换成自己蒲公英上的User Key
uKey="你的uKey"
#将XXX替换成自己蒲公英上的API Key
apiKey="你的apiKey"
#执行上传至蒲公英的命令
echo "+++++上传到蒲公英平台+++++"

# 上传App(即将废弃)
curl -F "file=@${exportIpaPath}/${scheme_name}.ipa" -F "uKey=${uKey}" -F "_api_key=${apiKey}" http://www.pgyer.com/apiv1/app/upload


fi

echo '---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'
echo '------------------------------------上传完成------------------------------------'
echo '---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'

exit 0



相关文章

网友评论

    本文标题:脚本快速上传“蒲公英”,分发测试:

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