-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from Taucher2003/12-show-job-output
Add Job logs to action output
- Loading branch information
Showing
11 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module GitlabPipelineAction | ||
module Helper | ||
module Github | ||
module_function | ||
|
||
def warning(message) | ||
puts "::warning::#{message}" | ||
end | ||
|
||
def with_group(name) | ||
puts "::group::#{name}" | ||
yield | ||
puts '::endgroup::' | ||
end | ||
|
||
def stop_commands | ||
token = SecureRandom.hex | ||
puts "::stop-commands::#{token}" | ||
yield | ||
puts "::#{token}::" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,10 @@ def initialize(context) | |
def skip? | ||
false | ||
end | ||
|
||
def github | ||
GitlabPipelineAction::Helper::Github | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
module GitlabPipelineAction | ||
module Step | ||
class ShowJobLogs < Base | ||
VARIANTS = { | ||
all: ->(_) { true }, | ||
failures: ->(job) { job.status == 'failed' }, | ||
}.freeze | ||
|
||
def execute | ||
unless VARIANTS.key?(context.gl_show_job_logs) | ||
github.warning 'Invalid option for SHOW_JOB_LOGS' | ||
return | ||
end | ||
|
||
jobs = context.gitlab_client | ||
.pipeline_jobs(context.gl_project_id, context.gl_pipeline.id) | ||
.select(&VARIANTS[context.gl_show_job_logs]) | ||
.sort_by { |job| job.id.to_i } | ||
|
||
jobs.each do |job| | ||
github.with_group "'#{job.name}' in stage '#{job.stage}' (#{job.status})" do | ||
github.stop_commands do | ||
puts context.gitlab_client.job_trace(context.gl_project_id, job.id) | ||
end | ||
end | ||
end | ||
end | ||
|
||
def skip? | ||
context.gl_show_job_logs.nil? || context.gl_show_job_logs == :none | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters