-
Notifications
You must be signed in to change notification settings - Fork 1
/
test-formula
executable file
·228 lines (203 loc) · 6.69 KB
/
test-formula
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/bin/bash
set -e
SELFDIR=$(dirname "$0")
SELFDIR=$(cd "$SELFDIR" && pwd)
# shellcheck source=lib/functions.sh
source "$SELFDIR/lib/functions.sh"
PASSENGER_DIR=
FORMULA=
TARBALL=
NGINX_PASSENGER_ENTERPRISE_FORMULA=
RESET_HOMEBREW=true
NO_UNINSTALL=false
NO_INSTALL_PASSENGER_FORMULA=false
NO_INSTALL_NGINX_FORMULA=false
HOMEBREW_INSTALL_COMMAND=install
NATIVE_PACKAGING_TEST_ARGS=()
function usage()
{
echo "Usage: ./test-formula OPTIONS..."
echo
echo "Required options:"
echo " -p PATH Passenger source directory"
echo " -f PATH Formula to test"
echo " -t PATH Passenger tarball"
echo " -g PATH Path to nginx-passenger-enterprise formula (only when testing Passenger Enterprise)"
echo
echo "Optional options:"
echo " -r Do not reset Homebrew repos"
echo " -n Do not uninstall existing formulas"
echo " -P Do not install Passenger formula"
echo " -N Do not install Nginx formula"
echo
echo " -R Reinstall instead of installing formulas"
echo " -U Upgrade instead of installing formulas"
echo
echo " -E NAME Run specific native packaging test under the given name"
echo
echo " -h Show usage"
}
function parse_options()
{
local OPTIND=1
local opt
while getopts "p:f:t:g:rnPNRUEh" opt; do
case "$opt" in
p)
PASSENGER_DIR="$OPTARG"
;;
f)
FORMULA="$OPTARG"
;;
t)
TARBALL=$(ruby -e 'puts File.absolute_path(ARGV[0])' "$OPTARG")
;;
g)
NGINX_PASSENGER_ENTERPRISE_FORMULA=$(ruby -e 'puts File.absolute_path(ARGV[0])' "$OPTARG")
;;
r)
RESET_HOMEBREW=false
;;
n)
NO_UNINSTALL=true
;;
P)
NO_INSTALL_PASSENGER_FORMULA=true
;;
N)
NO_INSTALL_NGINX_FORMULA=true
;;
R)
HOMEBREW_INSTALL_COMMAND=reinstall
;;
U)
HOMEBREW_INSTALL_COMMAND=upgrade
;;
E)
NATIVE_PACKAGING_TEST_ARGS=(-E "$OPTARG")
;;
h)
usage
exit
;;
*)
return 1
;;
esac
done
(( OPTIND -= 1 )) || true
shift $OPTIND || true
if [[ "$PASSENGER_DIR" = "" || "$FORMULA" = "" || "$TARBALL" = "" ]]; then
usage
exit 1
fi
}
parse_options "$@"
FORMULA_BASENAME=$(basename "$FORMULA")
FORMULA_NAME=$(sed 's/\.rb$//' <<<"$FORMULA_BASENAME")
if [[ "$FORMULA_BASENAME" != passenger.rb && "$FORMULA_BASENAME" != passenger-enterprise.rb ]]; then
echo "ERROR: formula filename may only be 'passenger' or 'passenger-enterprise'" >&2
exit 1
fi
if [[ "$FORMULA_NAME" = passenger-enterprise && "$NGINX_PASSENGER_ENTERPRISE_FORMULA" = '' ]]; then
echo "ERROR: when testing against Passenger Enterprise, -g must be given" >&2
exit 1
fi
# These environment variables interfere with 'brew install'
# and maybe other stuff, so unset them.
unset CC
unset CXX
unset USE_CCACHE
# Grab a lockfile to prevent concurrent instances of this test
# (e.g. concurrently testing Passenger and Passenger Enterprise
# Homebrew formula). This process will be automatically killed
# upon existing the current shell script.
echo "+ Grabbing lock file: /tmp/test-homebrew-formula.lock"
ruby -e 'File.open("/tmp/test-formula.lock", "w").flock(File::LOCK_EX); sleep' &
if $RESET_HOMEBREW; then
echo
header "Resetting Homebrew repositories"
run brew tap --force homebrew/core
run brew update-reset "$(brew --repository homebrew/core)"
if [[ "$FORMULA_NAME" = passenger-enterprise ]]; then
PASSENGER_ENTERPRISE_TAP=$(brew --repository phusion/passenger-enterprise)
if [[ -e "$PASSENGER_ENTERPRISE_TAP" ]]; then
run brew update-reset "$PASSENGER_ENTERPRISE_TAP"
else
run brew tap phusion/passenger-enterprise
fi
fi
fi
if ! $NO_UNINSTALL; then
echo
header "Uninstalling existing formulas"
for NAME in nginx nginx-passenger-enterprise passenger passenger-enterprise; do
echo "+ Checking whether $NAME is installed"
set +e
OUTPUT=$(brew info --json --installed "$NAME" 2>&1)
RETVAL=$?
set -e
if [[ "$RETVAL" != 0 ]] && ! [[ "$OUTPUT" =~ 'No available formula' ]]; then
echo "+ Error in 'brew info --json --installed $NAME':" >&2
echo "$OUTPUT" >&2
exit 1
fi
if ! grep -qE '(^Not installed|No available formula)' <<<"$OUTPUT"; then
run brew uninstall --force --ignore-dependencies "$NAME"
fi
done
fi
echo
header "Test installing Passenger and Nginx"
# We MUST copy our modified Formula to the offical path (i.e. the file that
# `brew edit` would open).
#
# I've already tried `brew install`-ing the modified formula from a different
# path, but then I would run into the following problem:
# If the formula version is different from the one in homebrew-core,
# then `brew install nginx --with-passenger` will try to install the passenger
# formula from homebrew-core. The only way to prevent this is to copy our
# modified formula to the official path.
OFFICIAL_FORMULA_PATH=$(brew formula "$FORMULA_NAME")
run cp "$FORMULA" "$OFFICIAL_FORMULA_PATH"
run sed -i '' -e '/^ *revision.*$/d' "$OFFICIAL_FORMULA_PATH"
run sed -i '' -e "s|^ url \".*| url \"file://$TARBALL\"|" "$OFFICIAL_FORMULA_PATH"
run sed -i '' -e '/ patch do/{N;N;N;N;d;}' "$OFFICIAL_FORMULA_PATH"
run sed -i '' -e '/patch :DATA/d' "$OFFICIAL_FORMULA_PATH"
run sed -i '' -e '/__END__/,$ d' "$OFFICIAL_FORMULA_PATH"
run sed -i '' -Ee 's/(compile-nginx-engine"),/\1/' "$OFFICIAL_FORMULA_PATH"
run sed -i '' -e '/.*--nginx-tarball.*/d' "$OFFICIAL_FORMULA_PATH"
run sed -i '' -e '/.*--nginx-version.*/d' "$OFFICIAL_FORMULA_PATH"
run grep '^ url' "$OFFICIAL_FORMULA_PATH"
cat "$OFFICIAL_FORMULA_PATH"
if [[ "$FORMULA_NAME" = passenger-enterprise ]]; then
OFFICIAL_FORMULA_PATH=$(brew formula nginx-passenger-enterprise)
run cp "$NGINX_PASSENGER_ENTERPRISE_FORMULA" "$OFFICIAL_FORMULA_PATH"
fi
run rm -rf "$(brew --cache)"/*
if ! $NO_INSTALL_PASSENGER_FORMULA; then
run brew "$HOMEBREW_INSTALL_COMMAND" -sv "$FORMULA_NAME"
if [[ "$FORMULA_NAME" = passenger ]]; then
# remove the word slave from the file:// url because it causes homebrew to fail the audit
run sed -i '' -Ee 's|^(.*url.*)-slave(.*)|\1\2|' "$OFFICIAL_FORMULA_PATH"
# We don't audit the Passenger Enterprise formula because the way
# we build the URL there conflicts with brew audit rules.
run brew audit --strict --verbose "$FORMULA_NAME" || ( cat "$OFFICIAL_FORMULA_PATH" && false )
fi
fi
if ! $NO_INSTALL_NGINX_FORMULA; then
if [[ "$FORMULA_NAME" = passenger ]]; then
run brew "$HOMEBREW_INSTALL_COMMAND" -v nginx passenger
run brew audit --strict --verbose nginx
else
run brew unlink nginx
run brew "$HOMEBREW_INSTALL_COMMAND" -v nginx-passenger-enterprise
run brew audit --strict --verbose nginx-passenger-enterprise
fi
fi
run brew uninstall --force --ignore-dependencies httpd
echo
header "Test Passenger installation"
echo "+ Switching to $PASSENGER_DIR"
cd "$PASSENGER_DIR"
run bundle exec rake test:integration:native_packaging "${NATIVE_PACKAGING_TEST_ARGS[@]}"