Class: HomebrewAutomation::Workflow

Inherits:
Object
  • Object
show all
Defined in:
lib/homebrew_automation/workflow.rb

Overview

Imperative glue code.

Each method in this class probably makes sense to be exposed as a CLI command.

Instance Method Summary collapse

Instance Method Details

#build_and_upload_bottle!(sdist, tap, git, formula_name, bversion, logger, mac_os: MacOS, bottle: Bottle, keep_tap_repo: false, keep_homebrew_tmp: false) ⇒ Bottle

Build and upload a bottle.

The built Bottle tarball gets uploaded to Bintray.

Parameters:

  • sdist (SourceDist)
  • tap (Tap)
  • formula_name (String)

    the name of the formula in the Tap

  • bversion (Bintray::Version)
  • logger (HomebrewAutomation::Logger)
  • mac_os (Class) (defaults to: MacOS)

    the MacOS class

  • bottle (Class) (defaults to: Bottle)

    the Bottle class

  • keep_homebrew_tmp (Boolean) (defaults to: false)

    keep the HOMEBREW_TEMP directory

Returns:



30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
# File 'lib/homebrew_automation/workflow.rb', line 30

def build_and_upload_bottle!(
    sdist,
    tap,
    git,
    formula_name,
    bversion,
    logger,
    mac_os: MacOS,
    bottle: Bottle,
    keep_tap_repo: false,
    keep_homebrew_tmp: false)
  logger.info!(
    "Hello, this is HomebrewAutomation! I will now build your Formula and upload the " \
    "bottles to Bintray.")
  os_name = mac_os.identify_version!
  logger.info!("First let's clone your Tap repo to see the Formula.")
  # TODO: What if repo already exists?
  git.with_clone!(tap.url, tap.repo, keep_dir: keep_tap_repo) do |cloned_dir|
    tap.on_formula! formula_name do |formula|
      formula.put_sdist(sdist.url, sdist.sha256)
    end
    git.commit_am! "Throwaway commit; just for building bottles"
    logger.info!(
      "I've updated the Formula file in our local Tap clone, and we're ready "\
      "to start building the Bottle. This could take a long time if your Formula "\
      "is slow to compile.")
    bot = bottle.new(
      'homebrew-automation/tmp-tap',
      cloned_dir,
      formula_name,
      os_name,
      keep_tmp: keep_homebrew_tmp)
    bot.build! do |filename, contents|
      # Bintray auto-creates Versions on file-upload.
      # Re-creating an existing Version results in a 409.
      #bversion.create!
      logger.info!("Bottle built! Let me now upload the Bottle tarball to Bintray.")
      begin
        bversion.upload_file!(filename, contents)
      rescue Bintray::Version::FileAlreadyExists
        logger.info!("A file with the same name as the one we're uploading already exits on Bintray.")
      end
    end
    bot
  end
  logger.info!("All done!")
rescue HomebrewAutomation::Bottle::Error => e
  logger.error!([
    "Something went wrong in a Bottle: " + e.message,
    "Original JSON:",
    e.original
  ].join("\n"))
  raise
rescue HomebrewAutomation::Brew::UninstallFailed => e
  logger.error!("brew uninstall failed: #{e}")
  raise
rescue HomebrewAutomation::Brew::InstallFailed => e
  logger.error!("brew install failed: #{e}")
  raise
rescue HomebrewAutomation::Brew::Error => e
  logger.error!("Something went wrong in this Homebrew command: #{e}")
  raise
rescue HomebrewAutomation::Git::Error => e
  logger.error!("Something went wrong in this Git command: #{e}")
  raise
rescue HomebrewAutomation::SourceDist::SdistDoesNotExist => e
  logger.error!(
    "The tar file from Github you named doesn't exist. " +
    "Is it because you haven't pushed that tag to Github yet?")
  raise
end

#gather_and_publish_bottles!(sdist, tap, formula_name, bversion, git, logger) ⇒ NilClass

Gather and publish bottles.

Look around on Bintray to see what Bottles we’ve already built and uploaded (as such “gathering” the bottles), then push new commits into the #tap repository to make an existing Formula aware of the Bottles we’re gathered (as such “publishing” the bottles).

Parameters:

Returns:

  • (NilClass)


116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/homebrew_automation/workflow.rb', line 116

def gather_and_publish_bottles!(sdist, tap, formula_name, bversion, git, logger)
  logger.info!(
    "Hello, this is HomebrewAutomation! I will browse through your Bintray to " \
    "see if there may be Bottles built earlier for your Formula, and update your " \
    "Tap to refer to them.")
  logger.info!(
    "I will also update the source tarball of your Formula in your Tap, " \
    "effectively releasing a new version of your Formula.")
  git.with_clone!(tap.url, tap.repo) do
    tap.on_formula! formula_name do |formula|
      logger.info!("Let's see if any files on your Bintray look like Bottles.")
      bottles = bversion.gather_bottles
      logger.info!("Found bottles: #{bottles}")
      bottles.reduce(
        formula.
        put_sdist(sdist.url, sdist.sha256).
        rm_all_bottles
      ) do |f, (os, checksum)|
        f.put_bottle(os, checksum)
      end
    end
    git.config!
    git.commit_am! "Add bottles for #{formula_name}@#{bversion.version_name}"
    logger.info!("I've refered to the Bottles I found in this new commit. Let's push to your Tap!")
    git.push!
  end
  logger.info!("All done!")
end