Skip to content

Commit 0979d0d

Browse files
committed
install brew locally
Sadly, brew wants to run all of openssl tests in order to install locally, which is a huge percentage of the actual time (and size)
1 parent f5c2661 commit 0979d0d

File tree

4 files changed

+97
-27
lines changed

4 files changed

+97
-27
lines changed

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Coverage"
22
uuid = "a2441757-f6aa-5fb2-8edb-039e3f45d037"
3-
authors = ["Iain Dunning <[email protected]>", "contributors"]
43
version = "1.7.0"
4+
authors = ["Iain Dunning <[email protected]>", "contributors"]
55

66
[deps]
77
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
@@ -13,6 +13,7 @@ JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
1313
LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"
1414
MbedTLS = "739be429-bea8-5141-9913-cc70e7f3736d"
1515
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
16+
Scratch = "6c6a2e73-6563-6170-7368-637461726353"
1617

1718
[compat]
1819
ArgParse = "1"
@@ -23,6 +24,7 @@ HTTP = "0.8, 0.9, 1"
2324
JSON = "0.21"
2425
MbedTLS = "0.6, 0.7, 1"
2526
SHA = "0.7.0"
27+
Scratch = "1"
2628
julia = "1"
2729

2830
[extras]

src/Coverage.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ using Artifacts
88
using JSON
99
using HTTP
1010
using MbedTLS
11+
using Scratch
1112

1213
export FileCoverage
1314
export LCOV

src/codecov_functions.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ function download_codecov_uploader(; force=false, install_dir=nothing)
8383

8484
# Determine installation directory
8585
if install_dir === nothing
86-
install_dir = mktempdir(; prefix="codecov_uploader_", cleanup=false)
86+
# Use scratch space for persistent storage across sessions
87+
install_dir = @get_scratch!("codecov_uploader")
8788
else
8889
mkpath(install_dir)
8990
end

src/coveralls_functions.jl

Lines changed: 91 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -123,48 +123,113 @@ end
123123
install_via_homebrew(reporter_info; force=false)
124124
125125
Install Coveralls reporter via Homebrew (macOS).
126+
First installs a local Homebrew if needed, then installs coveralls locally.
126127
"""
127128
function install_via_homebrew(reporter_info; force=false)
128-
# Check if Homebrew is available
129-
brew_path = Sys.which("brew")
130-
if brew_path === nothing
131-
error("Homebrew is not installed. Please install Homebrew first: https://brew.sh")
129+
# Set up local Homebrew installation directory using scratch space
130+
local_homebrew_dir = @get_scratch!("local_homebrew")
131+
local_brew_path = joinpath(local_homebrew_dir, "bin", "brew")
132+
133+
# Use the local Homebrew installation
134+
brew_cmd = local_brew_path
135+
136+
# Check if local Homebrew is available, install if not
137+
if !isfile(local_brew_path)
138+
@info "Installing local Homebrew to: $local_homebrew_dir"
139+
try
140+
# Create the directory
141+
mkpath(local_homebrew_dir)
142+
143+
# Download and extract Homebrew tarball directly
144+
@info "Downloading latest Homebrew release..."
145+
146+
# Get the latest release info
147+
latest_release_url = "https://api.github.com/repos/Homebrew/brew/releases/latest"
148+
response = HTTP.get(latest_release_url)
149+
release_data = JSON.parse(String(response.body))
150+
latest_tag = release_data["tag_name"]
151+
tarball_url = release_data["tarball_url"]
152+
153+
@info "Found latest Homebrew release: $latest_tag"
154+
tarball_path = joinpath(local_homebrew_dir, "homebrew-$latest_tag.tar.gz")
155+
156+
# Download the tarball
157+
Downloads.download(tarball_url, tarball_path)
158+
159+
# Extract the tarball to our directory
160+
@info "Extracting Homebrew..."
161+
run(`tar -xzf $tarball_path -C $local_homebrew_dir --strip-components=1`; wait=true)
162+
163+
# Remove the tarball
164+
rm(tarball_path)
165+
166+
# Verify the brew executable exists
167+
if !isfile(local_brew_path)
168+
error("Homebrew extraction failed - brew executable not found at: $local_brew_path")
169+
end
170+
171+
# Post-install setup
172+
@info "Running Homebrew post-install setup..."
173+
run(`$brew_cmd update --force --quiet`; wait=true)
174+
175+
# Fix zsh permissions
176+
brew_prefix = chomp(read(`$brew_cmd --prefix`, String))
177+
zsh_share_dir = joinpath(brew_prefix, "share", "zsh")
178+
if isdir(zsh_share_dir)
179+
run(`chmod -R go-w $zsh_share_dir`; wait=true)
180+
end
181+
182+
@info "Local Homebrew installed successfully"
183+
catch e
184+
error("Failed to install local Homebrew: $e")
185+
end
186+
else
187+
@info "Local Homebrew found at: $local_brew_path"
132188
end
133189

134-
# Check if coveralls is already installed
190+
# Check if coveralls is already installed locally
135191
if !force
136-
coveralls_path = Sys.which("coveralls")
137-
if coveralls_path !== nothing && isfile(coveralls_path)
138-
@info "Coveralls reporter already installed via Homebrew at: $coveralls_path"
139-
return coveralls_path
192+
# Check for coveralls in the local Homebrew bin directory
193+
local_coveralls_path = joinpath(local_homebrew_dir, "bin", "coveralls")
194+
if isfile(local_coveralls_path)
195+
@info "Coveralls reporter already installed via local Homebrew at: $local_coveralls_path"
196+
return local_coveralls_path
140197
end
141198
end
142199

143-
@info "Installing Coveralls reporter via Homebrew..."
200+
@info "Installing Coveralls reporter via local Homebrew..."
144201

145202
try
146-
# Add the tap if it doesn't exist
203+
# Add the tap if it doesn't exist (ignore failures)
147204
@info "Adding Homebrew tap: $(reporter_info.tap)"
148-
run(`brew tap $(reporter_info.tap)`; wait=true)
205+
try
206+
run(`$brew_cmd tap $(reporter_info.tap)`; wait=true)
207+
catch e
208+
@debug "Tap command failed (possibly already exists): $e"
209+
end
149210

150-
# Install coveralls
211+
# Install coveralls (ignore exit status)
151212
@info "Installing Coveralls reporter..."
152-
if force
153-
run(`brew reinstall $(reporter_info.package)`; wait=true)
154-
else
155-
run(`brew install $(reporter_info.package)`; wait=true)
213+
try
214+
if force
215+
run(`$brew_cmd reinstall $(reporter_info.package)`; wait=true)
216+
else
217+
run(`$brew_cmd install $(reporter_info.package)`; wait=true)
218+
end
219+
catch e
220+
@debug "Install command failed (possibly already installed): $e"
156221
end
157222

158-
# Get the installed path
159-
coveralls_path = Sys.which("coveralls")
160-
if coveralls_path === nothing
161-
error("Coveralls installation failed - command not found in PATH")
223+
# Check if the binary exists regardless of install command status
224+
local_coveralls_path = joinpath(local_homebrew_dir, "bin", "coveralls")
225+
if !isfile(local_coveralls_path)
226+
error("Coveralls installation failed - not found at expected path: $local_coveralls_path")
162227
end
163-
@info "Coveralls reporter installed at: $coveralls_path"
164-
return coveralls_path
228+
@info "Coveralls reporter installed locally at: $local_coveralls_path"
229+
return local_coveralls_path
165230

166231
catch e
167-
error("Failed to install Coveralls reporter via Homebrew: $e")
232+
error("Failed to install Coveralls reporter via local Homebrew: $e")
168233
end
169234
end
170235

@@ -176,7 +241,8 @@ Install Coveralls reporter via direct download (Linux/Windows).
176241
function install_via_download(reporter_info, platform; force=false, install_dir=nothing)
177242
# Determine installation directory
178243
if install_dir === nothing
179-
install_dir = mktempdir(; prefix="coveralls_reporter_", cleanup=false)
244+
# Use scratch space for persistent storage across sessions
245+
install_dir = @get_scratch!("coveralls_reporter")
180246
else
181247
mkpath(install_dir)
182248
end

0 commit comments

Comments
 (0)