美文网首页iOS 进阶
iOS自动化打包并上传蒲公英和fir.im

iOS自动化打包并上传蒲公英和fir.im

作者: 190CM | 来源:发表于2018-04-10 17:28 被阅读147次

一、执行xcodebuild需要指定你所需要对应的workspace和scheme

xcodebuild -workspace /Users/dingxiankun/Desktop/XXX/XXX.xcworkspace -scheme XXX

二、XCode8.3以下直接看下一步

XCode8.3以上直接执行会报错
xcrun: error: unable to find utility "PackageApplication", not a developer tool or in PATH

https://pan.baidu.com/s/1jHJF2Lo

放到下面这个目录:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/

然后执行命令:
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer/
chmod +x /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/PackageApplication

三、执行脚本

项目如果未使用Git,可直接注掉相关代码即可

#!/bin/bash

SCHEMENAME=XXX
BRANCHNAME=develop

DATE=`date +%Y%m%d_%H%M`
SOURCEPATH=$( cd "$( dirname $0 )" && pwd )
IPAPATH=$SOURCEPATH/AutoBuildIPA/$BRANCHNAME/$DATE
IPANAME=$SCHEMENAME_$DATE.ipa

# 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 XXX
xcodebuild \
-workspace $SOURCEPATH/$SCHEMENAME.xcworkspace \
-scheme $SCHEMENAME \
-configuration Debug \
clean \
build \
-derivedDataPath $IPAPATH

if [ -e $IPAPATH ]; then
    echo "xcodebuild successful"
else 
    echo "error:Build failed!!"
    exit 1
fi

# xcrun .ipa 
xcrun -sdk iphoneos PackageApplication \
        -v $IPAPATH/Build/Products/Debug-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 "\n Please check the cause of failure and contact developers, thanks!\n"
    echo "\n---------------------------------------\n"  
fi

UPLOADPATH=$IPAPATH/$IPANAME

# fir.im
# fir login -T e5fe0ee4xxxxxxx327xxx       # fir.im token
# fir publish $UPLOADPATH  

# pgyer
PGYUKEY=827b865a5cdexxxxxx10558491f8
PGYAPIKEY=c1f9bb4cc7xxxxxxxx5f0a1524a89

curl -F "file=@"${UPLOADPATH} \
-F "uKey="${PGYUKEY} \
-F "_api_key="${PGYAPIKEY} \
https://www.pgyer.com/apiv1/app/upload

四、上传成功

蒲公英success示例
{
    "code": 0,
    "message": "",
    "data": {
        // 成功信息
    }
}

相关文章

网友评论

    本文标题:iOS自动化打包并上传蒲公英和fir.im

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