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_message, #git_tag, #initialize, #node_labels, #node_name, #stage_name
Class Method Details
.handles?(env) ⇒ Boolean
17
18
19
|
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 17
def self.handles?(env)
env.key?("GITHUB_SHA")
end
|
Instance Method Details
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 78
def additional_tags
base_ref = env["GITHUB_BASE_REF"]
return {} if base_ref.nil? || base_ref.empty?
result = {
Git::TAG_PULL_REQUEST_BASE_BRANCH => base_ref
}
event_path = env["GITHUB_EVENT_PATH"]
event_json = JSON.parse(File.read(event_path))
head_sha = event_json.dig("pull_request", "head", "sha")
result[Git::TAG_COMMIT_HEAD_SHA] = head_sha if head_sha
base_sha = event_json.dig("pull_request", "base", "sha")
result[Git::TAG_PULL_REQUEST_BASE_BRANCH_SHA] = base_sha if base_sha
result
rescue => e
Datadog.logger.error("Failed to extract additional tags from GitHub Actions: #{e}")
{}
end
|
#ci_env_vars ⇒ Object
69
70
71
72
73
74
75
76
|
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 69
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
63
64
65
66
67
|
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 63
def git_branch_or_tag
ref = env["GITHUB_HEAD_REF"]
ref = env["GITHUB_REF"] if ref.nil? || ref.empty?
ref
end
|
#git_commit_sha ⇒ Object
59
60
61
|
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 59
def git_commit_sha
env["GITHUB_SHA"]
end
|
#git_repository_url ⇒ Object
55
56
57
|
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 55
def git_repository_url
"#{github_server_url}/#{env["GITHUB_REPOSITORY"]}.git"
end
|
#job_name ⇒ Object
25
26
27
|
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 25
def job_name
env["GITHUB_JOB"]
end
|
#job_url ⇒ Object
29
30
31
|
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 29
def job_url
"#{github_server_url}/#{env["GITHUB_REPOSITORY"]}/commit/#{env["GITHUB_SHA"]}/checks"
end
|
#pipeline_id ⇒ Object
33
34
35
|
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 33
def pipeline_id
env["GITHUB_RUN_ID"]
end
|
#pipeline_name ⇒ Object
37
38
39
|
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 37
def pipeline_name
env["GITHUB_WORKFLOW"]
end
|
#pipeline_number ⇒ Object
41
42
43
|
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 41
def pipeline_number
env["GITHUB_RUN_NUMBER"]
end
|
#pipeline_url ⇒ Object
45
46
47
48
49
|
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 45
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_name ⇒ Object
21
22
23
|
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 21
def provider_name
Provider::GITHUB
end
|
#workspace_path ⇒ Object
51
52
53
|
# File 'lib/datadog/ci/ext/environment/providers/github_actions.rb', line 51
def workspace_path
env["GITHUB_WORKSPACE"]
end
|