Module: Coveralls::Configuration

Defined in:
lib/coveralls/configuration.rb

Class Method Summary collapse

Class Method Details

.configurationObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/coveralls/configuration.rb', line 7

def self.configuration
  config = {
    :environment => self.relevant_env,
    :git => git
  }
  yml = self.yaml_config
  if yml
    config[:configuration] = yml
    config[:repo_token] = yml['repo_token'] || yml['repo_secret_token']
  end
  if ENV['COVERALLS_REPO_TOKEN']
    config[:repo_token] = ENV['COVERALLS_REPO_TOKEN']
  end
  if ENV['COVERALLS_PARALLEL'] && ENV['COVERALLS_PARALLEL'] != "false"
    config[:parallel] = true
  end
  if ENV['COVERALLS_FLAG_NAME']
    config[:flag_name] = ENV['COVERALLS_FLAG_NAME']
  end
  if ENV['TRAVIS']
    set_service_params_for_travis(config, yml ? yml['service_name'] : nil)
  elsif ENV['CIRCLECI']
    set_service_params_for_circleci(config)
  elsif ENV['SEMAPHORE']
    set_service_params_for_semaphore(config)
  elsif ENV['JENKINS_URL'] || ENV['JENKINS_HOME']
    set_service_params_for_jenkins(config)
  elsif ENV['APPVEYOR']
    set_service_params_for_appveyor(config)
  elsif ENV['TDDIUM']
    set_service_params_for_tddium(config)
  elsif ENV['GITLAB_CI']
    set_service_params_for_gitlab(config)
  elsif ENV['COVERALLS_RUN_LOCALLY'] || Coveralls.testing
    set_service_params_for_coveralls_local(config)
  end

  # standardized env vars
  set_standard_service_params_for_generic_ci(config)

  if service_name = ENV['COVERALLS_SERVICE_NAME']
    config[:service_name] = service_name
  end

  config
end

.configuration_pathObject



129
130
131
# File 'lib/coveralls/configuration.rb', line 129

def self.configuration_path
  File.expand_path(File.join(self.root, ".coveralls.yml")) if self.root
end

.gitObject



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/coveralls/configuration.rb', line 153

def self.git
  hash = {}

  Dir.chdir(root) do

    hash[:head] = {
      :id => ENV.fetch("GIT_ID", `git log -1 --pretty=format:'%H'`),
      :author_name => ENV.fetch("GIT_AUTHOR_NAME", `git log -1 --pretty=format:'%aN'`),
      :author_email => ENV.fetch("GIT_AUTHOR_EMAIL", `git log -1 --pretty=format:'%ae'`),
      :committer_name => ENV.fetch("GIT_COMMITTER_NAME", `git log -1 --pretty=format:'%cN'`),
      :committer_email => ENV.fetch("GIT_COMMITTER_EMAIL", `git log -1 --pretty=format:'%ce'`),
      :message => ENV.fetch("GIT_MESSAGE", `git log -1 --pretty=format:'%s'`)
    }

    # Branch
    hash[:branch] = ENV.fetch("GIT_BRANCH", `git rev-parse --abbrev-ref HEAD`)

    # Remotes
    remotes = nil
    begin
      remotes = `git remote -v`.split(/\n/).map do |remote|
        splits = remote.split(" ").compact
        {:name => splits[0], :url => splits[1]}
      end.uniq
    rescue
    end
    hash[:remotes] = remotes

  end

  hash

rescue Exception => e
  Coveralls::Output.puts "Coveralls git error:", :color => "red"
  Coveralls::Output.puts e.to_s, :color => "red"
  nil
end

.pwdObject



137
138
139
# File 'lib/coveralls/configuration.rb', line 137

def self.pwd
  Dir.pwd
end

.rails_rootObject



147
148
149
150
151
# File 'lib/coveralls/configuration.rb', line 147

def self.rails_root
  Rails.root.to_s
rescue
  nil
end

.relevant_envObject



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/coveralls/configuration.rb', line 191

def self.relevant_env
  hash = {
    :pwd => self.pwd,
    :rails_root => self.rails_root,
    :simplecov_root => simplecov_root,
    :gem_version => VERSION
  }

  hash.merge! begin
    if ENV['TRAVIS']
      {
        :travis_job_id => ENV['TRAVIS_JOB_ID'],
        :travis_pull_request => ENV['TRAVIS_PULL_REQUEST'],
        :branch => ENV['TRAVIS_BRANCH']
      }
    elsif ENV['CIRCLECI']
      {
        :circleci_build_num => ENV['CIRCLE_BUILD_NUM'],
        :branch => ENV['CIRCLE_BRANCH'],
        :commit_sha => ENV['CIRCLE_SHA1']
      }
    elsif ENV['JENKINS_URL']
      {
        :jenkins_build_num => ENV['BUILD_NUMBER'],
        :jenkins_build_url => ENV['BUILD_URL'],
        :branch => ENV['GIT_BRANCH'],
        :commit_sha => ENV['GIT_COMMIT']
      }
    elsif ENV['SEMAPHORE']
      {
        :branch => ENV['BRANCH_NAME'],
        :commit_sha => ENV['REVISION']
      }
    else
      {}
    end
  end

  hash
end

.rootObject



133
134
135
# File 'lib/coveralls/configuration.rb', line 133

def self.root
  pwd
end

.set_service_params_for_appveyor(config) ⇒ Object



