0

I implemented a Javascript-based GitHub Action for converting a .yml file into a multiline string with the specific format. Unfortunately, I can't access the output of the action. I have already learned that handling multi-line output is problematic. Hence, my test workflow uses the workaround with a custom EOF. Nevertheless, the workflow fails because the output can't be saved to the GITHUB_ENV.

Some more details about the Javascript action:

For the following .yml file:

all:
  options:
    - "--private-key /home/runner/.ssh/key"

gather_info:
  options:
  # no extra options
run:
  options:
    - "--extra-vars workspace=${{ github.workspace }}"
    - "--extra-vars path=/home/${{ secrets.USER }}/jars"

The action shall output:

  <<all>>
  --private-key /home/runner/.ssh/key
  <<run>>
  --extra-vars workspace=${{ github.workspace }}
  --extra-vars path=/home/${{ secrets.USER }}/jars

The Javascript logic reads the .yml file, makes a conversion to a string, and sets the output, i.e.:

const outputString = convertYamlToString(file);
core.setOutput('output', outputString);

The test workflow where I try to extract the output and save it to GITHUB_ENV:

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: test
        id: test
        uses: ./
        with:
          file: test-file.yml

      - name: save multiline output in github env
        run: |
          EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
          echo "TEST_OUTPUT<<$EOF" >> "$GITHUB_ENV"
          ${{steps.test.outputs.output}} >> "$GITHUB_ENV"
          echo "$EOF" >> "$GITHUB_ENV"

      - name: print output
        run: echo "$TEST_OUTPUT"

When I run it, I receive the following error:

---- Step: 4_save multiline output in github env (failed) ----
##[group]Run EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "TEST_OUTPUT<<$EOF" >> "$GITHUB_ENV"

  <<all>>
  --private-key /home/runner/.ssh/key
  <<run>>
  --extra-vars workspace=${{ github.workspace }}
  --extra-vars path=/home/${{ secrets.USER }}
 >> "$GITHUB_ENV"
echo "$EOF" >> "$GITHUB_ENV"
shell: /usr/bin/bash -e {0}
##[endgroup]
/home/runner/work/_temp/123efec.sh: line 12: warning: here-document at line 4 delimited by end-of-file (wanted `all')
/home/runner/work/_temp/123efec.sh: line 12: syntax error near unexpected token `newline'
##[error]Process completed with exit code 2.
##[error]Unable to process file command 'env' successfully.
##[error]Invalid value. Matching delimiter not found 'kim4lpoGcJjcupO'
SkogensKonung
  • 601
  • 1
  • 9
  • 22

0 Answers0