lib/homebrew_automation/workflow.rb
# Build and upload a bottle.
#
# The built Bottle tarball gets uploaded to Bintray.
#
# @param sdist [SourceDist]
# @param tap [Tap]
# @param formula_name [String] the name of the formula in the Tap
# @param bversion [Bintray::Version]
# @param logger [HomebrewAutomation::Logger]
#
# @param mac_os [Class] the MacOS class
# @param bottle [Class] the Bottle class
# @param keep_homebrew_tmp [Boolean] keep the HOMEBREW_TEMP directory
#
# @return [Bottle]
Build and upload a bottle.
The built Bottle tarball gets uploaded to Bintray.
Build and upload a bottle . The built Bottle tarball gets uploaded to Bintray .
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.")
      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|
          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
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." ) 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 | 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
Build and upload a bottle.
Build and upload a bottle .
# TODO: What if repo already exists? # Bintray auto-creates Versions on file-upload. # Re-creating an existing Version results in a 409. #bversion.create!
None
Bottle
sdist
tap
git
formula_name
the name of the formula in the Tap
the name of the formula in the Tap
bversion
logger
mac_os
the MacOS class
the MacOS class
bottle
the Bottle class
the Bottle class
keep_tap_repo
keep_homebrew_tmp
keep the HOMEBREW_TEMP directory
keep the HOMEBREW_TEMP directory
None