Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comment Job execution link as a comment to the PR #211

Open
leonardpahlke opened this issue Apr 30, 2022 · 7 comments
Open

Comment Job execution link as a comment to the PR #211

leonardpahlke opened this issue Apr 30, 2022 · 7 comments

Comments

@leonardpahlke
Copy link

Hi 👋

Great Action! Thanks :)

I integrated it to my workflow and it works great. I am trying to comment into the PR chat the link to the codecoverage website. Maybe this could be a nice addition for this too.

Code except

    - name: Send coverage
      id: send-coverage
      env:
        COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      run: |
        goveralls -coverprofile=covprofile -service=github > code_coverage_link
        coverage="$(cat code_coverage_link)"
        echo "::set-output name=coverage::$coverage"
     
    - name: Find Comment
      uses: peter-evans/find-comment@v2
      id: fc
      with:
        token: ${{secrets.GOVERNANCE_BOT_TOKEN}}
        issue-number: ${{ github.event.pull_request.number }}
        comment-author: 'carbonautMustache'
        body-includes: Code coverage link

    - name: Create or update comment
      uses: peter-evans/create-or-update-comment@v2
      with:
        token: ${{secrets.GOVERNANCE_BOT_TOKEN}}
        comment-id: ${{ steps.fc.outputs.comment-id }}
        issue-number: ${{ github.event.pull_request.number }}
        body: |
          Code coverage link: ${{ steps.send-coverage.outputs.coverage }}
        edit-mode: replace

I am unable to retrieve the link and only get this output: 'Code coverage link: Job #2250989753.1' no idea how to get the website link.. I looked into the API defenition but could find a way to http request it.

The link is printed to the action execution but I am unable to store it in a variable..

Any ideas? Thanks!

I am happy to document this in this repo's readme if that's interesting

Cheers Leo

@leonardpahlke
Copy link
Author

cc @mattn

@mattn
Copy link
Owner

mattn commented May 1, 2022

Interesting. Could you please send me PR to modify README ?

@shogo82148
Copy link
Collaborator

I recommend you to enable "Leave comments?" options on coveralls, instead of adding "Create or update comment" step.

e.g. the setting for https://github.com/shogo82148/actions-goveralls is available on https://coveralls.io/github/shogo82148/actions-goveralls/settings:

image

The example of coveralls' comments is here: shogo82148/actions-goveralls#352 (comment)

@leonardpahlke
Copy link
Author

Yes! I can create a "work in progress" / WIP PR but as I said it does not work quite yet..

I get Code coverage link: Job #2253645797.1 as a comment but it should be Code coverage link: https://coveralls.io/jobs/98738866
image

@shogo82148
Copy link
Collaborator

Or you want to do this in your GitHub Actions workflow, you should use 2> code_coverage_link instead of > code_coverage_link.

The "Send coverage" will be:

goveralls -coverprofile=covprofile -service=github 2> code_coverage_link
coverage="$(cat code_coverage_link)"
echo "::set-output name=coverage::$coverage"

@leonardpahlke
Copy link
Author

leonardpahlke commented May 1, 2022

Thanks for your help :) 2> does not solve the problem for me 🤔 .. The comment you posted before with the comment that gets posted, looks great and is actually is exactly what I like to achieve! Great that this is already implemented.

The settings on https://coveralls.io/github/<user/org>//settings are already configured. The comment does not appear tho. Do you know what could be missing?

Coveralls has granted access

@leonardpahlke
Copy link
Author

leonardpahlke commented May 1, 2022

okay I figured it out.. I will open a PR soon to update the README. The problem is that passing a multi line string through github action outputs is a bit weird,, (see article)

This version works for me now :)

    - name: Send coverage
      id: send-coverage
      env:
        COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      run: |
        CODE_COVERAGE_LINK=$(goveralls -coverprofile=covprofile -service=github)
        coverage=$(echo $CODE_COVERAGE_LINK)
        echo "::set-output name=coverage::$coverage"

    - name: Find Comment
      uses: peter-evans/find-comment@v2
      id: fc
      with:
        token: ${{secrets.GOVERNANCE_BOT_TOKEN}}
        issue-number: ${{ github.event.pull_request.number }}
        comment-author: 'carbonautMustache'
        body-includes: Code coverage link

    - name: Create or update comment
      uses: peter-evans/create-or-update-comment@v2
      with:
        token: ${{secrets.GOVERNANCE_BOT_TOKEN}}
        comment-id: ${{ steps.fc.outputs.comment-id }}
        issue-number: ${{ github.event.pull_request.number }}
        body: |
          Code coverage link: ${{ steps.send-coverage.outputs.coverage }}
        edit-mode: replace

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants