Files
2022-12-20 11:30:56 +03:00

128 lines
3.1 KiB
Bash
Executable File

#!/usr/bin/env bash
unlock_login_keychain() {
if [ -z "$1" ]; then
echo "Password parameter must be exists"
return 1
fi
local timeout=3600
if [ -n "$2" ]; then
timeout=$2
fi
security list-keychains -s ~/Library/Keychains/login.keychain-db
security unlock-keychain -p $1 ~/Library/Keychains/login.keychain-db
security set-keychain-settings -t $timeout -l ~/Library/Keychains/login.keychain-db
}
#Passed external variables
DEPLOY_TYPE=$1
if [ "$DEPLOY_TYPE" == "PRODUCTION" ]; then
DEPLOY_TYPE="PROD"
else
DEPLOY_TYPE="BETA"
fi
if [ -n "$CI_COMMIT_TAG" ]; then
DEPLOY_TYPE="PROD"
fi
APPLICATION_NAME=$2
APPLICATION_SCHEME=$3
ROOT=$(pwd)
IOS_PATH=$ROOT/iOS
#Remove Delivered data
rm -rf ~/Library/Developer/Xcode/DerivedData
DERIVED_PATH=$ROOT/DERIVED
ARCHIVE_PATH=$ROOT/$APPLICATION_NAME.xcarchive
IPA_PATH=$ROOT/ResultIPA
FULL_IPA_PATH=$IPA_PATH #/$DEPLOY_TYPE
PLIST_PATH=$ROOT/toolchain/Malinka-Production-iOS-ExportOptions.plist
#Remove old results
rm -rf $DERIVED_PATH
rm -rf $ARCHIVE_PATH
mkdir $DERIVED_PATH
# Prepare and generate xcodeproj file
if [ "$DEPLOY_TYPE" == "BETA" ]; then
cp -R $(dirname "$0")/Settings.bundle $IOS_PATH/Assets
cp -R $(dirname "$0")/NetworkSettings.bundle $IOS_PATH/Assets
fi
$(dirname "$0")/generate.swift --path=iOS/project.yml --type=$DEPLOY_TYPE
if [ "$?" != "0" ]; then
echo >&2 "Error: xcodeproj generation failed";
exit 1
fi
echo "🥠 Copy Package.resolved to Malinka.xcodeproj"
mkdir -p $IOS_PATH/Malinka.xcodeproj/project.xcworkspace/xcshareddata/swiftpm
cp -f $ROOT/toolchain/Package.resolved $IOS_PATH/Malinka.xcodeproj/project.xcworkspace/xcshareddata/swiftpm
cd $IOS_PATH
VERSION=$CI_PIPELINE_IID
if [ "$VERSION" != "" ]; then
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $VERSION" $IOS_PATH/Wallet/Info.plist
fi
# Set Tag version for release
if [ -n "$CI_COMMIT_TAG" ]; then
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $CI_COMMIT_TAG" $IOS_PATH/Wallet/Info.plist
fi
unlock_login_keychain "$K8S_SECRET_SPOCK"
#Create Archive
xcodebuild -project $APPLICATION_NAME.xcodeproj \
-scheme $APPLICATION_SCHEME \
-sdk iphoneos \
-archivePath $ARCHIVE_PATH \
-derivedDataPath $DERIVED_PATH \
-configuration "Release" \
archive \
ENABLE_SWIFTLINT=NO | xcpretty
if [ "${PIPESTATUS[0]}" != "0" ]; then
echo >&2 "Error: xcodebuild failed";
exit 1
fi
unlock_login_keychain "$K8S_SECRET_SPOCK"
echo $FULL_IPA_PATH
mkdir -p $IPA_PATH
#Create ipa
xcodebuild \
-exportArchive \
-archivePath $ARCHIVE_PATH \
-exportPath $FULL_IPA_PATH \
-exportOptionsPlist $PLIST_PATH | xcpretty
if [ "${PIPESTATUS[0]}" != "0" ]; then
echo >&2 "Error: xcodebuild failed";
exit 1
fi
# Copy dSYM and upload-symbols app for Crashlytics decoding
CRASHLYTICS_PATH=$FULL_IPA_PATH/Crashlytics
mkdir $CRASHLYTICS_PATH
cp $IOS_PATH/Assets/GoogleService-Info.plist $CRASHLYTICS_PATH
cp $DERIVED_PATH/SourcePackages/checkouts/firebase-ios-sdk/Crashlytics/upload-symbols $CRASHLYTICS_PATH
cp -r $ARCHIVE_PATH/dSYMs $CRASHLYTICS_PATH
# Clean after
rm -rf $DERIVED_PATH
rm -rf $ARCHIVE_PATH