Handling multiline set-env when command errors out

I have the following step defined

      - name: Multiline Test
        id: multiline
        run: |
          echo 'MULTILINE_OUTPUT<<EOF' >> $GITHUB_ENV
          a-command-that-can-fail >> $GITHUB_ENV
          echo 'EOF' >> $GITHUB_ENV
        continue-on-error: true

In this case, a-command-that-can-fail may or may not throw an exit code. I’d like the workflow to continue executing and display the command error. However, it appears that if a-command-that-can-fail throws an exit code, the step stops executing the rest of the run. Therefore, echo 'EOF' >> $GITHUB_ENV never runs and I can not access the output.

Is there a recommended way to handle this?

Depending on the command, there might be a built-in option to disable the non-zero exit code, but as you are interested in this code, one of these options might do what you want:

Yea the tricky bit here is that I actually want the step to result in a failed status which I surface in a PR message. I ended up getting passed this by writing the output to a temporary file and reading it the next step.

     - name: Multiline Test
        id: multiline
        run: |
          a-command-that-can-fail > "$RUNNER_TEMP/output.txt"
        continue-on-error: true

Then I retrieved the contents in the next step with actions/github-script

            const tempDirectory = process.env['RUNNER_TEMP']

            const fs = require('fs').promises
            const planContents = await fs.readFile(`${tempDirectory}/output.txt`, {encoding: 'utf8'})