actions / github-script

Write workflows scripting the GitHub API in JavaScript
MIT License
4.24k stars 424 forks source link

Multi-line output showing unknown characters #460

Closed porottasambar closed 8 months ago

porottasambar commented 8 months ago

Describe the bug I'm trying to capture multiline output from a previous step's as the body in createComment. Somehow it is giving me some weird characters.

To Reproduce

   - name: policy
        id: policy
        if: github.event_name == 'pull_request' 
        run: |
          set +e
          CMD=$(polaris audit --audit-path build --set-exit-code-on-danger --set-exit-code-below-score 100 --format=pretty --only-show-failed-tests true 2>&1)
          exitcode="$?"
          echo 'POLICY<<EOF' >> $GITHUB_ENV
          echo "$CMD" >> $GITHUB_ENV
          echo 'EOF' >> $GITHUB_ENV
          exit $exitcode
        continue-on-error: true

     - uses: actions/github-script@v7
        env:
          MAIN: "POLICY\n${{ env.POLICY }}"
        if: github.event_name == 'pull_request' 
        with:
          result-encoding: string
          script: |
            const output = `#### Validation 🖌\`${{ steps.policy.outcome }}\`

            <details><summary>Show Plan</summary>
            \`\`\`
            ${process.env.MAIN}
            \`\`\`
            </details>

            *Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: output
            })

Output Screenshot 2024-03-14 at 12 24 30 PM

porottasambar commented 8 months ago

It seems like the issue is with polaris since I used the --color false option and now it looks fine.