Class: Homebrew::DevCmd::PrUpload

Inherits:
AbstractCommand show all
Defined in:
dev-cmd/pr-upload.rb

Instance Attribute Summary

Attributes inherited from AbstractCommand

#args

Instance Method Summary collapse

Methods inherited from AbstractCommand

command, command_name, #initialize, parser

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#runvoid

This method returns an undefined value.



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
# File 'dev-cmd/pr-upload.rb', line 44

def run
  json_files = Dir["*.bottle.json"]
  odie "No bottle JSON files found in the current working directory" if json_files.blank?
  bottles_hash = bottles_hash_from_json_files(json_files, args)

  Homebrew.install_bundler_gems!(groups: ["pr_upload"])

  unless args.upload_only?
    bottle_args = ["bottle", "--merge", "--write"]
    bottle_args << "--verbose" if args.verbose?
    bottle_args << "--debug" if args.debug?
    bottle_args << "--keep-old" if args.keep_old?
    bottle_args << "--root-url=#{args.root_url}" if args.root_url
    bottle_args << "--committer=#{args.committer}" if args.committer
    bottle_args << "--no-commit" if args.no_commit?
    bottle_args << "--root-url-using=#{args.root_url_using}" if args.root_url_using
    bottle_args += json_files

    if args.dry_run?
      dry_run_service = if github_packages?(bottles_hash)
        # GitHub Packages has its own --dry-run handling.
        nil
      elsif github_releases?(bottles_hash)
        "GitHub Releases"
      else
        odie "Service specified by root_url is not recognized"
      end

      if dry_run_service
        puts <<~EOS
          brew #{bottle_args.join " "}
          Upload bottles described by these JSON files to #{dry_run_service}:
            #{json_files.join("\n  ")}
        EOS
        return
      end
    end

    check_bottled_formulae!(bottles_hash)

    safe_system HOMEBREW_BREW_FILE, *bottle_args

    json_files = Dir["*.bottle.json"]
    if json_files.blank?
      puts "No bottle JSON files after merge, no upload needed!"
      return
    end

    # Reload the JSON files (in case `brew bottle --merge` generated
    # `all: $SHA256` bottles)
    bottles_hash = bottles_hash_from_json_files(json_files, args)

    # Check the bottle commits did not break `brew audit`
    unless args.no_commit?
      audit_args = ["audit", "--skip-style"]
      audit_args << "--verbose" if args.verbose?
      audit_args << "--debug" if args.debug?
      audit_args += bottles_hash.keys
      safe_system HOMEBREW_BREW_FILE, *audit_args
    end
  end

  if github_releases?(bottles_hash)
    github_releases = GitHubReleases.new
    github_releases.upload_bottles(bottles_hash)
  elsif github_packages?(bottles_hash)
    github_packages = GitHubPackages.new
    github_packages.upload_bottles(bottles_hash,
                                   keep_old:      args.keep_old?,
                                   dry_run:       args.dry_run?,
                                   warn_on_error: args.warn_on_upload_failure?)
  else
    odie "Service specified by root_url is not recognized"
  end
end