Module: ExecutableStories::Output

Defined in:
lib/executable_stories/output.rb

Class Method Summary collapse

Class Method Details

.detect_ci ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/executable_stories/output.rb', line 32

def detect_ci
  if ENV["GITHUB_ACTIONS"] == "true"
    url = nil
    server = ENV["GITHUB_SERVER_URL"]
    repo = ENV["GITHUB_REPOSITORY"]
    run_id = ENV["GITHUB_RUN_ID"]
    url = "#{server}/#{repo}/actions/runs/#{run_id}" if server && repo && run_id
    RawCIInfo.new(name: "github", url: url, build_number: ENV["GITHUB_RUN_NUMBER"])
  elsif ENV["CIRCLECI"] == "true"
    RawCIInfo.new(name: "circleci", url: ENV["CIRCLE_BUILD_URL"], build_number: ENV["CIRCLE_BUILD_NUM"])
  elsif !ENV["JENKINS_URL"].nil?
    RawCIInfo.new(name: "jenkins", url: ENV["BUILD_URL"], build_number: ENV["BUILD_NUMBER"])
  elsif ENV["TRAVIS"] == "true"
    RawCIInfo.new(name: "travis", url: ENV["TRAVIS_BUILD_WEB_URL"], build_number: ENV["TRAVIS_BUILD_NUMBER"])
  elsif ENV["GITLAB_CI"] == "true"
    RawCIInfo.new(name: "gitlab", url: ENV["CI_PIPELINE_URL"], build_number: ENV["CI_PIPELINE_IID"])
  elsif ENV["CI"] == "true"
    RawCIInfo.new(name: "ci")
  end
end

.write_results(cases:, output_path: nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/executable_stories/output.rb', line 10

def write_results(cases:, output_path: nil)
  return if cases.empty?

  output_path ||= ENV.fetch("EXECUTABLE_STORIES_OUTPUT", ".executable-stories/raw-run.json")

  started = cases.map(&:start_time).compact.min
  finished = cases.map(&:end_time).compact.max

  run = RawRun.new(
    schema_version: 1,
    test_cases: cases,
    project_root: Dir.pwd,
    started_at_ms: started,
    finished_at_ms: finished,
    package_version: nil,
    git_sha: nil,
    ci: detect_ci
  )

  JsonWriter.write_raw_run(run, output_path)
end