Skip to content

Instantly share code, notes, and snippets.

@qoli
Created April 21, 2022 03:11
Show Gist options
  • Save qoli/256906f5dc10c66be129e1bf9c4784dc to your computer and use it in GitHub Desktop.
Save qoli/256906f5dc10c66be129e1bf9c4784dc to your computer and use it in GitHub Desktop.
exportAll.sh
#!/bin/zsh
function buildTest() {
clear
cp -rf ./lib/common/config_test.txt ./lib/common/config.dart
EX_FOLDER="app-test"
cat ./lib/common/config.dart
echo "// ==="
buildiOS
buildAndroid
}
function buildOnline() {
clear
cp -rf ./lib/common/config_online.txt ./lib/common/config.dart
EX_FOLDER="app-online"
cat ./lib/common/config.dart
echo "// ==="
buildiOS
buildAndroid
}
function buildiOS(){
flutter build ios
#
cd ios
tput setaf 1
echo "正在打包 iOS Project ..."
pwd
tput setaf 2
# 项目名称
PROJECT_NAME="Runner"
# 工作空间名称
WS_NAME="Runner.xcworkspace"
# 版本号
BUNDLE_VERSION=`grep -A1 'CFBundleShortVersionString' "./$PROJECT_NAME/Info.plist" | grep '<string>' | awk -F '<\/string>' '{print $1}' | awk -F '<string>' '{print $2}'`
# 当前日期时间
CURRENT_DATE_TIME=`date +%Y.%m.%d.%H.%M.%S`
# 由版本号及当前日期时间组成的目录名
EXPORT_FOLDER_NAME="v$BUNDLE_VERSION_$CURRENT_DATE_TIME"
# Scheme
SCHEME_NAME="Runner"
# 文件导出目录
EXPORT_ROOT=".././_export/"$EX_FOLDER
EXPORT_FULL_FOLDER_NAME="$EXPORT_ROOT/$PROJECT_NAME/$EXPORT_FOLDER_NAME"
# 归档路径
ARCHIVE_PATH="$EXPORT_FULL_FOLDER_NAME/$PROJECT_NAME.xcarchive"
EXPORT_OPTS_PLIST_NAME="export_opts.plist"
EXPORT_OPTS_PLIST_PATH="$EXPORT_FULL_FOLDER_NAME/$EXPORT_OPTS_PLIST_NAME"
mkdir -p $EXPORT_FULL_FOLDER_NAME
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n\
<plist version=\"1.0\">\n\
<dict>\n\
<key>compileBitcode</key>\n\
<true/>\n\
<key>destination</key>\n\
<string>export</string>\n\
<key>method</key>\n\
<string>ad-hoc</string>\n\
<key>provisioningProfiles</key>\n\
<dict>\n\
<key>com.jim.idj</key>\n\
<string>adhoc_distribution_0320</string>\n\
</dict>\n\
<key>signingCertificate</key>\n\
<string>Apple Distribution</string>\n\
<key>signingStyle</key>\n\
<string>automatic</string>\n\
<key>stripSwiftSymbols</key>\n\
<true/>\n\
<key>teamID</key>\n\
<string>92HB2R4A4W</string>\n\
<key>thinning</key>\n\
<string>&lt;none&gt;</string>\n\
</dict>\n\
</plist>" > "$EXPORT_OPTS_PLIST_PATH"
if [ -s "$EXPORT_OPTS_PLIST_PATH" ]
then
plutil "$EXPORT_OPTS_PLIST_PATH"
echo "成功生成 exportOptionsPlist 选项所需的 plist 文件"
else
echo "生成 exportOptionsPlist 选项所需的 plist 文件失败"
exit 1
fi
# STEP 1. 清理以前构建所留下的文件
echo "正在执行 xcodebuild clean ..."
xcodebuild -workspace "$WS_NAME" -scheme "$SCHEME_NAME" clean 1>/dev/null
echo "xcodebuild clean 执行完毕"
# STEP 2. 构建归档
echo "正在执行 xcodebuild archive ..."
xcodebuild -workspace "$WS_NAME" -scheme "$SCHEME_NAME" -configuration Release archive -archivePath "$ARCHIVE_PATH" 1>/dev/null
if [ -d "$ARCHIVE_PATH" ] # 构建归档成功
then
echo "执行 xcodebuild archive 成功"
else
echo "执行 xcodebuild archive 失败"
exit 1
fi
# STEP 4. 导出 ipa
echo "正在由归档导出 ipa、manifest.plist 文件 ..."
xcodebuild -exportArchive -archivePath "$ARCHIVE_PATH" -exportPath "$EXPORT_FULL_FOLDER_NAME" -exportOptionsPlist "$EXPORT_OPTS_PLIST_PATH" 1>/dev/null
# 删除归档
rm -rdf "$ARCHIVE_PATH"
# 删除生成的export options plist
# rm "$EXPORT_OPTS_PLIST_PATH"
}
function buildAndroid() {
cd $RUNNING_PATH
tput setaf 1
echo "正在打包 Android Project ..."
pwd
flutter build apk --release --no-shrink
mkdir -p "$RUNNING_PATH"/_export/"$EX_FOLDER"/Android-apk/
cp "$RUNNING_PATH"/build/app/outputs/flutter-apk/app-release.apk "$RUNNING_PATH"/_export/"$EX_FOLDER"/Android-apk/
}
function commit() {
#
echo "提交到 Git"
sed '4q;d' pubspec.yaml >version.txt
git add .
git status
git commit -m"Auto Release - $CURRENT_DATE_TIME"
# git push -u
}
function postto() {
echo '上傳到蒲公英'
echo '上傳 iOS'
curl -F "file=@./_export/$EX_FOLDER/Runner/$EXPORT_FOLDER_NAME/IDJGLOBAL.ipa" \
-F "uKey=[key]" \
-F "_api_key=[apikey]" \
https://www.pgyer.com/apiv1/app/upload
echo '上傳 Android'
curl -F "file=@./_export/$EX_FOLDER/Android-apk/app-release.apk" \
-F "uKey=[key]" \
-F "_api_key=[apikey]" \
https://www.pgyer.com/apiv1/app/upload
}
function get_char() {
SAVEDSTTY=`stty -g`
stty -echo
stty cbreak
dd if=/dev/tty bs=1 count=1 2> /dev/null
stty -raw
stty echo
stty $SAVEDSTTY
}
function copyAliPodspec {
cp ./_export_assets/ali_real_person.podspec /Users/qoli/.pub-cache/git/ali_real-921c104dc2503462d38061eedb3ceae6af388d90/ios/ali_real_person.podspec
cat /Users/qoli/.pub-cache/git/ali_real-921c104dc2503462d38061eedb3ceae6af388d90/ios/ali_real_person.podspec
}
clear
cd /Users/qoli/GitHub/idj/
RUNNING_PATH=$(pwd)
echo "請確認已更新 pubspec.yaml 的版本號,按任意鍵繼續"
sed '4q;d' pubspec.yaml
char=`get_char`
tput setaf 2
echo "删除历史存档"
rm -rf _export
flutter clean
copyAliPodspec
buildOnline
#buildTest
cp -rf ./lib/common/config_dev.txt ./lib/common/config.dart
commit
postto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment