Module: GitHub::Actions
- Defined in:
- utils/github/actions.rb
Overview
This module is part of an internal API. This module may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this module if possible, as it may be removed or changed without warning.
Helper functions for interacting with GitHub Actions.
Defined Under Namespace
Classes: Annotation
Class Method Summary collapse
- .env_set? ⇒ Boolean private
- .escape(string) ⇒ String private
- .format_multiline_string(name, value) ⇒ String private
- .puts_annotation_if_env_set(type, message, file: nil, line: nil) ⇒ Boolean private
Class Method Details
.env_set? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
37 38 39 |
# File 'utils/github/actions.rb', line 37 def self.env_set? ENV.fetch("GITHUB_ACTIONS", false).present? end |
.escape(string) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
10 11 12 13 14 15 |
# File 'utils/github/actions.rb', line 10 def self.escape(string) # See https://github.community/t/set-output-truncates-multiline-strings/16852/3. string.gsub("%", "%25") .gsub("\n", "%0A") .gsub("\r", "%0D") end |
.format_multiline_string(name, value) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'utils/github/actions.rb', line 18 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 require "securerandom" delimiter = "ghadelimiter_#{SecureRandom.uuid}" if name.include?(delimiter) || value.include?(delimiter) raise "`name` and `value` must not contain the delimiter" end <<~EOS #{name}<<#{delimiter} #{value} #{delimiter} EOS end |
.puts_annotation_if_env_set(type, message, file: nil, line: nil) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
48 49 50 51 52 53 54 55 56 57 |
# File 'utils/github/actions.rb', line 48 def self.puts_annotation_if_env_set(type, , file: nil, line: nil) # Don't print annotations during tests, too messy to handle these. return false if ENV.fetch("HOMEBREW_TESTS", false) return false unless env_set? std = (type == :notice) ? $stdout : $stderr std.puts Annotation.new(type, ) true end |