Class: Datadog::CI::Ext::Environment::Providers::GithubActions

Inherits:
Base
  • Object
show all
Defined in:
lib/datadog/ci/ext/environment/providers/github_actions.rb

Overview

Instance Attribute Summary

Attributes inherited from Base

#env

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#git_branch, #git_commit_author_date, #git_commit_author_email, #git_commit_author_name, #git_commit_committer_date, #git_commit_committer_email, #git_commit_committer_name, #git_commit_message, #git_tag, #initialize, #node_labels, #node_name, #stage_name

Constructor Details

This class inherits a constructor from Datadog::CI::Ext::Environment::Providers::Base

Class Method Details

.handles?(env) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 16

def self.handles?(env)
  env.key?("GITHUB_SHA")
end

Instance Method Details

#ci_env_varsObject



68
69
70
71
72
73
74
75
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 68

def ci_env_vars
  {
    "GITHUB_SERVER_URL" => github_server_url,
    "GITHUB_REPOSITORY" => env["GITHUB_REPOSITORY"],
    "GITHUB_RUN_ID" => env["GITHUB_RUN_ID"],
    "GITHUB_RUN_ATTEMPT" => env["GITHUB_RUN_ATTEMPT"]
  }.reject { |_, v| v.nil? }.to_json
end

#git_branch_or_tagObject



62
63
64
65
66
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 62

def git_branch_or_tag
  ref = env["GITHUB_HEAD_REF"]
  ref = env["GITHUB_REF"] if ref.nil? || ref.empty?
  ref
end

#git_commit_shaObject



58
59
60
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 58

def git_commit_sha
  env["GITHUB_SHA"]
end

#git_repository_urlObject



54
55
56
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 54

def git_repository_url
  "#{github_server_url}/#{env["GITHUB_REPOSITORY"]}.git"
end

#job_nameObject



24
25
26
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 24

def job_name
  env["GITHUB_JOB"]
end

#job_urlObject



28
29
30
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 28

def job_url
  "#{github_server_url}/#{env["GITHUB_REPOSITORY"]}/commit/#{env["GITHUB_SHA"]}/checks"
end

#pipeline_idObject



32
33
34
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 32

def pipeline_id
  env["GITHUB_RUN_ID"]
end

#pipeline_nameObject



36
37
38
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 36

def pipeline_name
  env["GITHUB_WORKFLOW"]
end

#pipeline_numberObject



40
41
42
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 40

def pipeline_number
  env["GITHUB_RUN_NUMBER"]
end

#pipeline_urlObject



44
45
46
47
48
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 44

def pipeline_url
  res = "#{github_server_url}/#{env["GITHUB_REPOSITORY"]}/actions/runs/#{env["GITHUB_RUN_ID"]}"
  res = "#{res}/attempts/#{env["GITHUB_RUN_ATTEMPT"]}" if env["GITHUB_RUN_ATTEMPT"]
  res
end

#provider_nameObject



20
21
22
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 20

def provider_name
  "github"
end

#workspace_pathObject



50
51
52
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 50

def workspace_path
  env["GITHUB_WORKSPACE"]
end