Skip to content

Commit dfd2675

Browse files
try controlling local homebrew further on limited CI machines
1 parent 38c64f4 commit dfd2675

File tree

1 file changed

+73
-14
lines changed

1 file changed

+73
-14
lines changed

src/coveralls_functions.jl

Lines changed: 73 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ Returns (brew_cmd, use_local, local_homebrew_dir, local_brew_path).
128128
function detect_homebrew_status()
129129
local_homebrew_dir = @get_scratch!("local_homebrew")
130130
local_brew_path = joinpath(local_homebrew_dir, "bin", "brew")
131-
131+
132132
# Try system Homebrew first
133133
system_brew_cmd = Sys.which("brew")
134134
if system_brew_cmd !== nothing
@@ -143,7 +143,7 @@ function detect_homebrew_status()
143143
@debug "System Homebrew check failed: $e"
144144
end
145145
end
146-
146+
147147
@info "Using local Homebrew installation"
148148
return (local_brew_path, true, local_homebrew_dir, local_brew_path)
149149
end
@@ -187,27 +187,47 @@ Install a local Homebrew instance.
187187
"""
188188
function install_local_homebrew(local_homebrew_dir, local_brew_path)
189189
@info "Installing local Homebrew to: $local_homebrew_dir"
190-
190+
191191
mkpath(local_homebrew_dir)
192192

193193
# Download and extract Homebrew
194194
latest_release_url = "https://api.github.com/repos/Homebrew/brew/releases/latest"
195195
response = HTTP.get(latest_release_url)
196196
release_data = JSON.parse(String(response.body))
197197
tarball_url = release_data["tarball_url"]
198-
198+
199199
tarball_path = joinpath(local_homebrew_dir, "homebrew-latest.tar.gz")
200200
Downloads.download(tarball_url, tarball_path)
201-
201+
202202
run(`tar -xzf $tarball_path -C $local_homebrew_dir --strip-components=1`)
203203
rm(tarball_path)
204-
204+
205205
if !isfile(local_brew_path)
206206
error("Homebrew extraction failed - brew executable not found")
207207
end
208208

209-
# Post-install setup
210-
run(`$local_brew_path update --force --quiet`)
209+
# Post-install setup with better error handling
210+
try
211+
# Set environment variables for local Homebrew
212+
homebrew_env = copy(ENV)
213+
homebrew_env["HOMEBREW_NO_AUTO_UPDATE"] = "1"
214+
homebrew_env["HOMEBREW_NO_INSTALL_CLEANUP"] = "1"
215+
homebrew_env["HOMEBREW_NO_ANALYTICS"] = "1"
216+
homebrew_env["HOMEBREW_CACHE"] = joinpath(local_homebrew_dir, "cache")
217+
homebrew_env["HOMEBREW_TEMP"] = joinpath(local_homebrew_dir, "temp")
218+
homebrew_env["TMPDIR"] = joinpath(local_homebrew_dir, "temp")
219+
220+
# Create cache and temp directories
221+
mkpath(homebrew_env["HOMEBREW_CACHE"])
222+
mkpath(homebrew_env["HOMEBREW_TEMP"])
223+
224+
withenv(homebrew_env) do
225+
run(`$local_brew_path update --force --quiet`)
226+
end
227+
catch e
228+
@warn "Homebrew post-install setup failed, but continuing: $e"
229+
end
230+
211231
@info "Local Homebrew installed successfully"
212232
end
213233

@@ -220,26 +240,65 @@ function install_coveralls_with_homebrew(brew_cmd, reporter_info, coveralls_path
220240
homebrew_type = use_local_homebrew ? "local Homebrew" : "system Homebrew"
221241
@info "Installing Coveralls reporter via $homebrew_type..."
222242

243+
# Set up environment for local Homebrew
244+
homebrew_env = copy(ENV)
245+
if use_local_homebrew
246+
local_homebrew_dir = dirname(dirname(brew_cmd)) # Get parent of bin directory
247+
homebrew_env["HOMEBREW_NO_AUTO_UPDATE"] = "1"
248+
homebrew_env["HOMEBREW_NO_INSTALL_CLEANUP"] = "1"
249+
homebrew_env["HOMEBREW_NO_ANALYTICS"] = "1"
250+
homebrew_env["HOMEBREW_CACHE"] = joinpath(local_homebrew_dir, "cache")
251+
homebrew_env["HOMEBREW_TEMP"] = joinpath(local_homebrew_dir, "temp")
252+
homebrew_env["TMPDIR"] = joinpath(local_homebrew_dir, "temp")
253+
homebrew_env["HOMEBREW_NO_BOTTLE_SOURCE_FALLBACK"] = "1"
254+
homebrew_env["HOMEBREW_FORCE_BREWED_CURL"] = "1"
255+
homebrew_env["HOMEBREW_NO_ENV_HINTS"] = "1"
256+
homebrew_env["HOMEBREW_QUIET"] = "1"
257+
258+
# Ensure directories exist
259+
mkpath(homebrew_env["HOMEBREW_CACHE"])
260+
mkpath(homebrew_env["HOMEBREW_TEMP"])
261+
262+
# Set additional permissions to handle CI environments
263+
try
264+
chmod(homebrew_env["HOMEBREW_CACHE"], 0o755)
265+
chmod(homebrew_env["HOMEBREW_TEMP"], 0o755)
266+
catch e
267+
@debug "Could not set directory permissions: $e"
268+
end
269+
end
270+
223271
# Add tap (ignore failures)
224272
try
225-
run(`$brew_cmd tap $(reporter_info.tap)`)
273+
withenv(homebrew_env) do
274+
run(`$brew_cmd tap $(reporter_info.tap)`)
275+
end
226276
catch e
227277
@debug "Tap command failed (possibly already exists): $e"
228278
end
229279

230280
# Install coveralls
231281
install_cmd = force ? "reinstall" : "install"
232282
try
233-
run(`$brew_cmd $install_cmd $(reporter_info.package)`)
283+
withenv(homebrew_env) do
284+
# For local Homebrew, try to install with more permissive settings
285+
if use_local_homebrew
286+
run(`$brew_cmd $install_cmd $(reporter_info.package) --force-bottle`)
287+
else
288+
run(`$brew_cmd $install_cmd $(reporter_info.package)`)
289+
end
290+
end
234291
catch e
235-
@debug "Install command failed (possibly already installed): $e"
292+
@error "Install command failed: $e"
293+
# Re-throw to let caller handle the error
294+
rethrow(e)
236295
end
237296

238297
# Verify installation
239298
if !isfile(coveralls_path)
240299
error("Coveralls installation failed - not found at: $coveralls_path")
241300
end
242-
301+
243302
@info "Coveralls reporter installed at: $coveralls_path"
244303
return coveralls_path
245304
end
@@ -297,7 +356,7 @@ function get_coveralls_executable(; auto_download=true, install_dir=nothing)
297356
# For macOS, check Homebrew installations
298357
if platform == :macos
299358
_, use_local_homebrew, local_homebrew_dir, _ = detect_homebrew_status()
300-
359+
301360
# Check system Homebrew if available
302361
if !use_local_homebrew
303362
system_brew_cmd = Sys.which("brew")
@@ -314,7 +373,7 @@ function get_coveralls_executable(; auto_download=true, install_dir=nothing)
314373
end
315374
end
316375
end
317-
376+
318377
# Check local Homebrew installation
319378
local_coveralls_path = joinpath(local_homebrew_dir, "bin", "coveralls")
320379
if isfile(local_coveralls_path)

0 commit comments

Comments
 (0)