-
Notifications
You must be signed in to change notification settings - Fork 80
/
build.sh
executable file
·142 lines (117 loc) · 4.17 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/bash
# Copyright (c) 2017, Psiphon Inc.
# All rights reserved.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set -ue
BASE_DIR=$(cd "$(dirname "$0")" ; pwd -P)
usage () {
echo " Usage: ${0} <release|dev-release|debug> [--dry-run]"
echo ""
echo " This script can be used to create various Psiphon iOS VPN builds for different distribution platforms. I.E. app store, testflight and internal testing."
exit 1
}
setup_env () {
cd "${BASE_DIR}"
PSIPHON_IOS_VPN_XCODE_WORKSPACE="${BASE_DIR}"
# The location of the final build
BUILD_DIR="${PSIPHON_IOS_VPN_XCODE_WORKSPACE}/build/${TARGET_DISTRIBUTION_PLATFORM}"
# Clean previous output
rm -rf "${BUILD_DIR}"
if ! [ -x "$(command -v xcrun)" ]; then
echo "Error: 'xcrun' is not installed"
exit 1
fi
}
build () {
# Install pods
pod install --repo-update
# Build
if ! xcodebuild -workspace "${PSIPHON_IOS_VPN_XCODE_WORKSPACE}/Psiphon.xcworkspace" -scheme Psiphon -sdk iphoneos -configuration "${CONFIGURATION}" archive -archivePath "${BUILD_DIR}/Psiphon.xcarchive" -allowProvisioningUpdates;
then
echo "xcodebuild failed. Failed to create Psiphon.xcarchive, aborting..."
exit 1
fi
if ! xcodebuild -exportArchive -archivePath "${BUILD_DIR}/Psiphon.xcarchive" -exportOptionsPlist "${PSIPHON_IOS_VPN_XCODE_WORKSPACE}/${EXPORT_OPTIONS_PLIST}" -exportPath "${BUILD_DIR}" -allowProvisioningUpdates;
then
echo "xcodebuild failed. Failed to export Psiphon.xcarchive, aborting..."
exit 1
fi
# Jenkins loses symlinks from the framework directory, which results in a build
# artifact that is invalid to use in an App Store app. Instead, we will zip the
# resulting build and use that as the artifact.
cd "${BUILD_DIR}"
zip --recurse-paths --symlinks build.zip ./* --exclude "*.DS_Store"
echo "BUILD DONE"
}
upload_ipa () {
echo "Validating exported ipa..."
if ! xcrun altool --validate-app -t ios -f "${BUILD_DIR}/Psiphon.ipa" -u "${ITUNES_CONNECT_USERNAME}" -p "${ITUNES_CONNECT_PASSWORD}";
then
echo "Psiphon.ipa failed validation, aborting..."
exit 1
fi
echo "Uploading validated ipa to TestFlight..."
if ! xcrun altool --upload-app -t ios -f "${BUILD_DIR}/Psiphon.ipa" -u "${ITUNES_CONNECT_USERNAME}" -p "${ITUNES_CONNECT_PASSWORD}";
then
echo "Failed to upload Psiphon.ipa, aborting..."
exit 1
fi
}
# If $1 is unset or null, prints usage.
# More information on parameter expansion: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02
if [ -z "${1:-}" ]; then
usage
fi
TARGET_DISTRIBUTION_PLATFORM="$1"
# if $2 is unset or null, sets DRY_RUN to false,
# otherwise if it is set to "--dry-run", sets DRY_RUN to true,
# otherwise it is incorrect usage.
if [ -z "${2:-}" ]; then
DRY_RUN=false
elif [ "$2" = "--dry-run" ]; then
DRY_RUN=true
else
usage
fi
# Option parsing
case $TARGET_DISTRIBUTION_PLATFORM in
release)
CONFIGURATION="Release"
EXPORT_OPTIONS_PLIST="exportAppStoreOptions.plist"
setup_env
build
if [ "$DRY_RUN" = false ]; then
upload_ipa
fi
;;
dev-release)
CONFIGURATION="DevRelease"
EXPORT_OPTIONS_PLIST="exportAppStoreOptions.plist"
setup_env
build
if [ "$DRY_RUN" = false ]; then
upload_ipa
fi
;;
debug)
CONFIGURATION="Debug"
EXPORT_OPTIONS_PLIST="exportDevelopmentOptions.plist"
setup_env
build
;;
*)
usage
;;
esac