Interview Prep/GitHub Actions/Contexts, Expressions, Env & Outputs

How do you write a step output, including a multiline value?

BeginnerConceptContexts, Expressions, Env & Outputs
Answer

Append to the $GITHUB_OUTPUT file. Multiline values use a heredoc-style delimiter, which should be random for untrusted content:

echo "tag=v1.4.0" >> "$GITHUB_OUTPUT"

delim="EOF_$(openssl rand -hex 8)"
{
  echo "notes<<$delim"
  git log --oneline v1.3.0..HEAD
  echo "$delim"
} >> "$GITHUB_OUTPUT"

Read as steps.<id>.outputs.notes. The step needs an id.

All GitHub Actions questions Roadmap: GitHub Actions

More on Contexts, Expressions, Env & Outputs