Created
June 16, 2015 07:20
自动打包并上传到Fir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# init build configuration | |
# archive and ipa output path | |
build_path="./build" | |
# if file not exist , create it | |
if [ ! -x "$build_path" ]; then | |
mkdir "$build_path" | |
fi | |
# workspace name | |
build_workspace="HomeInn.xcworkspace" | |
# project name and path | |
project_path=$(pwd) | |
project_name=$(ls | grep xcodeproj | awk -F.xcodeproj '{print $1}') | |
# provisiong profile name | |
provisioningProfile='"aep_incommonuse"' | |
# timestamp for ouput file name | |
timeStamp="$(date +"%Y%m%d_%H%M%S")" | |
echo "$project_path/$build_workspace" | |
if [ ! -d "$project_path/$build_workspace" ]; then | |
echo "Error!Current path is not a xcode workspace.Please check, or do not use -w option." | |
exit 2 | |
fi | |
# get the info.plist | |
app_infoplist_path=${project_path}/${project_name}/${project_name}-Info.plist | |
echo ${app_infoplist_path} | |
# get the main version | |
bundleShortVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleShortVersionString" "${app_infoplist_path}") | |
# get the build version | |
bundleVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleVersion" "${app_infoplist_path}") | |
# get the svn revision | |
svn_revision=$(svn info |grep Revision: |awk '{print $2}') | |
#`svnversion -c |sed 's/^.*://' |sed 's/[A-Z]*$//'` | |
#svn info |grep Revision: |awk '{print $2}' | |
#workspace_name='*.xcworkspace' | |
#ls $project_path/$build_workspace &>/dev/null | |
#rtnValue=$? | |
#if [ !$rtnValue = 0 ];then | |
# #build_workspace=$(echo $(basename $project_path/$workspace_name)) | |
# echo "Error!Current path is not a xcode workspace.Please check, or do not use -w option." | |
# exit 2 | |
#fi | |
# scheme name | |
build_scheme="HomeInn" | |
# buidl config. the default is Debug|Release | |
build_config="Release" | |
# clean build | |
clean_cmd='xcodebuild' | |
clean_cmd=${clean_cmd}' clean -workspace '${build_workspace}' -scheme '${build_scheme}' -configuration '${build_config} | |
$clean_cmd > $build_path/clean_qa.txt || exit | |
# build & archive, generate the archive file | |
archive_name="${timeStamp}.xcarchive" | |
archive_path="./build/"$archive_name | |
build_cmd='xcodebuild' | |
build_cmd=${build_cmd}' -workspace '${build_workspace}' -scheme '${build_scheme}' -destination generic/platform=iOS archive -configuration '${build_config}' ONLY_ACTIVE_ARCH=NO -archivePath '${archive_path} | |
echo "** Archiving QA ** to the ${archive_path}" | |
echo ${build_cmd} | |
$build_cmd > ./build/build_archive_qa.log || exit | |
if [ ! -d "${archive_path}" ]; then | |
echo "** Error! ARCHIVE QA FAILED ** Please check ./build/build_archive_qa.log." | |
exit 2 | |
else | |
echo "** ARCHIVE QA SUCCEEDED ** to the ${archive_path}" | |
fi | |
# export to ipa with QA server | |
ipa_name="${bundleShortVersion}_b${bundleVersion}_rev${svn_revision}_t${timeStamp}.ipa" | |
ipa_path="./build/"$ipa_name | |
ipa_cmd='xcodebuild' | |
ipa_cmd=${ipa_cmd}' -exportArchive -exportFormat ipa -archivePath '${archive_path}' -exportPath '${ipa_path}' -exportProvisioningProfile '${provisioningProfile} | |
echo "** Exporting QA ** to the ${ipa_path}" | |
echo ${ipa_cmd} | |
eval ${ipa_cmd} > ./build/export_ipa_qa.log || exit | |
if [ ! -f "${ipa_path}" ]; then | |
echo "** Error! Export IPA QA FAILED ** Please check ./build/export_ipa_qa.log." | |
exit 2 | |
else | |
echo "** Export IPA QA SUCCEEDED ** to the ${ipa_path}" | |
echo "** Now Upload to Fir **" | |
cd build | |
USER_TOKEN="" | |
APP_ID="" | |
echo "getting token" | |
INFO=`curl http://fir.im/api/v2/app/info/${APP_ID}?token=${USER_TOKEN} 2>/dev/null` | |
KEY=$(echo ${INFO} | grep "pkg.*url" -o | grep "key.*$" -o | awk -F '"' '{print $3;}') | |
TOKEN=$(echo ${INFO} | grep "pkg.*url" -o | grep "token.*$" -o | awk -F '"' '{print $3;}') | |
#echo key ${KEY} | |
#echo token ${TOKEN} | |
echo "uploading" | |
APP_INFO=`curl -# -F file=@${ipa_name} -F "key=${KEY}" -F "token=${TOKEN}" http://up.qiniu.com` | |
if [ $? != 0 ] | |
then | |
echo "upload error" | |
exit 1 | |
fi | |
APPOID=`echo ${APP_INFO} | grep "appOid.*," -o | awk -F '"' '{print $3;}'` | |
#echo ${APP_INFO} | |
#echo ${APPOID} | |
# when upload success , update version info | |
echo "updating version info" | |
curl -X PUT -d changelog="update version" http://fir.im/api/v2/app/${APPOID}?token=${USER_TOKEN} | |
# you can change version or other info by params | |
# curl -X PUT -d changelog="update version" -d "version=${bundleVersion}" -d "versionShort=${bundleShortVersion}" http://fir.im/api/v2/app/${APPOID}?token=${USER_TOKEN} | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment