diff options
author | André Arko <mail@arko.net> | 2015-05-16 14:42:10 -0700 |
---|---|---|
committer | André Arko <mail@arko.net> | 2015-05-16 14:42:10 -0700 |
commit | 4c6d3152227fdfb477228aa40fcc88ba7f60d974 (patch) | |
tree | 720b7b9b816cb34f8404650a55eae441c346475e | |
parent | 724af3839ed20aa9a219229492cff760fac5837d (diff) | |
parent | ad69165cac0d8b0996bc2ec523751437220a4784 (diff) | |
download | bundler-4c6d3152227fdfb477228aa40fcc88ba7f60d974.tar.gz |
Merge pull request #3646 from fotanus/track_ci
Distinguish CI command runs
-rw-r--r-- | lib/bundler/fetcher.rb | 17 | ||||
-rw-r--r-- | spec/bundler/fetcher_spec.rb | 17 | ||||
-rw-r--r-- | spec/support/helpers.rb | 12 |
3 files changed, 46 insertions, 0 deletions
diff --git a/lib/bundler/fetcher.rb b/lib/bundler/fetcher.rb index 42c6eb6717..936f28331f 100644 --- a/lib/bundler/fetcher.rb +++ b/lib/bundler/fetcher.rb @@ -155,6 +155,8 @@ module Bundler agent << " options/#{Bundler.settings.all.join(",")}" + agent << " ci/#{cis.join(",")}" if cis.any? + # add a random ID so we can consolidate runs server-side agent << " " << SecureRandom.hex(8) @@ -178,6 +180,21 @@ module Bundler FETCHERS = [Dependency, Index] + def cis + env_cis = { + "TRAVIS" => "travis", + "CIRCLECI" => "circle", + "SEMAPHORE" => "semaphore", + "JENKINS_URL" => "jenkins", + "BUILDBOX" => "buildbox", + "GO_SERVER_URL" => "go", + "SNAP_CI" => "snap", + "CI_NAME" => ENV["CI_NAME"], + "CI" => "ci" + } + env_cis.find_all{ |env, ci| ENV[env]}.map{ |env, ci| ci } + end + def connection @connection ||= begin needs_ssl = remote_uri.scheme == "https" || diff --git a/spec/bundler/fetcher_spec.rb b/spec/bundler/fetcher_spec.rb index 0d47bc5e90..3c7bef39f2 100644 --- a/spec/bundler/fetcher_spec.rb +++ b/spec/bundler/fetcher_spec.rb @@ -16,5 +16,22 @@ describe Bundler::Fetcher do expect(fetcher.user_agent).to match(/ruby\/(\d.)/) expect(fetcher.user_agent).to match(/options\/foo,bar/) end + + describe "include CI information" do + it "from one CI" do + with_env_vars({"JENKINS_URL" => "foo"}) do + ci_part = fetcher.user_agent.split(' ').find{|x| x.match(/\Aci\//)} + expect(ci_part).to match("jenkins") + end + end + + it "from many CI" do + with_env_vars({"TRAVIS" => "foo", "CI_NAME" => "my_ci"}) do + ci_part = fetcher.user_agent.split(' ').find{|x| x.match(/\Aci\//)} + expect(ci_part).to match("travis") + expect(ci_part).to match("my_ci") + end + end + end end end diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index 6d7e9dfbe2..c1d9bfc28c 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -357,5 +357,17 @@ module Spec end File.open(pathname, 'w') { |file| file.puts(changed_lines.join) } end + + def with_env_vars(env_hash, &block) + current_values = {} + env_hash.each do |k,v| + current_values[k] = v + ENV[k] = v + end + block.call if block_given? + env_hash.each do |k,v| + ENV[k] = current_values[k] + end + end end end |