Merge pull request #15002 from nandahkrishna/actions-multiline-envfile
utils/github/actions: add `format_multiline_string` method
This commit is contained in:
		
						commit
						27bb6ff1dd
					
				@ -1,6 +1,7 @@
 | 
				
			|||||||
# typed: true
 | 
					# typed: true
 | 
				
			||||||
# frozen_string_literal: true
 | 
					# frozen_string_literal: true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					require "securerandom"
 | 
				
			||||||
require "utils/tty"
 | 
					require "utils/tty"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module GitHub
 | 
					module GitHub
 | 
				
			||||||
@ -18,6 +19,24 @@ module GitHub
 | 
				
			|||||||
            .gsub("\r", "%0D")
 | 
					            .gsub("\r", "%0D")
 | 
				
			||||||
    end
 | 
					    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.
 | 
					    # Helper class for formatting annotations on GitHub Actions.
 | 
				
			||||||
    class Annotation
 | 
					    class Annotation
 | 
				
			||||||
      extend T::Sig
 | 
					      extend T::Sig
 | 
				
			||||||
@ -85,5 +104,9 @@ module GitHub
 | 
				
			|||||||
        @file.descend.next.to_s != ".."
 | 
					        @file.descend.next.to_s != ".."
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # Generic GitHub Actions error.
 | 
				
			||||||
 | 
					    class Error < RuntimeError
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user