build-buddy 1.9.2 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/build-buddy +1 -6
- data/lib/build_buddy.rb +1 -1
- data/lib/build_buddy/builder.rb +95 -22
- data/lib/build_buddy/config.rb +4 -3
- data/lib/build_buddy/scheduler.rb +2 -4
- data/lib/build_buddy/slacker.rb +9 -15
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 2a8a7992124d1da142da38648ea45d39b805582f
         | 
| 4 | 
            +
              data.tar.gz: 6785a428216e7499fc90d437692715f3442434b2
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 1b789719672f1d11b0bf637063db822d66a4867d2f430e478cf7a6c212209081b2a3e00e95bcad838a220eca323142a39edc35c5fadc07e887825b820861c01d
         | 
| 7 | 
            +
              data.tar.gz: 05299a51f399a428f3038f1da2de44edc9b9d671d65a7cdc9b8009f035a9173e356ae35d94b79b7aaf994bb69041ffa6e72d22ccc214f5261abf82ce5664b410
         | 
    
        data/bin/build-buddy
    CHANGED
    
    | @@ -22,12 +22,7 @@ module BuildBuddy | |
| 22 22 | 
             
                  load config_file_name
         | 
| 23 23 |  | 
| 24 24 | 
             
                  config_path = File.dirname(config_file_name)
         | 
| 25 | 
            -
                   | 
| 26 | 
            -
                  Config.master_build_script = File.expand_path(Config.master_build_script, config_path)
         | 
| 27 | 
            -
                  Config.release_build_script = File.expand_path(Config.release_build_script, config_path)
         | 
| 28 | 
            -
                  Config.build_log_dir = File.expand_path(Config.build_log_dir, config_path)
         | 
| 29 | 
            -
             | 
| 30 | 
            -
                  build_log_dir = BuildBuddy::Config.build_log_dir
         | 
| 25 | 
            +
                  build_log_dir = File.expand_path(Config.build_log_dir, config_path)
         | 
| 31 26 |  | 
| 32 27 | 
             
                  unless Dir.exist?(build_log_dir)
         | 
| 33 28 | 
             
                    Dir.mkdir(build_log_dir)
         | 
    
        data/lib/build_buddy.rb
    CHANGED
    
    
    
        data/lib/build_buddy/builder.rb
    CHANGED
    
    | @@ -2,6 +2,7 @@ require 'rubygems' | |
| 2 2 | 
             
            require 'bundler'
         | 
| 3 3 | 
             
            require 'celluloid'
         | 
| 4 4 | 
             
            require 'psych'
         | 
| 5 | 
            +
            require 'fileutils'
         | 
| 5 6 | 
             
            require_relative './watcher.rb'
         | 
| 6 7 | 
             
            require_relative './config.rb'
         | 
| 7 8 |  | 
| @@ -18,51 +19,123 @@ module BuildBuddy | |
| 18 19 | 
             
                end
         | 
| 19 20 |  | 
| 20 21 | 
             
                def start_build(build_data)
         | 
| 22 | 
            +
                  def expand_vars(s)
         | 
| 23 | 
            +
                    s.gsub(/\$([a-zA-Z_]+[a-zA-Z0-9_]*)|\$\{(.+)\}/) { ENV[$1||$2] }
         | 
| 24 | 
            +
                  end
         | 
| 25 | 
            +
             | 
| 21 26 | 
             
                  @build_data = build_data
         | 
| 22 27 | 
             
                  @metrics_tempfile = Tempfile.new('build-metrics')
         | 
| 23 28 | 
             
                  @metrics_tempfile.close()
         | 
| 24 29 |  | 
| 25 30 | 
             
                  repo_parts = build_data.repo_full_name.split('/')
         | 
| 26 | 
            -
                   | 
| 27 | 
            -
                   | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 31 | 
            +
                  git_repo_owner = repo_parts[0]
         | 
| 32 | 
            +
                  git_repo_name = repo_parts[1]
         | 
| 33 | 
            +
                  env = {}
         | 
| 34 | 
            +
                  build_script = %q(#!/bin/bash
         | 
| 35 | 
            +
             | 
| 36 | 
            +
            if [[ -z "$GIT_REPO_OWNER" || -z "$GIT_REPO_NAME" || -z "$BUILD_SCRIPT" ]]; then
         | 
| 37 | 
            +
              echo Must set GIT_REPO_OWNER, GIT_REPO_NAME, GIT_PULL_REQUEST and BUILD_SCRIPT before calling
         | 
| 38 | 
            +
              exit 1
         | 
| 39 | 
            +
            fi
         | 
| 40 | 
            +
            )
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                  case build_data.type
         | 
| 43 | 
            +
                  when :pull_request
         | 
| 44 | 
            +
                      build_script += %q(
         | 
| 45 | 
            +
            if [[ -z "$GIT_PULL_REQUEST" ]]; then
         | 
| 46 | 
            +
              echo Must set GIT_PULL_REQUEST before calling
         | 
| 47 | 
            +
            fi
         | 
| 48 | 
            +
            )
         | 
| 49 | 
            +
                  when :branch
         | 
| 50 | 
            +
                    build_script += %q(
         | 
| 51 | 
            +
            if [[ -z "$GIT_BRANCH" ]]; then
         | 
| 52 | 
            +
              echo Must set GIT_BRANCH before calling
         | 
| 53 | 
            +
            fi
         | 
| 54 | 
            +
            )
         | 
| 55 | 
            +
                  else
         | 
| 56 | 
            +
                    raise "Unknown build type"
         | 
| 57 | 
            +
                  end
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                  build_script += %q(
         | 
| 60 | 
            +
            if [[ -d ${GIT_REPO_NAME} ]]; then
         | 
| 61 | 
            +
              echo WARNING: Deleting old clone directory $(pwd)/${GIT_REPO_NAME}
         | 
| 62 | 
            +
              rm -rf ${GIT_REPO_NAME}
         | 
| 63 | 
            +
            fi
         | 
| 64 | 
            +
             | 
| 65 | 
            +
            echo Pulling sources to $(pwd)/${GIT_REPO_NAME}
         | 
| 66 | 
            +
            if ! git clone git@github.com:${GIT_REPO_OWNER}/${GIT_REPO_NAME}.git ${GIT_REPO_NAME}; then
         | 
| 67 | 
            +
              echo ERROR: Unable to clone repository
         | 
| 68 | 
            +
              exit 1
         | 
| 69 | 
            +
            fi
         | 
| 70 | 
            +
             | 
| 71 | 
            +
            cd ${GIT_REPO_NAME}
         | 
| 72 | 
            +
            )
         | 
| 73 | 
            +
             | 
| 74 | 
            +
                  case build_data.type
         | 
| 75 | 
            +
                  when :pull_request
         | 
| 76 | 
            +
                    build_root_dir = expand_vars(Config.pull_request_root_dir)
         | 
| 77 | 
            +
                    env.merge!({
         | 
| 78 | 
            +
                      "GIT_PULL_REQUEST" => build_data.pull_request.to_s,
         | 
| 79 | 
            +
                      "BUILD_SCRIPT" => Config.pull_request_build_script
         | 
| 80 | 
            +
                    })
         | 
| 81 | 
            +
                    # See https://gist.github.com/piscisaureus/3342247
         | 
| 82 | 
            +
                    build_script += %q(
         | 
| 83 | 
            +
            echo Switching to pr/${GIT_PULL_REQUEST} branch
         | 
| 84 | 
            +
            git config --add remote.origin.fetch '+refs/pull/*/head:refs/remotes/origin/pr/*'
         | 
| 85 | 
            +
            git fetch -q origin
         | 
| 86 | 
            +
            git checkout pr/$GIT_PULL_REQUEST
         | 
| 87 | 
            +
            )
         | 
| 88 | 
            +
                  when :branch
         | 
| 89 | 
            +
                    build_root_dir = expand_vars(Config.branch_root_dir)
         | 
| 90 | 
            +
                    env.merge!({
         | 
| 91 | 
            +
                      "GIT_BRANCH" => 'master',
         | 
| 92 | 
            +
                      "BUILD_SCRIPT" => Config.branch_build_script
         | 
| 93 | 
            +
                    })
         | 
| 94 | 
            +
                    build_script += %q(
         | 
| 95 | 
            +
            echo Switching to ${GIT_BRANCH} branch
         | 
| 96 | 
            +
            git checkout ${GIT_BRANCH}
         | 
| 97 | 
            +
            )
         | 
| 98 | 
            +
                  end
         | 
| 99 | 
            +
             | 
| 100 | 
            +
                  build_script += %q(
         | 
| 101 | 
            +
            source ${BUILD_SCRIPT}
         | 
| 102 | 
            +
            )
         | 
| 103 | 
            +
                  env.merge!({
         | 
| 104 | 
            +
                      "GIT_REPO_OWNER" => git_repo_owner,
         | 
| 105 | 
            +
                      "GIT_REPO_NAME" => git_repo_name,
         | 
| 30 106 | 
             
                      "METRICS_DATA_FILE" => @metrics_tempfile.path,
         | 
| 31 107 | 
             
                      "RBENV_DIR" => nil,
         | 
| 32 108 | 
             
                      "RBENV_VERSION" => nil,
         | 
| 33 109 | 
             
                      "RBENV_HOOK_PATH" => nil,
         | 
| 34 110 | 
             
                      "RBENV_ROOT" => nil,
         | 
| 35 | 
            -
                      "PATH" => ENV['PATH'].split(':').select { |v| !v.match(/\.rbenv\/versions|Cellar\/rbenv/) }.join(':')
         | 
| 36 | 
            -
                  }
         | 
| 111 | 
            +
                      "PATH" => ENV['PATH'].split(':').select { |v| !v.match(/\.rbenv\/versions|Cellar\/rbenv/) }.join(':'),
         | 
| 112 | 
            +
                  })
         | 
| 113 | 
            +
             | 
| 37 114 | 
             
                  unless build_data.flags.nil?
         | 
| 38 115 | 
             
                    build_data.flags.each do |flag|
         | 
| 39 116 | 
             
                     env["BUILD_FLAG_#{flag.to_s.upcase}"] = '1'
         | 
| 40 117 | 
             
                    end
         | 
| 41 118 | 
             
                  end
         | 
| 42 119 |  | 
| 43 | 
            -
                  case build_data.type
         | 
| 44 | 
            -
                    when :pull_request
         | 
| 45 | 
            -
                      env["GIT_PULL_REQUEST"] = build_data.pull_request.to_s
         | 
| 46 | 
            -
                      command += Config.pull_request_build_script
         | 
| 47 | 
            -
                    when :master
         | 
| 48 | 
            -
                      command += Config.master_build_script
         | 
| 49 | 
            -
                    when :release
         | 
| 50 | 
            -
                      env["GIT_BRANCH"] = build_data.branch
         | 
| 51 | 
            -
                      command += Config.release_build_script
         | 
| 52 | 
            -
                    else
         | 
| 53 | 
            -
                      raise "Unknown build type"
         | 
| 54 | 
            -
                  end
         | 
| 55 | 
            -
             | 
| 56 120 | 
             
                  @build_data.start_time = Time.now.utc
         | 
| 57 | 
            -
                  log_filename = File.join(Config.build_log_dir,
         | 
| 121 | 
            +
                  log_filename = File.join(File.expand_path(Config.build_log_dir),
         | 
| 58 122 | 
             
                    "build_#{build_data.type.to_s}_#{build_data.start_time.strftime('%Y%m%d_%H%M%S')}.log")
         | 
| 59 123 | 
             
                  @build_data.log_filename = log_filename
         | 
| 60 124 |  | 
| 125 | 
            +
                  # Ensure build root and git user directory exists
         | 
| 126 | 
            +
                  clone_dir = File.join(build_root_dir, git_repo_owner)
         | 
| 127 | 
            +
                  FileUtils.mkdir_p(clone_dir)
         | 
| 128 | 
            +
             | 
| 129 | 
            +
                  # Write the bootstrapping build script to it
         | 
| 130 | 
            +
                  script_filename = File.join(clone_dir, "build-buddy-bootstrap.sh")
         | 
| 131 | 
            +
                  File.write(script_filename, build_script)
         | 
| 132 | 
            +
             | 
| 133 | 
            +
                  # Run the build script
         | 
| 61 134 | 
             
                  Bundler.with_clean_env do
         | 
| 62 | 
            -
                    @pid = Process.spawn(env,  | 
| 135 | 
            +
                    @pid = Process.spawn(env, "bash #{script_filename}", :pgroup => true, :chdir => clone_dir, [:out, :err] => log_filename)
         | 
| 63 136 | 
             
                    @gid = Process.getpgid(@pid)
         | 
| 64 137 | 
             
                  end
         | 
| 65 | 
            -
                  info "Running  | 
| 138 | 
            +
                  info "Running build script (pid #{@pid}, gid #{@gid}) : Log #{log_filename}"
         | 
| 66 139 |  | 
| 67 140 | 
             
                  if @watcher
         | 
| 68 141 | 
             
                    @watcher.terminate
         | 
    
        data/lib/build_buddy/config.rb
    CHANGED
    
    | @@ -14,9 +14,10 @@ module BuildBuddy | |
| 14 14 | 
             
                attr_accessor :xcode_test_scheme
         | 
| 15 15 | 
             
                attr_accessor :build_log_dir
         | 
| 16 16 | 
             
                attr_accessor :pull_request_build_script
         | 
| 17 | 
            -
                attr_accessor : | 
| 18 | 
            -
                attr_accessor : | 
| 19 | 
            -
                attr_accessor : | 
| 17 | 
            +
                attr_accessor :branch_build_script
         | 
| 18 | 
            +
                attr_accessor :pull_request_root_dir
         | 
| 19 | 
            +
                attr_accessor :branch_root_dir
         | 
| 20 | 
            +
                attr_accessor :allowed_build_branches
         | 
| 20 21 | 
             
                attr_accessor :kill_build_after_mins
         | 
| 21 22 | 
             
                attr_accessor :server_base_uri
         | 
| 22 23 | 
             
                attr_accessor :mongo_uri
         | 
| @@ -25,10 +25,8 @@ module BuildBuddy | |
| 25 25 | 
             
                      Celluloid::Actor[:gitter].async.set_status(
         | 
| 26 26 | 
             
                          build_data.repo_full_name, build_data.repo_sha, :pending, "This build is in the queue")
         | 
| 27 27 | 
             
                      info "Pull request build queued"
         | 
| 28 | 
            -
                    when : | 
| 29 | 
            -
                      info " | 
| 30 | 
            -
                    when :release
         | 
| 31 | 
            -
                      info "Release branch build queued"
         | 
| 28 | 
            +
                    when :branch
         | 
| 29 | 
            +
                      info "'#{build_data.branch}' branch build queued"
         | 
| 32 30 | 
             
                  end
         | 
| 33 31 |  | 
| 34 32 | 
             
                  if @build_timer.nil?
         | 
    
        data/lib/build_buddy/slacker.rb
    CHANGED
    
    | @@ -56,21 +56,22 @@ module BuildBuddy | |
| 56 56 | 
             
                      flags = Slacker.get_build_flags($~[:flags])
         | 
| 57 57 | 
             
                      response = "OK, I've queued a build of the `master` branch."
         | 
| 58 58 | 
             
                      scheduler.queue_a_build(BuildData.new(
         | 
| 59 | 
            -
                          :type => : | 
| 59 | 
            +
                          :type => :branch,
         | 
| 60 | 
            +
                          :branch => 'master',
         | 
| 60 61 | 
             
                          :flags => flags,
         | 
| 61 62 | 
             
                          :repo_full_name => Config.github_webhook_repo_full_name))
         | 
| 62 63 | 
             
                    when /^(?<version>v\d+\.\d+)(?: with )?(?<flags>.*)?/
         | 
| 63 64 | 
             
                      flags = Slacker.get_build_flags($~[:flags])
         | 
| 64 65 | 
             
                      version = $~[:version]
         | 
| 65 | 
            -
                      if Config. | 
| 66 | 
            +
                      if Config.allowed_build_branches.include?(version)
         | 
| 66 67 | 
             
                        response = "OK, I've queued a build of the `#{version}` branch."
         | 
| 67 68 | 
             
                        scheduler.queue_a_build(BuildData.new(
         | 
| 68 | 
            -
                            :type => : | 
| 69 | 
            +
                            :type => :branch,
         | 
| 69 70 | 
             
                            :branch => version,
         | 
| 70 71 | 
             
                            :flags => flags,
         | 
| 71 72 | 
             
                            :repo_full_name => Config.github_webhook_repo_full_name))
         | 
| 72 73 | 
             
                      else
         | 
| 73 | 
            -
                        response = "I'm sorry, I am not allowed to build the `#{version}`  | 
| 74 | 
            +
                        response = "I'm sorry, I am not allowed to build the `#{version}` branch"
         | 
| 74 75 | 
             
                      end
         | 
| 75 76 | 
             
                    else
         | 
| 76 77 | 
             
                      response = "Sorry#{from_slack_channel ? " <@#{data['user']}>" : ""}, I'm not sure if you want do a `master` or release branch build"
         | 
| @@ -107,9 +108,7 @@ module BuildBuddy | |
| 107 108 | 
             
                    case build_data.type
         | 
| 108 109 | 
             
                    when :pull_request
         | 
| 109 110 | 
             
                      response = "There is a pull request build in progress for https://github.com/#{build_data.repo_full_name}/pull/#{build_data.pull_request}."
         | 
| 110 | 
            -
                    when : | 
| 111 | 
            -
                      response = "There is a build of the `master` branch of https://github.com/#{build_data.repo_full_name} in progress."
         | 
| 112 | 
            -
                    when :release
         | 
| 111 | 
            +
                    when :branch
         | 
| 113 112 | 
             
                      response = "There is a build of the `#{build_data.branch}` branch of https://github.com/#{build_data.repo_full_name} in progress."
         | 
| 114 113 | 
             
                    end
         | 
| 115 114 | 
             
                    if queue_length == 1
         | 
| @@ -159,10 +158,8 @@ Ask me `what happened` to get a list of recent builds and log files and `what op | |
| 159 158 | 
             
                      build_datas.each do |build_data|
         | 
| 160 159 | 
             
                        response += "A "
         | 
| 161 160 | 
             
                        response += case build_data.type
         | 
| 162 | 
            -
                                    when : | 
| 163 | 
            -
                                      "` | 
| 164 | 
            -
                                    when :release
         | 
| 165 | 
            -
                                      "`#{build_data.branch}` release branch build"
         | 
| 161 | 
            +
                                    when :branch
         | 
| 162 | 
            +
                                      "`#{build_data.branch}` branch build"
         | 
| 166 163 | 
             
                                    when :pull_request
         | 
| 167 164 | 
             
                                      "pull request `#{build_data.pull_request}` build"
         | 
| 168 165 | 
             
                                    end
         | 
| @@ -278,10 +275,7 @@ Ask me `what happened` to get a list of recent builds and log files and `what op | |
| 278 275 | 
             
                    info "Pull request build #{status_message}"
         | 
| 279 276 | 
             
                  else
         | 
| 280 277 | 
             
                    status_message += "Log file at #{log_url}."
         | 
| 281 | 
            -
                    if build_data.type == : | 
| 282 | 
            -
                      message = "A build of the `master` branch #{status_message}"
         | 
| 283 | 
            -
                      info "`master` branch build #{status_message}"
         | 
| 284 | 
            -
                    else
         | 
| 278 | 
            +
                    if build_data.type == :branch
         | 
| 285 279 | 
             
                      message = "A build of the `#{build_data.branch}` branch #{status_message}"
         | 
| 286 280 | 
             
                      info "Release branch build #{status_message}"
         | 
| 287 281 | 
             
                    end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: build-buddy
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1. | 
| 4 | 
            +
              version: 1.10.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - John Lyon-smith
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2016-05- | 
| 11 | 
            +
            date: 2016-05-12 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: timers
         |