#!/usr/bin/env bash# name: adminecho "~~~~~~~~~~~~~~~~開始執行指令碼~~~~~~~~~~~~~~~~"#開始時間beginTime=`date +%s`DATE=`date '+%Y-%m-%d-%T'`#需要編譯的 targetNameTARGET_NAME="WheatMoneyManagement"#編譯模式 工程預設有 Debug ReleaseCONFIGURATION_TARGET=Release#編譯路徑BUILDPATH=/opt/demo/build/${TARGET_NAME}_${DATE}#archivePathARCHIVEPATH=${BUILDPATH}/${TARGET_NAME}.xcarchive#輸出的ipa目錄IPAPATH=/Users/admin/Desktop#匯出ipa 所需plistADHOCExportOptionsPlist=${ARCHIVEPATH}/Info.plistExportOptionsPlist=${ADHOCExportOptionsPlist}# 是否上傳蒲公英UPLOADPGYER=true# git項目分支號breach=v2.0.0git clone -b $breach 項目git地址echo "~~~~~~~~~~~~~~~~開始構建~~~~~~~~~~~~~~~~~~~"#開始構建xcodebuild archive -workspace ${TARGET_NAME}.xcworkspace \-scheme ${TARGET_NAME} \-archivePath ${ARCHIVEPATH} \-configuration ${CONFIGURATION_TARGET}echo "~~~~~~~~~~~~~~~~檢查是否構建成功~~~~~~~~~~~~~~~~~~~"# xcarchive 實際是一個檔案夾不是一個檔案所以使用 -d 判斷if [ -d "$ARCHIVEPATH" ]thenecho "構建成功......"elseecho "構建失敗......"rm -rf $BUILDPATHexit 1fiendTime=`date +%s`ArchiveTime="構建時間$[ endTime - beginTime ]秒"echo "~~~~~~~~~~~~~~~~匯出ipa~~~~~~~~~~~~~~~~~~~"beginTime=`date +%s`xcodebuild -exportArchive \-archivePath ${ARCHIVEPATH} \-exportOptionsPlist ${ExportOptionsPlist} \-exportPath ${IPAPATH}echo "~~~~~~~~~~~~~~~~檢查是否成功匯出ipa~~~~~~~~~~~~~~~~~~~"IPAPATH=${IPAPATH}/${TARGET_NAME}.ipaif [ -f "$IPAPATH" ]thenecho "匯出ipa成功......"elseecho "匯出ipa失敗......"# 結束時間endTime=`date +%s`echo "$ArchiveTime"echo "匯出ipa時間$[ endTime - beginTime ]秒"exit 1fiendTime=`date +%s`ExportTime="匯出ipa時間$[ endTime - beginTime ]秒" # 上傳蒲公英if [ $UPLOADPGYER = true ]; then echo "~~~~~~~~~~~~~~~~上傳ipa到蒲公英~~~~~~~~~~~~~~~~~~~" curl -F "file=@$IPAPATH" \ -F "uKey=9c86dd6f*******d7d784e841d91" \ -F "_api_key=220fd5e840f******bdb80e2e80" \ -F "password=蒲公英密碼" \ https://www.pgyer.com/apiv1/app/upload if [ $? = 0 ] thenecho -e "\n" echo "~~~~~~~~~~~~~~~~上傳蒲公英成功~~~~~~~~~~~~~~~~~~~" elseecho -e "\n" echo "~~~~~~~~~~~~~~~~上傳蒲公英失敗~~~~~~~~~~~~~~~~~~~" fifiecho "~~~~~~~~~~~~~~~~配置資訊~~~~~~~~~~~~~~~~~~~"echo "開始執行指令碼時間: ${DATE}"echo "編譯模式: ${CONFIGURATION_TARGET}"echo "匯出ipa配置: ${ExportOptionsPlist}"echo "打包檔案路徑: ${ARCHIVEPATH}"echo "匯出ipa路徑: ${IPAPATH}"echo "$ArchiveTime"echo "$ExportTime"exit 1