vendor-gems.rb 1.25 KB
Newer Older
1
# typed: false
2
3
# frozen_string_literal: true

Mike McQuaid's avatar
Mike McQuaid committed
4
require "formula"
5
require "cli/parser"
Mike McQuaid's avatar
Mike McQuaid committed
6
7

module Homebrew
Markus Reiter's avatar
Markus Reiter committed
8
9
  extend T::Sig

Mike McQuaid's avatar
Mike McQuaid committed
10
11
  module_function

Markus Reiter's avatar
Markus Reiter committed
12
  sig { returns(CLI::Parser) }
13
  def vendor_gems_args
Mike McQuaid's avatar
Mike McQuaid committed
14
15
16
17
18
19
    Homebrew::CLI::Parser.new do
      usage_banner <<~EOS
        `vendor-gems`

        Install and commit Homebrew's vendored gems.
      EOS
Markus Reiter's avatar
Markus Reiter committed
20

21
22
      comma_array "--update",
                  description: "Update all vendored Gems to the latest version."
23

24
      max_named 0
25
26
27
    end
  end

28
  sig { void }
29
  def vendor_gems
30
    args = vendor_gems_args.parse
Mike McQuaid's avatar
Mike McQuaid committed
31

32
    Homebrew.install_bundler!
Mike McQuaid's avatar
Mike McQuaid committed
33

34
    ohai "cd #{HOMEBREW_LIBRARY_PATH}"
35
    HOMEBREW_LIBRARY_PATH.cd do
36
      if args.update
37
        ohai "bundle update"
38
        safe_system "bundle", "update", *args.update
39
40
41
42
43

        ohai "git add Gemfile.lock"
        system "git", "add", "Gemfile.lock"
      end

Mike McQuaid's avatar
Mike McQuaid committed
44
45
46
      ohai "bundle install --standalone"
      safe_system "bundle", "install", "--standalone"

47
48
49
      ohai "bundle pristine"
      safe_system "bundle", "pristine"

50
51
      ohai "git add vendor/bundle"
      system "git", "add", "vendor/bundle"
Mike McQuaid's avatar
Mike McQuaid committed
52

53
54
      Utils::Git.set_name_email!
      Utils::Git.setup_gpg!
Mike McQuaid's avatar
Mike McQuaid committed
55
56
57
58
59
60

      ohai "git commit"
      system "git", "commit", "--message", "brew vendor-gems: commit updates."
    end
  end
end