How to replace ::set-output in your GitHub actions

Last modified date

Comments: 0

Using ::set-output has been deprecated by GitHub, but thankfully the changes to your action are really minimal in order to use it’s replacement, the $GITHUB_OUTPUT environment variable.

Let’s imagine that in your action, you have something along the lines of:

echo "::set-output name=action-summary::${OUTPUT}"

The change is to make it look like:

echo "action-summary=$OUTPUT" >> $GITHUB_OUTPUT

Super simple, right?

And the create thing is, you can still use them in exactly the same way with something like ${{ steps.cool-step.outputs.action-summary }}

Now, that’s great for simple lines. But what if you wanted to output multiple lines for the same output name? Before, you have to escape lines such as:

OUTPUT="${OUTPUT//'%'/'%25'}"
OUTPUT="${OUTPUT//$'\n'/'%0A'}"
AOUTPUT="${OUTPUT//$'\r'/'%0D'}"
echo "::set-output name=action-summary::${OUTPUT}"

But – for me at any rate – this didn’t work. The easiest way around that I’ve found is to use the heredoc output, such as:

echo "action-summary<<EOF" >> $GITHUB_OUTPUT
echo "$OUTPUT" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT

So you kick-start the heredoc with <<EOF (you can use whatever marker text you want, but convention goes with EOF), and then output all the lines you want, and finish it off with outputting the marker.

Hopefully this’ll help get your GitHub actions up-to-date and not using the deprecated ::set-output!

Share

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.