Use multi-line values in GitHub Actions

I created an action that needed a rich Markdown value in it, because it’s our weekly meeting agenda template which is formatted for humans with links and paragraphs and things. The Action syntax produced errors when trying to add the content directly to the action, but I got it to work by putting the content into the file, and using the file contents as an environment variable. That’s really the punchline of this post, but read on if you would like more details and some examples.

The wider context is that we use GitHub Discussions to plan meeting agendas. The meeting discussions always need to include the same explanatory text, a link to the video call (currently not included as it’s about to change), and information about the Code of Conduct. The action makes this very quick for any of the project members to do in preparation for the next meeting.

The steps look something like this:

  1. I put the Markdown to use as the content of the discussion into a file .github/templates/agenda.md. It’s quite nice to have it as its own Markdown file as it’s easier to edit and update by itself.

  2. In order to access this file, the GitHub action needs a checkout action.

  3. The next step reads the file and puts it into an environment variable. It took me a while to find how to do this, but here’s what I ended up with:

      - name: Get agenda text from template
        id: get-agenda
        run: |
          echo 'AGENDA<<EOF' >> $GITHUB_ENV
          cat .github/templates/agenda.md >> $GITHUB_ENV
          echo 'EOF' >> $GITHUB_ENV
    
  4. Then I used the value in the next step with the notation ${{ env.AGENDA }}.

GitHub Discussions isn’t supported in the v3 API as far as I can see, so I used the v4 GraphQL API instead. You can see the full action in the repository if you’re interested.

One thought on “Use multi-line values in GitHub Actions

Leave a Reply

Please use [code] and [/code] around any source code you wish to share.

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