Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

comment the file content to the PR#341

Unanswered
raghu-prasad-ttec asked this question inQ&A
Discussion options

The comment is showing as "$(cat sample.out)" instead of the actual file content. Below is the code for reference. Can someone what changes required to the "body: " in below code to get the required comment.

` - name: set file as an output variable
id: filestepid
run: |
echo 'FILE1_OUTPUT<<EOF' >> $GITHUB_OUTPUT
echo '$(cat sample.out)' >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT

  - name: Comment on PR    uses: actions/github-script@v6.4.0    with:      github-token: ${{secrets.GITHUB_TOKEN}}      script: |        github.rest.issues.createComment({          issue_number: context.issue.number,          owner: context.repo.owner,          repo: context.repo.repo,          body: '${{ steps.filestepid.outputs.FILE1_OUTPUT }}'        })`
You must be logged in to vote

Replies: 2 comments 8 replies

Comment options

👋 In Bash, single quotes will cause the value to be taken literally rather than evaluating that command in the$( ) block.

https://www.gnu.org/software/bash/manual/html_node/Single-Quotes.html

Try using" instead:

echo"$(cat sample.out)">>$GITHUB_OUTPUT

Alternatively, you could redirect the output ofcat directly:

cat sample.out>>$GITHUB_OUTPUT
You must be logged in to vote
0 replies
Comment options

@joshmgross I'm doing something similar

  - id: keploytestreport    name: Run Script    run:  |      ${GITHUB_ACTION_PATH}/install.sh > ${GITHUB_WORKSPACE}/${WORKDIR}/report.txt      grep "TESTRUN SUMMARY. For testrun with id: " ${GITHUB_WORKSPACE}/${WORKDIR}/report.txt > ${GITHUB_WORKSPACE}/${WORKDIR}/final.txt      grep "Total tests: " ${GITHUB_WORKSPACE}/${WORKDIR}/report.txt >> ${GITHUB_WORKSPACE}/${WORKDIR}/final.txt      grep "Total test passed: " ${GITHUB_WORKSPACE}/${WORKDIR}/report.txt >> ${GITHUB_WORKSPACE}/${WORKDIR}/final.txt      grep "Total test failed: " ${GITHUB_WORKSPACE}/${WORKDIR}/report.txt >> ${GITHUB_WORKSPACE}/${WORKDIR}/final.txt      echo 'KEPLOY_REPORT<<EOF' > $GITHUB_OUTPUT      cat ${GITHUB_WORKSPACE}/${WORKDIR}/final.txt >> $GITHUB_OUTPUT      echo 'EOF' >> $GITHUB_OUTPUT    shell: bash    env:      WORKDIR: ${{ inputs.working-directory }}      DELAY: ${{ inputs.delay }}      COMMAND : ${{ inputs.command }}      KEPLOY_PATH: ${{inputs.keploy-path}}  - name: Comment on PR    uses: actions/github-script@v6    with:      github-token: ${{ github.token }}      script: |        github.rest.issues.createComment({          issue_number: context.issue.number,          owner: context.repo.owner,          repo: context.repo.repo,          body: '${{ steps.keploytestreport.outputs.KEPLOY_REPORT }}'        })`

But i'm getting "Error: Unhandled error: SyntaxError: Invalid or unexpected token"

You must be logged in to vote
8 replies
@Sonichigo
Comment options

Thanks@joshmgross , it worked !!!

@johnrhunt
Comment options

This didn't work for me, the env var was just set to "steps.keploytestreport.outputs.KEPLOY_REPORT" so that's what I saw in the github comment (literally). What I needed to do was wrap it in ${{ }} - so:

- name: Comment on PR    uses: actions/github-script@v6    env:      KEPLOY_REPORT: ${{ steps.keploytestreport.outputs.KEPLOY_REPORT }}    with:      github-token: ${{ github.token }}      script: |        github.rest.issues.createComment({          issue_number: context.issue.number,          owner: context.repo.owner,          repo: context.repo.repo,          body: process.env.KEPLOY_REPORT        })

I hope that helps someone in the future. All the escaping complexities in GH workflows are baffling, I'm tempted to make a website just to cover all this lol

@joshmgross
Comment options

Thanks@johnrhunt for the correction, I updated my comment in case someone in the future decides to copy it without reading the full thread.

All the escaping complexities in GH workflows are baffling, I'm tempted to make a website just to cover all this

Let me know if there's anything I can do to help, agreed it can be pretty confusing at times.
If you have any feedback for our  existing docs, an issue inhttps://github.com/github/docs-content would be very appreciated.

@DGuhr
Comment options

I'm trying to achieve basically the same here, and after reading through many threads I got a comment with previous' step results, but the escaping complexities are real. Here's the createdcomment and my script looks like this:

- name: Run arch-go      id: arch-go-check      shell: bash      run: |        verbose_flag=$([ "${{ inputs.verbose }}" == "true" ] && echo "--verbose" || echo "" )        report_flag=$([ "${{ inputs.generate_report }}" == "true" ] && echo "--html" || echo "" )        arch-go ${verbose_flag} ${report_flag} 2>&1 | tee result.log        exit_code=${PIPESTATUS[0]}        archgo_result=$(cat result.log)        archgo_result="${archgo_result//'%'/'%25'}"        archgo_result="${archgo_result//$'\n'/'%0A'}"        archgo_result="${archgo_result//$'\r'/'%0D'}"        echo "checkresult=$archgo_result" >> $GITHUB_OUTPUT        exit $exit_code    - name: Upload report      if: inputs.generate_report == 'true'      uses: actions/upload-artifact@v4      with:        name: report.html        path: .arch-go/report.html    - name: Add PR comment      uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea #v7.0.1      env:        ARCHGO_RESULT: ${{steps.arch-go-check.outputs.checkresult}}      with:        script: |          const result = process.env.ARCHGO_RESULT;                    github.rest.issues.createComment({            issue_number: context.issue.number,            owner: context.repo.owner,            repo: context.repo.repo,            body: result           })

(source)

If I may ask, do you habe an idea why it doesn't escape right? (and also, why there's no multiline output?)

@DGuhr
Comment options

forget it, fixed it by using EOF :)

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
5 participants
@raghu-prasad-ttec@joshmgross@johnrhunt@Sonichigo@DGuhr

[8]ページ先頭

©2009-2025 Movatter.jp