forked from material-components/material-components-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.kokoro
executable file
·200 lines (169 loc) · 6.06 KB
/
.kokoro
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/bin/bash
#
# Copyright 2017-present The Material Components for iOS Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Fail on any error.
set -e
KOKORO_RUNNER_VERSION="v4.*"
# Kokoro only supports up to 8.2 for now. Once 8.3 support is introduced we will bump this version.
XCODE_MINIMUM_VERSION="8.2.0"
fix_bazel_imports() {
if [ -z "$KOKORO_BUILD_NUMBER" ]; then
tests_dir_prefix=""
else
tests_dir_prefix="github/repo/"
fi
rewrite_tests() {
find "${stashed_dir}${tests_dir_prefix}"components/private/*/tests/unit -type f -name '*.swift' -exec sed -i '' -E "$1" {} + || true
find "${stashed_dir}${tests_dir_prefix}"components/*/tests/unit -type f -name '*.swift' -exec sed -i '' -E "$1" {} + || true
}
rewrite_source() {
find "${stashed_dir}${tests_dir_prefix}"components/private/*/src -type f -name '*.h' -exec sed -i '' -E "$1" {} + || true
find "${stashed_dir}${tests_dir_prefix}"components/private/*/src -type f -name '*.m' -exec sed -i '' -E "$1" {} + || true
find "${stashed_dir}${tests_dir_prefix}"components/*/src -type f -name '*.h' -exec sed -i '' -E "$1" {} + || true
find "${stashed_dir}${tests_dir_prefix}"components/*/src -type f -name '*.m' -exec sed -i '' -E "$1" {} + || true
}
stashed_dir=""
rewrite_tests "s/import MaterialComponents.MaterialMath/import components_private_Math_Math/"
rewrite_tests "s/import MaterialComponents.Material(.+)/import components_\1_\1/"
rewrite_source "s/import <Motion(.+)\/Motion.+\.h>/import \"Motion\1.h\"/"
rewrite_source "s/import <MDF(.+)\/MDF.+\.h>/import \"MDF\1.h\"/"
rewrite_tests "s/import MDFTextAccessibility/import material_text_accessibility_ios_MDFTextAccessibility/"
rewrite_tests "s/import MDFInternationalization/import material_internationalization_ios_MDFInternationalization/"
stashed_dir="$(pwd)/"
reset_imports() {
# Undoes our source changes from above.
rewrite_tests "s/import components_private_Math_Math/import MaterialComponents.MaterialMath/"
rewrite_tests "s/import components_(.+)_.+/import MaterialComponents.Material\1/"
rewrite_source "s/import \"Motion(.+)\.h\"/import <Motion\1\/Motion\1.h>/"
rewrite_source "s/import \"MDF(.+)\.h\"/import <MDF\1\/MDF\1.h>/"
rewrite_tests "s/import material_text_accessibility_ios_MDFTextAccessibility/import MDFTextAccessibility/"
rewrite_tests "s/import material_internationalization_ios_MDFInternationalization/import MDFInternationalization/"
}
trap reset_imports EXIT
}
version_as_number() {
padded_version="${1%.}" # Strip any trailing dots
# Pad with .0 until we get a M.m.p version string.
while [ $(grep -o "\." <<< "$padded_version" | wc -l) -lt "2" ]; do
padded_version=${padded_version}.0
done
echo "${padded_version//.}"
}
run_bazel() {
echo "Running bazel builds..."
fix_bazel_imports
if [ -n "$VERBOSE_OUTPUT" ]; then
verbosity_args="-v"
fi
if [ -z "$COMMAND" ]; then
COMMAND="test"
fi
if [ -z "$TARGET" ]; then
TARGET="//components/..."
fi
./.kokoro-ios-runner/bazel.sh $COMMAND $TARGET \
--min-xcode-version $XCODE_MINIMUM_VERSION \
$verbosity_args \
--ios_minimum_os=8.0 \
--ios_multi_cpus=i386,x86_64
}
run_cocoapods() {
echo "Running cocoapods builds..."
xcode_min_version_as_number="$(version_as_number $XCODE_MINIMUM_VERSION)"
if [ -n "$KOKORO_BUILD_NUMBER" ]; then
# Move into our cloned repo
cd github/repo
gem install xcpretty cocoapods --no-rdoc --no-ri --no-document --quiet
pod --version
fi
ls /Applications/ | grep "Xcode" | while read -r xcode_path; do
xcode_version=$(cat /Applications/$xcode_path/Contents/version.plist \
| grep "CFBundleShortVersionString" -A1 \
| grep string \
| cut -d'>' -f2 \
| cut -d'<' -f1)
if [ -n "$xcode_min_version_as_number" ]; then
xcode_version_as_number="$(version_as_number $xcode_version)"
if [ "$xcode_version_as_number" -lt "$xcode_min_version_as_number" ]; then
continue
fi
fi
sudo xcode-select --switch /Applications/$xcode_path/Contents/Developer
xcodebuild -version
# Resolves the following crash when switching Xcode versions:
# "Failed to locate a valid instance of CoreSimulatorService in the bootstrap"
launchctl remove com.apple.CoreSimulator.CoreSimulatorService || true
scripts/prep_all
scripts/build_all --verbose
if [ "$IS_RELEASE" -eq "1" ]; then
scripts/test_all
else
scripts/test_all catalog/MDCCatalog.xcworkspace:MDCUnitTests
fi
done
bash <(curl -s https://codecov.io/bash)
}
POSITIONAL=()
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-v|--verbose)
VERBOSE_OUTPUT="1"
shift
;;
-d|--dependency_system)
DEPENDENCY_SYSTEM="$2"
shift
shift
;;
-c|--command)
COMMAND="$2"
shift
shift
;;
-t|--target)
TARGET="$2"
shift
shift
;;
*)
POSITIONAL+=("$1")
shift
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
if [ -n "$KOKORO_BUILD_NUMBER" ]; then
# Always enable verbose output on kokoro runs.
VERBOSE_OUTPUT=1
fi
if [ -n "$VERBOSE_OUTPUT" ]; then
# Display commands to stderr.
set -x
fi
if [ ! -d .kokoro-ios-runner ]; then
git clone https://github.com/material-foundation/kokoro-ios-runner.git .kokoro-ios-runner
fi
pushd .kokoro-ios-runner
git fetch > /dev/null
TAG=$(git tag --sort=v:refname -l "$KOKORO_RUNNER_VERSION" | tail -n1)
git checkout "$TAG" > /dev/null
popd
case "$DEPENDENCY_SYSTEM" in
"bazel") run_bazel ;;
"cocoapods") run_cocoapods ;;
*) run_bazel ;;
esac
echo "Success!"