jacoco-report icon indicating copy to clipboard operation
jacoco-report copied to clipboard

No Pull Request comment added on push

Open MichaelJHaywood opened this issue 1 year ago • 6 comments

I've been having trouble trying to get the plugin to add a comment to the PR. I've enabled debug-mode and it successfully finds the Jacoco xml file. It outputs messages about the changes but doesn't mention trying to add a comment. The action is successful.

- name: Publish code coverage results
  id: jacoco
  uses: madrapps/[email protected]
  with:
    paths: |
      jacoco/jacocoTestReport.xml
    token: ${{ github.token }}
    min-coverage-overall: 40
    min-coverage-changed-files: 60
    title: Code Coverage
    update-comment: true
    debug-mode: true
    continue-on-error: false

Logs

Run madrapps/[email protected]
Event is push
passEmoji: :green_apple:
failEmoji: :x:
base sha: ...
head sha: ...
reportPaths: jacoco/jacocoTestReport.xml
Resolved files: ...
file: {
...
]
project: {
...
}
skip: false
prNumber: undefined

I can successfully add comments myself using a separate github action so I don't believe this is permission related.

Adds a comment successfully

- name: PR Comment Test
  uses: mshick/add-pr-comment@v2
  with:
    message: |
      **Test**

Am I using this incorrectly? Should it fail if it doesn't add a comment?

MichaelJHaywood avatar Aug 07 '23 09:08 MichaelJHaywood

The problem seems to be here:

action.ts

if (prNumber != null && !skip) {

If the prNumber is undefined we don't add a comment. In the case of a "push" there is no prNumber set.

I've managed to get this working by getting the PR number associated with the commit.

case 'push':
  base = github.context.payload.before
  head = github.context.payload.after

  const prs: any[] = (await client.rest.repos.listPullRequestsAssociatedWithCommit({
    commit_sha: github.context.sha,
    owner: github.context.repo.owner,
    repo: github.context.repo.repo,
  })).data

  if(prs.length > 0){
     prNumber = prs[0].number
  }

  break

Overall this means pushing changes will not update the code coverage comment without this change (or similar).

MichaelJHaywood avatar Aug 09 '23 07:08 MichaelJHaywood

@thsaravana Can you reopen issue and apply this fix on master branch?

patrykosak avatar Dec 15 '23 13:12 patrykosak

I am already making some changes in 1.7 in this area. So I will test this as well and will fix this in 1.7 properly.

thsaravana avatar Dec 26 '23 08:12 thsaravana

isn't the workaround also to trigger the workflow not on push event, but on pull_request opened / reopened / synchronize ? I think a push in a branch for which there's a PR always generates a synchronize. and you would not want the action to run on a push if there's no PR associated to the branch, right ?

vincent-fuchs avatar Jan 12 '24 03:01 vincent-fuchs

isn't the workaround also to trigger the workflow not on push event, but on pull_request opened / reopened / synchronize ? I think a push in a branch for which there's a PR always generates a synchronize. and you would not want the action to run on a push if there's no PR associated to the branch, right ?

The problem with that is that you always want to build and test on push, at least in main. Adding a comment to an associated PR is an optional addition. I wouldn't want to rebuild/retest everything just for the coverage comment.

guus-bloemsma avatar Jan 19 '24 15:01 guus-bloemsma

Is there still any progress on this?

sheepdreamofandroids avatar May 02 '24 06:05 sheepdreamofandroids

Same problem here, my workflows are triggered by push and I don't want to have to re-build everything in a workflow with a pull_request trigger. Would it be possible to either allow a PR number as an input or to try to get the PR number on push workflows too? It should be possible

jameshreaver avatar Aug 21 '24 14:08 jameshreaver

Same issue as @jameshreaver here. Would be good to see this fixed in the next release

choweiyuan avatar Sep 12 '24 10:09 choweiyuan

We will release this in v1.7.2.

  • There will now be an input field pr-number where we can input "any" Pull Request number and the Comment will be added to that, eg. here
  • If pr-number is not provided, then we will figure out the PR Number from the environment. For pull_request event this happens already, and for push event (and more events we are planning to add like workflow_run) this will be calculated from the commit_sha. eg. here

PS: In addition to this, we have also added "Workflow Summary", so for "push" to main branch, you don't really need to go to the associated PR to get the coverage report, but can get the same information in the action workflow summary. eg. here

All of this will be released in the next one: v1.7.2

thsaravana avatar Sep 18 '24 19:09 thsaravana

This is now available in v1.7.2-alpha. We will release v1.7.2 in the coming weeks.

thsaravana avatar Sep 19 '24 17:09 thsaravana