Skip to content

Commit

Permalink
feat: Support apiKey for appstore
Browse files Browse the repository at this point in the history
  • Loading branch information
fwh1990 committed Feb 25, 2020
1 parent b83c72c commit be4f7b0
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 61 deletions.
33 changes: 25 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
一键上传 android/ios APP到各个测试平台和`app store`

### 支持系统
**MacOs** (使用了`shell`语法,而且ios只能依赖xcode软件)
**MacOs** (使用了`bash`语法,而且ios只能依赖xcode软件)

### 已集成平台

Expand Down Expand Up @@ -47,23 +47,40 @@ npx upload-init
},
// 上传到App Store
"app_store": {
// 用户(APP_ID)必须拥有该APP的上传权限
"username": "",
////////////////////////////////////////////////////////////////////////////
// 注意:
// user_* 与 api_* 是互斥的,只需要填写其中一组即可正常上传
////////////////////////////////////////////////////////////////////////////

// 用户(APPLE_ID)必须拥有该APP的上传权限
"user_name": "",
// 随机密码,访问链接 https://appleid.apple.com/account/manage ,点击 App专用密码 生成密码
"random_password": "",
"user_password": "",

// 秘钥ID,访问链接 https://appstoreconnect.apple.com/access/api ,点击蓝色圆形+号图标即可生成秘钥。
////////////////////////////////////////////////////////////////////////////
// 注意:
// 生成秘钥后,必须下载秘钥文件,并复制到以下随意一个文件夹中:
// ./private_keys
// ~/private_keys
// ~/.private_keys
// ~/.appstoreconnect/private_keys
////////////////////////////////////////////////////////////////////////////
"api_key": "",
// 生成秘钥后,秘钥的列表上方有个 Issuer ID
"api_issuer": "",

"ios_export_plist": "./ios-export/app-store.plist"
},
// 上传到Test Flight
// 默认从app_store配置中拿 user_* 或者 api_*,也可以在test_flight配置下覆盖这几个参数
"test_flight": {
// 用户(APP_ID)必须拥有该APP的上传权限
"username": "",
// 可与App Store配置共享同一个随机密码
"random_password": "",
"ios_export_plist": "./ios-export/ad-hoc.plist"
}
}
```


# 准备工作

`ios_export_plist`即ios打包参数的存放路径。因为ios的打包参数及其复杂,每个项目都会有一些差异,所以为了保证能准确无误地打包出符合要求的app,您需要手动执行一次以下内容(**只需一次**)。
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-upload",
"version": "0.8.2",
"version": "1.0.0",
"main": "index.js",
"repository": "[email protected]:fwh1990/react-native-upload.git",
"author": "范文华 <[email protected]>",
Expand Down
62 changes: 42 additions & 20 deletions src/libs/appstore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,55 @@

set -e

libs=$(dirname $0)
# @see src/upload-appstore.sh
# @see src/upload-testflight.sh

username=$(node $libs/get-config.js app_store.username)
password=$(node $libs/get-config.js app_store.random_password)
ios_export_plist=$1
ios_app_save_dir=./ios/build/rn-upload-app-temp

bash $libs/archive.sh
bash $libs/export-ipa.sh $ios_export_plist $ios_app_save_dir
ios_app=$(ls $ios_app_save_dir/*.ipa)

echo -e "\033[032mValidating ios app...\033[0m"
xcrun altool \
--validate-app \
--file "$ios_app" \
--type "ios" \
--username "$username" \
--password "$password"
type="ios"

# In some case, it will fail when uploading, we'd better remove these folders.
rm -rf ~/.itmstransporter/ ~/.old_itmstransporter/

echo -e "\033[032m[$log_prefix] Validating ios app...\033[0m"

if [ -n "$username" ]
then
xcrun altool \
--validate-app \
--file "$ios_app" \
--type "$type" \
--username "$username" \
--password "$password"
else
xcrun altool \
--validate-app \
--file "$ios_app" \
--type "$type" \
--apiIssuer "$api_issuer" \
--apiKey "$api_key"
fi

# Upload to https://appstoreconnect.apple.com/
echo -e "\033[032mUploading ios app to appstore...\033[0m"
xcrun altool \
--upload-app \
--file "$ios_app" \
--type "ios" \
--username "$username" \
--password "$password"
echo -e "\033[032m[$log_prefix] Uploading ios app...\033[0m"

if [ -n "$username" ]
then
xcrun altool \
--upload-app \
--file "$ios_app" \
--type "$type" \
--username "$username" \
--password "$password"
else
xcrun altool \
--upload-app \
--file "$ios_app" \
--type "$type" \
--apiIssuer "$api_issuer" \
--apiKey "$api_key"
fi

echo -e "\033[32m[$log_prefix] Done!\033[0m"
10 changes: 6 additions & 4 deletions src/libs/upload.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
"ios_export_plist": "./ios-export/ad-hoc.plist"
},
"app_store": {
"username": "",
"random_password": "",
"user_name": "",
"user_password": "",

"api_key": "",
"api_issuer": "",

"ios_export_plist": "./ios-export/app-store.plist"
},
"test_flight": {
"username": "",
"random_password": "",
"ios_export_plist": "./ios-export/ad-hoc.plist"
}
}
16 changes: 14 additions & 2 deletions src/upload-appstore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,20 @@ else
fi
libs=$dir/libs

log_prefix="App Store"
ios_export_plist=$(bash $libs/ipa-export-plist.sh app_store.ios_export_plist)
username=$(node $libs/get-config.js app_store.user_name#)
api_key=$(node $libs/get-config.js app_store.api_key#)

bash $libs/appstore.sh $ios_export_plist
if [ -n "$username" ]
then
password=$(node $libs/get-config.js app_store.user_password)
elif [ -n "$api_key" ]
then
api_issuer=$(node $libs/get-config.js app_store.api_issuer)
else
echo -e "\033[031m[$log_prefix] You are required to provide either app_store.user_* or app_store.api_*\033[0m"
exit 1
fi

echo -e "\033[32m[app-store] Done!\033[0m"
source $libs/appstore.sh
31 changes: 16 additions & 15 deletions src/upload-fir.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ else
fi
libs=$dir/libs

log_prefix="Fir.im"
fir_host=http://api.fir.im/apps
api_token=$(node $libs/get-config.js fir.fir_api_token)

Expand All @@ -18,10 +19,10 @@ ios=$(node $libs/get-config.js ios#1 "$@")

if [ $android -eq 0 ]
then
echo -e "\n\033[33m[fir.im] Android is skipped.\033[0m\n"
echo -e "\n\033[33m[$log_prefix] Android is skipped.\033[0m\n"
sleep 1
else
echo -e "\033[32m[fir.im] Building android app...\033[0m"
echo -e "\033[32m[$log_prefix] Building android app...\033[0m"
sleep 1

sh $libs/build-android.sh
Expand All @@ -33,10 +34,10 @@ fi

if [ $ios -eq 0 ]
then
echo -e "\n\033[33m[fir.im] Ios is skipped.\033[0m\n"
echo -e "\n\033[33m[$log_prefix] Ios is skipped.\033[0m\n"
sleep 1
else
echo -e "\033[32m[fir.im] Building ios app...\033[0m"
echo -e "\033[32m[$log_prefix] Building ios app...\033[0m"
sleep 1

ios_export_plist=$(bash $libs/ipa-export-plist.sh fir.ios_export_plist)
Expand All @@ -58,11 +59,11 @@ else
fi

# Android
[ \( $android -ne 0 \) -a \( -z "$android_app" \) ] && echo -e "\033[31m[fir.im] Android file is missing.\033[0m"
[ \( $android -ne 0 \) -a \( -z "$android_app" \) ] && echo -e "\033[31m[$log_prefix] Android file is missing.\033[0m"

if [ \( $android -ne 0 \) -a \( -n "$android_app" \) ]
then
echo -e "\033[32m[fir.im] Getting android token...\033[0m"
echo -e "\033[32m[$log_prefix] Getting android token...\033[0m"
token_result=$(
curl \
--silent \
Expand All @@ -83,7 +84,7 @@ then

if [ -n "$android_icon" ]
then
echo -e "\033[32m[fir.im] Uploading android icon...\033[0m"
echo -e "\033[32m[$log_prefix] Uploading android icon...\033[0m"
result=$(
curl \
--silent \
Expand All @@ -95,7 +96,7 @@ then
rm -f $android_icon
fi

echo -e "\033[32m[fir.im] Uploading android app...\033[0m"
echo -e "\033[32m[$log_prefix] Uploading android app...\033[0m"
result=$(
curl \
--form "file=@$android_app" \
Expand All @@ -108,15 +109,15 @@ then
${binary_upload_url}
)
node $libs/validate-fir.js "$result"
echo -e "\n[fir.im] Install app by open link: \033[32mhttps://fir.im/$short_url\033[0m\n"
echo -e "\n[$log_prefix] Install app by open link: \033[32mhttps://fir.im/$short_url\033[0m\n"
fi

# Ios
[ \( $ios -ne 0 \) -a \( -z "$ios_app" \) ] && echo -e "\033[31m[fir.im] Ios file is missing.\033[0m"
[ \( $ios -ne 0 \) -a \( -z "$ios_app" \) ] && echo -e "\033[31m[$log_prefix] Ios file is missing.\033[0m"

if [ \( $ios -ne 0 \) -a \( -n "$ios_app" \) ]
then
echo -e "\033[32m[fir.im] Getting ios token...\033[0m"
echo -e "\033[32m[$log_prefix] Getting ios token...\033[0m"
token_result=$(
curl \
--silent \
Expand All @@ -137,7 +138,7 @@ then

if [ -n "$ios_icon" ]
then
echo -e "\033[32m[fir.im] Uploading ios icon...\033[0m"
echo -e "\033[32m[$log_prefix] Uploading ios icon...\033[0m"
result=$(
curl \
--silent \
Expand All @@ -156,7 +157,7 @@ then
release_type=adhoc
fi

echo -e "\033[32m[fir.im] Uploading ios app...\033[0m"
echo -e "\033[32m[$log_prefix] Uploading ios app...\033[0m"
result=$(
curl \
--form "file=@$ios_app" \
Expand All @@ -170,7 +171,7 @@ then
${binary_upload_url}
)
node $libs/validate-fir.js "$result"
echo -e "\n[fir.im] Install app by open link: \033[32mhttps://fir.im/$short_url\033[0m\n"
echo -e "\n[$log_prefix] Install app by open link: \033[32mhttps://fir.im/$short_url\033[0m\n"
fi

echo -e "\033[32m[fir.im] Done!\033[0m"
echo -e "\033[32m[$log_prefix] Done!\033[0m"
19 changes: 10 additions & 9 deletions src/upload-pgy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ else
fi
libs=$dir/libs

log_prefix="Pgyer"
pgy_host=https://www.pgyer.com/apiv2/app/upload
api_key=$(node $libs/get-config.js pgy.pgy_api_key)
install_type=$(node $libs/get-config.js pgy.pgy_install_type)
Expand All @@ -26,10 +27,10 @@ ios=$(node $libs/get-config.js ios#1 "$@")

if [ $android -eq 0 ]
then
echo -e "\n\033[33m[pgyer] Android is skipped.\033[0m\n"
echo -e "\n\033[33m[$log_prefix] Android is skipped.\033[0m\n"
sleep 1
else
echo -e "\033[32m[pgyer] Building android app...\033[0m"
echo -e "\033[32m[$log_prefix] Building android app...\033[0m"
sleep 1

sh $libs/build-android.sh
Expand All @@ -38,10 +39,10 @@ fi

if [ $ios -eq 0 ]
then
echo -e "\n\033[33m[pgyer] Ios is skipped.\033[0m\n"
echo -e "\n\033[33m[$log_prefix] Ios is skipped.\033[0m\n"
sleep 1
else
echo -e "\033[32m[pgyer] Building ios app...\033[0m"
echo -e "\033[32m[$log_prefix] Building ios app...\033[0m"
sleep 1

ios_export_plist=$(bash $libs/ipa-export-plist.sh pgy.ios_export_plist)
Expand All @@ -54,11 +55,11 @@ else
fi

# Android
[ \( $android -ne 0 \) -a \( -z "$android_app" \) ] && echo -e "\033[31m[pgyer] Android file is missing.\033[0m"
[ \( $android -ne 0 \) -a \( -z "$android_app" \) ] && echo -e "\033[31m[$log_prefix] Android file is missing.\033[0m"

if [ \( $android -ne 0 \) -a \( -n "$android_app" \) ]
then
echo -e "\033[32m[pgyer] Uploading android...\033[0m"
echo -e "\033[32m[$log_prefix] Uploading android...\033[0m"
result=$(
curl \
--form "file=@$android_app" \
Expand All @@ -72,11 +73,11 @@ then
fi

# Ios
[ \( $ios -ne 0 \) -a \( -z "$ios_app" \) ] && echo -e "\033[31m[pgyer] Ios file is missing.\033[0m"
[ \( $ios -ne 0 \) -a \( -z "$ios_app" \) ] && echo -e "\033[31m[$log_prefix] Ios file is missing.\033[0m"

if [ \( $ios -ne 0 \) -a \( -n "$ios_app" \) ]
then
echo -e "\033[32m[pgyer] Uploading ios...\033[0m"
echo -e "\033[32m[$log_prefix] Uploading ios...\033[0m"
result=$(
curl \
--form "file=@$ios_app" \
Expand All @@ -89,4 +90,4 @@ then
node $libs/validate-pgy.js "$result"
fi

echo -e "\033[32m[pgyer] Done!\033[0m"
echo -e "\033[32m[$log_prefix] Done!\033[0m"
16 changes: 14 additions & 2 deletions src/upload-testflight.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,20 @@ else
fi
libs=$dir/libs

log_prefix="Test Flight"
ios_export_plist=$(bash $libs/ipa-export-plist.sh test_flight.ios_export_plist)
username=$(node $libs/get-config.js test_flight.user_name,app_store.user_name#)
api_key=$(node $libs/get-config.js test_flight.api_key,app_store.api_key#)

bash $libs/appstore.sh $ios_export_plist
if [ -n "$username" ]
then
password=$(node $libs/get-config.js test_flight.user_password,app_store.user_password)
elif [ -n "$api_key" ]
then
api_issuer=$(node $libs/get-config.js test_flight.api_issuer,app_store.api_issuer)
else
echo -e "\033[031m[$log_prefix] You are required to provide either {test_flight|app_store}.user_* or {test_flight|app_store}.api_*\033[0m"
exit 1
fi

echo -e "\033[32m[test-flight] Done!\033[0m"
source $libs/appstore.sh

0 comments on commit be4f7b0

Please sign in to comment.