-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstep.sh
152 lines (119 loc) · 4.35 KB
/
step.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
#!/bin/bash
set -e
# Dependency directories
STEP_DIR="$( dirname "${BASH_SOURCE[0]}" )"
DEPS_DIR="$STEP_DIR/deps"
# --- 1. INSTALL DEPENDENCIES ---
bluepill_formulae_file="$DEPS_DIR/brew-formulae/$bluepill_version/bluepill.rb"
# Check if the Bluepill formulae is supported
if [ -f "$bluepill_formulae_file" ]; then
printf "\n\nInstalling Bluepill ($bluepill_version/bluepill.rb)...\n"
brew list bluepill \
&& echo " ...already installed." \
|| brew install "$bluepill_formulae_file"
else
printf "Unrecognised Bluepill version identifier passed: '$bluepill_version'\n"
exit -1
fi
printf "\n\nInstalling junitparser...\n"
# Install junitparser to run the `PrintBluepillJUnitResults.py` script for parsing test results
# Allow this part to fail silently
set +e
brew list python3 || brew install python3 && brew postinstall python3
pip3 install junitparser
set -e
# --- 2. BUILD ---
printf "\n\nBuilding App...\n"
# Use xcpretty to pipe pretty build logs if available, otherwise cat
# Not going to require this as a hard dependency because it's just a nice-to-have.
XCPRETTY_OR_CAT=$(which xcpretty && echo xcpretty || echo cat)
# Include code coverage flag if required.
ENABLE_CODE_COV=""
if [ "$generate_coverage" == "true" ]; then
ENABLE_CODE_COV="-enableCodeCoverage YES"
fi
# Build for testing
xcodebuild build-for-testing $ENABLE_CODE_COV ${additional_xcodebuild_args} \
-derivedDataPath "${derived_data_path}" \
-workspace "${workspace}" \
-scheme "${scheme}" \
-destination "platform=iOS Simulator,name=${device_type},OS=${ios_version}" \
| eval $XCPRETTY_OR_CAT
# --- 3. RUN TESTS --- #
printf "\n\nRunning Tests...\n"
# Report name (e.g. "iPhone 6 - 12.2 - 1762297376")
report_name="${device_type} - ${ios_version} - $( date '+%s' )"
report_output_dir="${bluepill_output_dir}/${report_name}"
# Don't fail the build if tests fail...
set +e
# Run tests with Bluepill
bluepill --xctestrun-path "${derived_data_path}"/Build/Products/*.xctestrun \
-r "iOS ${ios_version}" \
-d "${device_type}" \
-o "${report_output_dir}/" \
-n ${num_simulators} \
-f ${failure_tolerance} \
-F ${retry_only_failed_tests} \
-H on ${additional_bluepill_args} \
|| tests_failed=true
# ...renable failures.
set -e
# Parse results
if [ -f "$bluepill_formulae_file" ]; then
results_full=$( printf "$( python3 "$DEPS_DIR/PrintBluepillJUnitResults.py" "${report_output_dir}/TEST-FinalReport.xml" )" )
results_markdown=$( printf "$( python3 "$DEPS_DIR/PrintBluepillJUnitResults.py" "${report_output_dir}/TEST-FinalReport.xml" markdown )" )
else
results_full="Bluepill failed to generate a final test report."
results_markdown="$results_full"
fi
# --- 4. COLLECT COVERAGE (OPTIONAL) ---
if [ "$generate_coverage" == "true" ]; then
# Don't fail the build if coverage fail...
set +e
coverage_file="${bluepill_output_dir}/${target_name}.app.coverage.txt"
# Merge coverage profile
xcrun llvm-profdata merge \
-sparse \
-o ${bluepill_output_dir}/Coverage.profdata \
${bluepill_output_dir}/**/**/*.profraw \
|| coverage_failed=true
# Generate coverage report
if ! [ "$coverage_failed" == "true" ]; then
xcrun llvm-cov show \
-instr-profile ${bluepill_output_dir}/Coverage.profdata \
${derived_data_path}/Build/Products/*/${target_name}.app/${target_name} \
> ${coverage_file} \
|| coverage_failed=true
fi
# ...renable failures.
set -e
else
printf "\nSkipping coverage\n"
fi
# --- 5. EXPORT ENV VARS ---
# Test results (human readable)
envman add --key "${test_result_env_var}" --value "$results_full"
envman add --key "${test_result_env_var}_MARKDOWN" --value "$results_markdown"
# --- 6. PRINT TEST RESULTS TO CONSOLE ---
printf "$results_full"
# --- 7. PASS/FAIL THE STEP ---
# Fail the step if there was an error
if [ "$tests_failed" == "true" ]
then
exit -1
fi
# Report coverage if coverage is set to generate.
if [ "$generate_coverage" == "true" ]; then
# Coverage logging
if [ "$coverage_failed" == "true" ]; then
if [ "$fail_build_if_coverage_fails" == "true" ]; then
printf "\nFailed to gather coverage data and \$fail_build_if_coverage_fails is set to true.\n"
exit -1
else
printf "\nFailed to gather coverage data but \$fail_build_if_coverage_fails is set to false.\n"
fi
else
printf "\nCoverage report generated at: $coverage_file\n"
fi
fi
exit 0