-
Notifications
You must be signed in to change notification settings - Fork 7
/
.travis.sh
executable file
·153 lines (120 loc) · 4.87 KB
/
.travis.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
142
143
144
145
146
147
148
149
150
151
152
153
#! /bin/zsh
set -euo pipefail
logInfo () {
echo "\033[32m$1\033[0m" >&2
}
logWarning () {
echo "\033[33m$1\033[0m" >&2
}
logError () {
echo "\033[31m$1\033[0m" >&2
}
# Make sure all parameters are set correctly.
logInfo "RFCI_PRODUCT_NAME = $RFCI_PRODUCT_NAME"
readonly RFCI_TASK="${RFCI_TASK:? is not set.}"
logInfo "RFCI_TASK = $RFCI_TASK"
readonly RFCI_STAGE="${1:?STAGE is not set.}"
logInfo "RFCI_STAGE = $RFCI_STAGE"
readonly RFWorkspace=${RFWorkspace:="$RFCI_PRODUCT_NAME.xcworkspace"}
logInfo "RFWorkspace = $RFWorkspace"
TRAVIS_COMMIT_MESSAGE=${TRAVIS_COMMIT_MESSAGE:="$(logWarning 'TRAVIS_COMMIT_MESSAGE is not set, leave it blank.')"}
TRAVIS_BRANCH=${TRAVIS_BRANCH:="$(logWarning 'TRAVIS_BRANCH is not set, leave it blank.')"}
echo ""
# Run test
# $1 scheme
# $2 destination
XC_Test() {
xcodebuild test -enableCodeCoverage YES -workspace "$RFWorkspace" -scheme "$1" -destination "$2" ONLY_ACTIVE_ARCH=NO GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES GCC_GENERATE_TEST_COVERAGE_FILES=YES | xcpretty
}
# Run macOS test
XC_TestMac() {
xcodebuild test -enableCodeCoverage YES -workspace "$RFWorkspace" -scheme "Test-macOS" GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES GCC_GENERATE_TEST_COVERAGE_FILES=YES | xcpretty
}
# Run watchOS build
XC_TestWatch() {
xcodebuild build -workspace "$RFWorkspace" -scheme "Target-watchOS" ONLY_ACTIVE_ARCH=NO | xcpretty
}
# Run tests on iOS Simulator.
# The destinations are the first and last available destination that are automatically detected.
# $1 scheme
XC_TestAutoIOS() {
logInfo "Detecting destinations..."
destList=$(xcodebuild -showdestinations -workspace "$RFWorkspace" -scheme "$1" | grep "iOS Simulator")
destCount=$(echo "$destList" | wc -l)
destFirst=$(echo "$destList" | head -1)
destLast=$(echo "$destList" | tail -2 | head -1)
destFirstID=$(echo "$destFirst" | awk 'match($0,/id\:[0-9A-F-]+/){ print substr($0,RSTART+3,RLENGTH-3) }')
destLastID=$(echo "$destLast" | awk 'match($0,/id\:[0-9A-F-]+/){ print substr($0,RSTART+3,RLENGTH-3) }')
logWarning "Test on simulator (id: $destFirstID)."
XC_Test "$1" "platform=iOS Simulator,id=$destFirstID"
logWarning "Test on simulator (id: $destLastID)."
XC_Test "$1" "platform=iOS Simulator,id=$destLastID"
}
STAGE_SETUP() {
gem install cocoapods --no-document
}
STAGE_MAIN() {
if [ "$RFCI_TASK" = "POD_LINT" ]; then
if [[ "$TRAVIS_COMMIT_MESSAGE" = *"[skip lint]"* ]]; then
logWarning "Skip pod lint"
else
if [[ "$TRAVIS_BRANCH" =~ ^[0-9]+\.[0-9]+ ]]; then
logWarning "Release the podspec."
pod trunk push "$RFCI_PRODUCT_NAME.podspec"
elif [ "$TRAVIS_BRANCH" = "master" ]; then
logInfo "Lint the podspec."
pod lib lint --fail-fast
else
logInfo "Lint the podspec."
pod lib lint --fail-fast --allow-warnings
fi
fi
elif [ "$RFCI_TASK" = "Xcode12" ]; then
pod install
XC_TestMac
XC_TestWatch
XC_TestAutoIOS "Test-iOS"
XC_Test "Test-tvOS" "platform=tvOS Simulator,name=Apple TV 4K,OS=14.0"
XC_Test "Test-tvOS" "platform=tvOS Simulator,name=Apple TV,OS=10.2"
echo "Test Swift"
XC_Test "Test-Swift" "platform=iOS Simulator,name=iPhone 11,OS=14.0"
elif [ "$RFCI_TASK" = "Xcode11" ]; then
pod install
XC_TestMac
XC_TestWatch
echo "Test on lastest device and OS."
XC_Test "Test-iOS" "platform=iOS Simulator,name=iPhone 11 Pro,OS=13.0"
XC_Test "Test-tvOS" "platform=tvOS Simulator,name=Apple TV 4K,OS=13.0"
echo "Test on old device and OS".
XC_Test "Test-iOS" "platform=iOS Simulator,name=iPhone 5,OS=10.3.1"
XC_Test "Test-tvOS" "platform=tvOS Simulator,name=Apple TV,OS=10.2"
echo "Test Swift"
XC_Test "Test-Swift" "platform=iOS Simulator,name=iPhone 8,OS=13.0"
elif [ "$RFCI_TASK" = "Xcode10" ]; then
pod install
echo "Test for macOS and watchOS."
XC_TestMac
XC_TestWatch
echo "Test on lastest device and OS."
XC_Test "Test-iOS" "platform=iOS Simulator,name=iPhone XS Max,OS=12.0"
XC_Test "Test-tvOS" "platform=tvOS Simulator,name=Apple TV 4K,OS=12.0"
echo "Test on old device and OS".
XC_Test "Test-iOS" "platform=iOS Simulator,name=iPhone 5,OS=9.0"
XC_Test "Test-tvOS" "platform=tvOS Simulator,name=Apple TV,OS=9.0"
echo "Test Swift"
XC_Test "Test-Swift" "platform=iOS Simulator,name=iPhone SE,OS=12.0"
else
logError "Unexpected CI task: $RFCI_TASK"
fi
}
STAGE_SUCCESS() {
if [ "${RFCI_COVERAGE-}" = "1" ]; then
curl -s https://codecov.io/bash | bash -s
fi
}
STAGE_FAILURE() {
if [[ "$RFCI_TASK" == Xcode* ]]; then
cat -n ~/Library/Logs/DiagnosticReports/xctest*.crash
fi
}
"STAGE_$RFCI_STAGE"