Class: Datadog::CI::Ext::Environment::Providers::GithubActions
- Inherits:
-
Base
- Object
- Base
- Datadog::CI::Ext::Environment::Providers::GithubActions
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_head_author_date, #git_commit_head_author_email, #git_commit_head_author_name, #git_commit_head_committer_date, #git_commit_head_committer_email, #git_commit_head_committer_name, #git_commit_head_message, #git_commit_message, #git_pull_request_base_branch_sha, #git_tag, #initialize, #node_labels, #node_name, #stage_name
Class Method Details
.handles?(env) ⇒ Boolean
18
19
20
|
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 18
def self.handles?(env)
env.key?("GITHUB_SHA")
end
|
Instance Method Details
#ci_env_vars ⇒ Object
74
75
76
77
78
79
80
81
|
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 74
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_tag ⇒ Object
68
69
70
71
72
|
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 68
def git_branch_or_tag
ref = env["GITHUB_HEAD_REF"]
ref = env["GITHUB_REF"] if ref.nil? || ref.empty?
ref
end
|
#git_commit_head_sha ⇒ Object
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 100
def git_commit_head_sha
return nil if git_pull_request_base_branch.nil?
event_json = github_event_json
return nil if event_json.nil?
event_json.dig("pull_request", "head", "sha")
rescue => e
Datadog.logger.error("Failed to extract commit head SHA from GitHub Actions: #{e}")
Core::Telemetry::Logger.report(e, description: "Failed to extract commit head SHA from GitHub Actions")
nil
end
|
#git_commit_sha ⇒ Object
64
65
66
|
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 64
def git_commit_sha
env["GITHUB_SHA"]
end
|
#git_pull_request_base_branch ⇒ Object
83
84
85
|
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 83
def git_pull_request_base_branch
env["GITHUB_BASE_REF"]
end
|
#git_pull_request_base_branch_head_sha ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 87
def git_pull_request_base_branch_head_sha
return nil if git_pull_request_base_branch.nil?
event_json = github_event_json
return nil if event_json.nil?
event_json.dig("pull_request", "base", "sha")
rescue => e
Datadog.logger.error("Failed to extract pull request base branch head SHA from GitHub Actions: #{e}")
Core::Telemetry::Logger.report(e, description: "Failed to extract pull request base branch head SHA from GitHub Actions")
nil
end
|
#git_repository_url ⇒ Object
60
61
62
|
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 60
def git_repository_url
"#{github_server_url}/#{env["GITHUB_REPOSITORY"]}.git"
end
|
#job_id ⇒ Object
34
35
36
|
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 34
def job_id
env["GITHUB_JOB"]
end
|
#job_name ⇒ Object
26
27
28
|
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 26
def job_name
env["GITHUB_JOB"]
end
|
#job_url ⇒ Object
30
31
32
|
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 30
def job_url
"#{github_server_url}/#{env["GITHUB_REPOSITORY"]}/commit/#{env["GITHUB_SHA"]}/checks"
end
|
#pipeline_id ⇒ Object
38
39
40
|
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 38
def pipeline_id
env["GITHUB_RUN_ID"]
end
|
#pipeline_name ⇒ Object
42
43
44
|
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 42
def pipeline_name
env["GITHUB_WORKFLOW"]
end
|
#pipeline_number ⇒ Object
46
47
48
|
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 46
def pipeline_number
env["GITHUB_RUN_NUMBER"]
end
|
#pipeline_url ⇒ Object
50
51
52
53
54
|
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 50
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
|
#pr_number ⇒ Object
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 113
def pr_number
event_json = github_event_json
return nil if event_json.nil?
event_json["number"]
rescue => e
Datadog.logger.error("Failed to extract PR number from GitHub Actions: #{e}")
Core::Telemetry::Logger.report(e, description: "Failed to extract PR number from GitHub Actions")
nil
end
|
#provider_name ⇒ Object
22
23
24
|
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 22
def provider_name
Provider::GITHUB
end
|
#workspace_path ⇒ Object
56
57
58
|
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 56
def workspace_path
env["GITHUB_WORKSPACE"]
end
|