#!/bin/bash
# 不需要git验证
git config --global http.sslVerify false
# 编码处理
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
# 安装fastlane
# https://docs.fastlane.tools/getting-started/ios/setup/
# sudo gem install fastlane -NV
# brew cask install fastlane
# 初始化
# fastlane init (OC)
# fastlane init swift (Swift)
# 更新私有库
# pod repo update XXXSpec
# 更新公有库
# pod update
# pod update --verbose --no-repo-update
# 颜色
RedColor='\033[31m'
GreenColor='\033[32m'
YellowColor='\033[33m'
DefaultColor='\033[0m'
export_method_type="development"
build_type="Debug"
echo -e "--------------------------------------------------------------------------------"
echo -e "Please enter the number you want to export ? [ ${RedColor}1:app-store ${GreenColor}2:ad-hoc ${YellowColor}3:develop ] ${DefaultColor}"
echo -e "--------------------------------------------------------------------------------"
read number
# while [[ $number != 1 -a $number != 2 -a $number != 3 ]]; do
while [[ $number != 1 ]] && [[ $number != 2 ]] && [[ $number != 3 ]]; do
echo -e "${RedColor}Error! Should enter 1 or 2 or 3${DefaultColor}"
echo -e "Please enter the number you want to export ? [ ${RedColor}1:app-store ${GreenColor}2:ad-hoc ${YellowColor}3:develop ] ${DefaultColor}"
read number
done
if [[ $number == 1 ]]; then
export_method_type="app-store"
build_type=Release
elif [[ $number == 2 ]]; then
export_method_type="ad-hoc"
build_type=Release
elif [[ $number == 3 ]]; then
export_method_type="development"
build_type=Debug
fi
cd ../
# 工程绝对路径
pro_path=$(cd "$(dirname "$0")"; pwd)
# 打包环境模式 (可以变更) app-store, ad-hoc, development, enterprise
# export_method_type="development"
# Scheme名 (可以变更)
pro_scheme="XXX"
# 编译模式 (可以变更) Release, Debug
# build_type="Debug"
ipa_name="${pro_scheme}_$(date +%m%d_%H%M)"
# IPA文件路径
ipa_path="${pro_path}/Archive/IPAFile/${pro_scheme}_${build_type}_${export_method_type}/"
# 打包日志路径
log_path="${pro_path}/Archive/LogFile/Log_$(date +%m%d_%H%M).txt"
mkdir -p "Archive/LogFile"
# 上传发布日志路径
up_log_path="${pro_path}/Archive/UpLogFile/Log_$(date +%m%d_%H%M).txt"
mkdir -p "Archive/UpLogFile"
echo -e "1.正在清理工程..."
xcodebuild clean
# xcodebuild clean -workspace $pro_workspace -scheme $pro_scheme -quiet || exit
# xcodebuild clean -workspace $pro_workspace -scheme $pro_scheme -configuration $build_type -quiet || exit
rm -rf ~/Library/Developer/Xcode/Archives
rm -rf ~/Library/Developer/Xcode/Products
# rm -rf Archive/IPAFile
# rm -rf Archive/LogFile
# rm -rf Archive/UpLogFile
# fastlane gym --workspace "Example.xcworkspace" --scheme "AppName" --clean
echo -e "2.正在编译工程和导出ipa..."
# DEVELOPER_DIR="/Applications/Xcode.app"
# fastlane gym --export_method ${export_method_type} \
# --scheme ${pro_scheme} \
# --configuration ${build_type} \
# --output_name ${ipa_name} \
# --output_directory ${ipa_path} \
# --clean true \
# --verbose
log_str=$(fastlane gym --export_method ${export_method_type} \
--scheme ${pro_scheme} \
--configuration ${build_type} \
--output_name ${ipa_name} \
--output_directory ${ipa_path} \
--clean true \
--verbose)
echo -e "${log_str}" > ${log_path}
if [[ -e "${ipa_path}/${ipa_name}.ipa" ]]; then
echo -e "3.ipa包导出成功"
else
echo -e "3.${RedColor}ipa包导出失败${DefaultColor}"
exit 0
fi
# 打开路径
open ${ipa_path}
echo -e "4.开始上传到 蒲公英..."
# curl -F "file=@${ipa_path}/${ipa_name}.ipa" \
# -F "_api_key=xxx" \
# -F "buildInstallType=2" \
# -F "buildPassword=xxx" \
# https://www.pgyer.com/apiv2/app/upload
# 添加上传日志
upload_str=$(curl -F "file=@${ipa_path}/${ipa_name}.ipa" \
-F "_api_key=xxx" \
-F "buildInstallType=2" \
-F "buildPassword=xxx" \
https://www.pgyer.com/apiv2/app/upload)
echo -e "${upload_str}" > ${up_log_path}
# 复制本地文件到服务器
# cd ${ipa_path}
# scp -r ${ipa_name}.ipa root@server