utils/github/actions: add format_multiline_string method
				
					
				
			This commit is contained in:
		
							parent
							
								
									b3684e55a7
								
							
						
					
					
						commit
						b792a5fd20
					
				@ -1,6 +1,7 @@
 | 
			
		||||
# typed: true
 | 
			
		||||
# frozen_string_literal: true
 | 
			
		||||
 | 
			
		||||
require "securerandom"
 | 
			
		||||
require "utils/tty"
 | 
			
		||||
 | 
			
		||||
module GitHub
 | 
			
		||||
@ -18,6 +19,24 @@ module GitHub
 | 
			
		||||
            .gsub("\r", "%0D")
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    sig { params(name: String, value: String).returns(String) }
 | 
			
		||||
    def self.format_multiline_string(name, value)
 | 
			
		||||
      # Format multiline strings for environment files
 | 
			
		||||
      # See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
 | 
			
		||||
 | 
			
		||||
      delimiter = "ghadelimiter_#{SecureRandom.uuid}"
 | 
			
		||||
 | 
			
		||||
      if name.include?(delimiter) || value.include?(delimiter)
 | 
			
		||||
        raise Error, "`name` and `value` must not contain the delimiter"
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      <<~EOS
 | 
			
		||||
        #{name}<<#{delimiter}
 | 
			
		||||
        #{value}
 | 
			
		||||
        #{delimiter}
 | 
			
		||||
      EOS
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    # Helper class for formatting annotations on GitHub Actions.
 | 
			
		||||
    class Annotation
 | 
			
		||||
      extend T::Sig
 | 
			
		||||
@ -85,5 +104,9 @@ module GitHub
 | 
			
		||||
        @file.descend.next.to_s != ".."
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    # Generic GitHub Actions error.
 | 
			
		||||
    class Error < RuntimeError
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user