Module: ActionReporter::WorkflowCommand

Defined in:
action/lib/action_reporter.rb

Overview

Shared GitHub Actions output and annotation formatting.

Class Method Summary collapse

Class Method Details

.annotation(level, properties, message) ⇒ Object



48
49
50
# File 'action/lib/action_reporter.rb', line 48

def annotation(level, properties, message)
  "::#{level} #{property_string(properties)}::#{escape_data(message)}"
end

.env_value(key) ⇒ Object



20
21
22
23
# File 'action/lib/action_reporter.rb', line 20

def env_value(key)
  value = ENV.fetch(key, "").strip
  value.empty? ? nil : value
end

.escape_data(value) ⇒ Object



40
41
42
# File 'action/lib/action_reporter.rb', line 40

def escape_data(value)
  value.to_s.gsub("%", "%25").gsub("\r", "%0D").gsub("\n", "%0A")
end

.escape_property(value) ⇒ Object



44
45
46
# File 'action/lib/action_reporter.rb', line 44

def escape_property(value)
  escape_data(value).gsub(":", "%3A").gsub(",", "%2C")
end

.property_string(properties) ⇒ Object



34
35
36
37
38
# File 'action/lib/action_reporter.rb', line 34

def property_string(properties)
  properties
    .map { |key, value| "#{key}=#{escape_property(value)}" }
    .join(",")
end

.write_multiline_output(file, name, value) ⇒ Object



25
26
27
28
29
30
31
32
# File 'action/lib/action_reporter.rb', line 25

def write_multiline_output(file, name, value)
  delimiter = "SPM_VERSION_UPDATES_JSON"
  delimiter = "#{delimiter}_END" while value.include?(delimiter)

  file.puts("#{name}<<#{delimiter}")
  file.puts(value)
  file.puts(delimiter)
end