Merge pull request #19579 from Homebrew/bundle_version_file
Add `version_file:` DSL to `Brewfile`
This commit is contained in:
commit
2dbce6bac5
@ -82,6 +82,34 @@ module Homebrew
|
|||||||
|
|
||||||
return_value
|
return_value
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def formula_versions_from_env
|
||||||
|
@formula_versions_from_env ||= begin
|
||||||
|
formula_versions = {}
|
||||||
|
|
||||||
|
ENV.each do |key, value|
|
||||||
|
match = key.match(/^HOMEBREW_BUNDLE_EXEC_FORMULA_VERSION_(.+)$/)
|
||||||
|
next if match.blank?
|
||||||
|
|
||||||
|
formula_name = match[1]
|
||||||
|
next if formula_name.blank?
|
||||||
|
|
||||||
|
ENV.delete(key)
|
||||||
|
formula_versions[formula_name.downcase] = value
|
||||||
|
end
|
||||||
|
|
||||||
|
formula_versions
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
sig { void }
|
||||||
|
def reset!
|
||||||
|
@mas_installed = nil
|
||||||
|
@vscode_installed = nil
|
||||||
|
@whalebrew_installed = nil
|
||||||
|
@cask_installed = nil
|
||||||
|
@formula_versions_from_env = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -27,6 +27,7 @@ module Homebrew
|
|||||||
@start_service = options.fetch(:start_service, @restart_service)
|
@start_service = options.fetch(:start_service, @restart_service)
|
||||||
@link = options.fetch(:link, nil)
|
@link = options.fetch(:link, nil)
|
||||||
@postinstall = options.fetch(:postinstall, nil)
|
@postinstall = options.fetch(:postinstall, nil)
|
||||||
|
@version_file = options.fetch(:version_file, nil)
|
||||||
@changed = nil
|
@changed = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -57,6 +58,19 @@ module Homebrew
|
|||||||
|
|
||||||
postinstall_result = postinstall_change_state!(verbose:)
|
postinstall_result = postinstall_change_state!(verbose:)
|
||||||
result &&= postinstall_result
|
result &&= postinstall_result
|
||||||
|
|
||||||
|
if result && @version_file.present?
|
||||||
|
# Use the version from the environment if it hasn't changed.
|
||||||
|
version = if !changed? && (env_version = Bundle.formula_versions_from_env[@name])
|
||||||
|
env_version
|
||||||
|
else
|
||||||
|
Formula[@full_name].version.to_s
|
||||||
|
end
|
||||||
|
version_path = Pathname.new(@version_file)
|
||||||
|
version_path.write("#{version}\n")
|
||||||
|
|
||||||
|
puts "Wrote #{@name} version #{version} to #{@version_file}" if verbose
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
result
|
result
|
||||||
|
|||||||
@ -108,18 +108,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Replace the formula versions from the environment variables
|
# Replace the formula versions from the environment variables
|
||||||
formula_versions = {}
|
Bundle.formula_versions_from_env.each do |formula_name, formula_version|
|
||||||
ENV.each do |key, value|
|
|
||||||
match = key.match(/^HOMEBREW_BUNDLE_EXEC_FORMULA_VERSION_(.+)$/)
|
|
||||||
next if match.blank?
|
|
||||||
|
|
||||||
formula_name = match[1]
|
|
||||||
next if formula_name.blank?
|
|
||||||
|
|
||||||
ENV.delete(key)
|
|
||||||
formula_versions[formula_name.downcase] = value
|
|
||||||
end
|
|
||||||
formula_versions.each do |formula_name, formula_version|
|
|
||||||
ENV.each do |key, value|
|
ENV.each do |key, value|
|
||||||
opt = %r{/opt/#{formula_name}([/:$])}
|
opt = %r{/opt/#{formula_name}([/:$])}
|
||||||
next unless value.match(opt)
|
next unless value.match(opt)
|
||||||
|
|||||||
@ -29,6 +29,7 @@ RSpec.describe Homebrew::Bundle::Commands::Exec do
|
|||||||
context "with valid command setup" do
|
context "with valid command setup" do
|
||||||
before do
|
before do
|
||||||
allow(described_class).to receive(:exec).and_return(nil)
|
allow(described_class).to receive(:exec).and_return(nil)
|
||||||
|
Homebrew::Bundle.reset!
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not raise an error" do
|
it "does not raise an error" do
|
||||||
|
|||||||
@ -40,6 +40,8 @@ brew "mysql@5.6", restart_service: :changed, link: true, conflicts_with: ["mysql
|
|||||||
# 'brew install' and run a command if installer or upgraded.
|
# 'brew install' and run a command if installer or upgraded.
|
||||||
brew "postgresql@16",
|
brew "postgresql@16",
|
||||||
postinstall: "${HOMEBREW_PREFIX}/opt/postgresql@16/bin/postgres -D ${HOMEBREW_PREFIX}/var/postgresql@16"
|
postinstall: "${HOMEBREW_PREFIX}/opt/postgresql@16/bin/postgres -D ${HOMEBREW_PREFIX}/var/postgresql@16"
|
||||||
|
# 'brew install' and write the installed version to the '.ruby-version' file.
|
||||||
|
brew "ruby", version_file: ".ruby-version"
|
||||||
# install only on specified OS
|
# install only on specified OS
|
||||||
brew "gnupg" if OS.mac?
|
brew "gnupg" if OS.mac?
|
||||||
brew "glibc" if OS.linux?
|
brew "glibc" if OS.linux?
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user