需要自行配置各平台相关参数和plist文件
#---------------------------------------------------------------------------------------------------------------------
#修改环境变量函数
function addressVariableDis()
{
__environmentVariable__='//#define __NET_APPSTORE__'
__filePath__='./xxxx/xxxx/xxxx/TYAPIService.h'
cat ${__filePath__} | while read line;
do
if [ "${line}" == "${__environmentVariable__}" ];
then
echo "changeDis"
sed -i '' 's/\/\/\#define __NET_APPSTORE__/\#define __NET_APPSTORE__/g' ${__filePath__}
fi
done
__filePath__='./xxxx/xxxx/DyConstDefine.h'
cat ${__filePath__} | while read line;
do
if [ "${line}" == $'//#define AppStore' ];
then
echo "changeDis"
sed -i '' 's/\/\/\#define AppStore/\#define AppStore/g' ${__filePath__}
elif [ "${line}" == $'#define Develop' ];
then
echo "changeDis"
sed -i '' 's/\#define Develop/\/\/\#define Develop/g' ${__filePath__}
fi
done
}
#修改环境变量函数
function addressVariableDev()
{
__environmentVariable__='#define __NET_APPSTORE__'
__filePath__='./xxxx/xxxxx/xxxx/TYAPIService.h'
cat ${__filePath__} | while read line;
do
if [ "${line}" == "${__environmentVariable__}" ];
then
echo "changeDis"
sed -i '' 's/\#define __NET_APPSTORE__/\/\/\#define __NET_APPSTORE__/g' ${__filePath__}
elif [ "${line}" == "static NSInteger const K_Server_Status = 0;" ];
then
echo "changeDis"
sed -i '' 's/static NSInteger const K_Server_Status = 0;/static NSInteger const K_Server_Status = 1;/g' ${__filePath__}
fi
done
__filePath__='./xxxx/xxxx/DyConstDefine.h'
cat ${__filePath__} | while read line;
do
if [ "${line}" == $'#define AppStore' ];
then
echo "changeDis"
sed -i '' 's/\#define AppStore/\/\/\#define AppStore/g' ${__filePath__}
elif [ "${line}" == $'//#define Develop' ];
then
echo "changeDis"
sed -i '' 's/\/\/\#define Develop/\#define Develop/g' ${__filePath__}
fi
done
}
function changeDevelopmentEnvironment(){
echo "选择发布环境"
echo "1: dev环境"
echo "2: pro环境"
read isDebug
if [ $isDebug == 1 ];
then
addressVariableDev
elif [ $isDebug == 2 ];
then
addressVariableDis
else
echo "参数无效。。。"
fi
}
#---------------------------------------------------------------------------------------------------------------------
#以下内容需要根据各自电脑和上传平台账号做替换
__MACPASS__="xxxx"
#App Store
APPID="xxxxx"
APPPASSWORD="xxxxx"
#蒲公英上传
__API_KEY="xxxxx"
__USER_KEY="xxxx"
#fir.im 上传
__FIR_Token="xxxxx"
__line__="---------------------------------------"
__SCHEME_NAME="xxxx"
# 获取项目名称
__PROJECT_NAME="xxxx"
#Release或者Debug,默认release ad-hoc
#DeveloperExportOptions.plist AdHocExportOptions.plist
__BUILD_CONFIGURATION="debug"
ExportOptionsPlistPath="DeveloperExportOptions.plist"
# 编译生成文件目录
__EXPORT_PATH="iOSArchivePackage"
# 归档文件路径
__EXPORT_ARCHIVE_PATH="${__EXPORT_PATH}/${__SCHEME_NAME}.xcarchive"
ALTOOLPATH="/Applications/Xcode.app/Contents/Applications/Application Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool"
__EXPORT_IPA_PATH="${__EXPORT_PATH}/output"
#获取钥匙串和打包电脑密码
security unlock-keychain -p ${__MACPASS__} $keychainPath
echo "选择上传平台"
echo "1:蒲公英"
echo "2: fir.im"
echo "3: App Store 构建包"
read parameter
if [ $parameter == 1 ];
then
changeDevelopmentEnvironment
__BUILD_CONFIGURATION="Debug"
ExportOptionsPlistPath="DeveloperExportOptions.plist"
elif [ $parameter == 2 ];
then
changeDevelopmentEnvironment
__BUILD_CONFIGURATION="Debug"
ExportOptionsPlistPath="DeveloperExportOptions.plist"
elif [ $parameter == 3 ];
then
addressVariableDis
__BUILD_CONFIGURATION="Release"
ExportOptionsPlistPath="AppStoreExportOptions.plist"
else
echo "参数无效...."
fi
echo "${__line__} "$parameter" ${__line__}"
echo "${__line__} "$__BUILD_CONFIGURATION" ${__line__}"
echo "${__line__} "$ExportOptionsPlistPath" ${__line__}"
mkdir -p "${__EXPORT_IPA_PATH}"
echo "${__line__} Clean ${__line__}"
/usr/bin/xcodebuild clean -workspace ${__PROJECT_NAME}.xcworkspace \
-scheme ${__SCHEME_NAME} \
-configuration ${__BUILD_CONFIGURATION}
echo "${__line__} 导出archive文件 ${__line__}"
/usr/bin/xcodebuild archive -workspace ${__pwdPath}${__PROJECT_NAME}.xcworkspace -scheme ${__SCHEME_NAME} -configuration ${__BUILD_CONFIGURATION} -archivePath ${__EXPORT_ARCHIVE_PATH}
echo "${__line__} 开始导出ipa文件 ${__line__}"
/usr/bin/xcodebuild -exportArchive -archivePath ${__EXPORT_ARCHIVE_PATH} \
-exportPath ${__EXPORT_IPA_PATH} \
-destination generic/platform=ios \
-exportOptionsPlist ${ExportOptionsPlistPath} \
-allowProvisioningUpdates
if [ $parameter == 1 ];
then
echo "${__line__} 打包到蒲公英 ${__line__}"
MSG=`git log -1 --pretty=%B`
curl -F "file=@${__EXPORT_IPA_PATH}/${__PROJECT_NAME}.ipa" -F uKey=${__USER_KEY} -F _api_key=${__API_KEY} -F "updateDescription=${MSG}" -F installType="2" -F password="123456" https://upload.pgyer.com/apiv1/app/upload
elif [ $parameter == 2 ];
then
echo "${__line__} 打包到Fir.im ${__line__}"
MSG=`git log -1 --pretty=%B`
fir publish "${__EXPORT_IPA_PATH}/${__PROJECT_NAME}.ipa" -c "${MSG}" --password="123456" -Q -T "${__FIR_Token}"
elif [ $parameter == 3 ];
then
echo "${__line__} 上传iTunesConnect验证信息 ${__line__}"
#"${ALTOOLPATH}" --validate-app -f "${__EXPORT_IPA_PATH}/${__PROJECT_NAME}.ipa" -u "${APPID}" -p "${APPPASSWORD}" --output-format xml
# --apiKey --apiIssuer 自行配置
xcrun altool --validate-app -f "${__EXPORT_IPA_PATH}/${__PROJECT_NAME}.ipa" -t ios --apiKey "xxxxxxxxxx" --apiIssuer "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" --verbose
echo "${__line__} 上传iTunesConnect ${__line__}"
#"${ALTOOLPATH}" --upload-app -f "${__EXPORT_IPA_PATH}/${__PROJECT_NAME}.ipa" -u "${APPID}" -p "${APPPASSWORD}" --output-format xml
xcrun altool --upload-app -f "${__EXPORT_IPA_PATH}/${__PROJECT_NAME}.ipa" -t ios --apiKey "xxxxxxxxxx" --apiIssuer "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" --verbose
else
echo "参数无效...."
fi
网友评论