82
83
84
85
86
87
88
89
# File 'lib/coveralls/configuration.rb', line 82

def self.set_service_params_for_appveyor(config)
  config[:service_name]   = 'appveyor'
  config[:service_number] = ENV['APPVEYOR_BUILD_VERSION']
  config[:service_branch] = ENV['APPVEYOR_REPO_BRANCH']
  config[:commit_sha] = ENV['APPVEYOR_REPO_COMMIT']
  repo_name = ENV['APPVEYOR_REPO_NAME']
  config[:service_build_url]  = 'https://ci.appveyor.com/project/%s/build/%s' % [repo_name, config[:service_number]]
end

.set_service_params_for_circleci(config) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/coveralls/configuration.rb', line 61

def self.set_service_params_for_circleci(config)
  config[:service_name]         = 'circleci'
  config[:service_number]       = ENV['CIRCLE_BUILD_NUM']
  config[:service_pull_request] = (ENV['CI_PULL_REQUEST'] || "")[/(\d+)$/,1]
  config[:parallel]             = ENV['CIRCLE_NODE_TOTAL'].to_i > 1
  config[:service_job_number]   = ENV['CIRCLE_NODE_INDEX']
end

.set_service_params_for_coveralls_local(config) ⇒ Object



108
109
110
111
112
# File 'lib/coveralls/configuration.rb', line 108

def self.set_service_params_for_coveralls_local(config)
  config[:service_job_id]     = nil
  config[:service_name]       = 'coveralls-ruby'
  config[:service_event_type] = 'manual'
end

.set_service_params_for_gitlab(config) ⇒ Object



100
101
102
103
104
105
106
# File 'lib/coveralls/configuration.rb', line 100

def self.set_service_params_for_gitlab(config)
  config[:service_name]         = 'gitlab-ci'
  config[:service_job_number]   = ENV['CI_BUILD_NAME']
  config[:service_job_id]       = ENV['CI_BUILD_ID']
  config[:service_branch]       = ENV['CI_BUILD_REF_NAME']
  config[:commit_sha]           = ENV['CI_BUILD_REF']
end

.set_service_params_for_jenkins(config) ⇒ Object



75
76
77
78
79
80
# File 'lib/coveralls/configuration.rb', line 75

def self.set_service_params_for_jenkins(config)
  config[:service_name]   = 'jenkins'
  config[:service_number] = ENV['BUILD_NUMBER']
  config[:service_branch] = ENV['BRANCH_NAME']
  config[:service_pull_request] = ENV['ghprbPullId']
end

.set_service_params_for_semaphore(config) ⇒ Object



69
70
71
72
73
# File 'lib/coveralls/configuration.rb', line 69

def self.set_service_params_for_semaphore(config)
  config[:service_name]         = 'semaphore'
  config[:service_number]       = ENV['SEMAPHORE_BUILD_NUMBER']
  config[:service_pull_request] = ENV['PULL_REQUEST_NUMBER']
end

.set_service_params_for_tddium(config) ⇒ Object



91
92
93
94
95
96
97
98
# File 'lib/coveralls/configuration.rb', line 91

def self.set_service_params_for_tddium(config)
  config[:service_name]         = 'tddium'
  config[:service_number]       = ENV['TDDIUM_SESSION_ID']
  config[:service_job_number]   = ENV['TDDIUM_TID']
  config[:service_pull_request] = ENV['TDDIUM_PR_ID']
  config[:service_branch]       = ENV['TDDIUM_CURRENT_BRANCH']
  config[:service_build_url]    = "https://ci.solanolabs.com/reports/#{ENV['TDDIUM_SESSION_ID']}"
end

.set_service_params_for_travis(config, service_name) ⇒ Object



54
55
56
57
58
59
# File 'lib/coveralls/configuration.rb', line 54

def self.set_service_params_for_travis(config, service_name)
  config[:service_job_id] = ENV['TRAVIS_JOB_ID']
  config[:service_pull_request] = ENV['TRAVIS_PULL_REQUEST'] unless ENV['TRAVIS_PULL_REQUEST'] == 'false'
  config[:service_name]   = service_name || 'travis-ci'
  config[:service_branch] = ENV['TRAVIS_BRANCH']
end

.set_standard_service_params_for_generic_ci(config) ⇒ Object



114
115
116
117
118
119
120
121
# File 'lib/coveralls/configuration.rb', line 114

def self.set_standard_service_params_for_generic_ci(config)
  config[:service_name]         ||= ENV['CI_NAME']
  config[:service_number]       ||= ENV['CI_BUILD_NUMBER']
  config[:service_job_id]       ||= ENV['CI_JOB_ID']
  config[:service_build_url]    ||= ENV['CI_BUILD_URL']
  config[:service_branch]       ||= ENV['CI_BRANCH']
  config[:service_pull_request] ||= (ENV['CI_PULL_REQUEST'] || "")[/(\d+)$/,1]
end

.simplecov_rootObject



141
142
143
144
145
# File 'lib/coveralls/configuration.rb', line 141

def self.simplecov_root
  if defined?(::SimpleCov)
    ::SimpleCov.root
  end
end

.yaml_configObject



123
124
125
126
127
# File 'lib/coveralls/configuration.rb', line 123

def self.yaml_config
  if self.configuration_path && File.exist?(self.configuration_path)
    YAML::load_file(self.configuration_path)
  end
end