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

Action is not creating any comments on PR #250

Open
nilsfriess opened this issue Jun 11, 2024 · 3 comments
Open

Action is not creating any comments on PR #250

nilsfriess opened this issue Jun 11, 2024 · 3 comments

Comments

@nilsfriess
Copy link

I was trying to setup a Github action that runs when I open a PR and add a comment with the content /benchmark.
Here's my workflow file:

name: Benchmark test

on:
  issue_comment:
    types: [created, edited, deleted]

jobs:
  run-benchmark:
    if: contains(github.event.comment.html_url, '/pull/') && contains(github.event.comment.body, '/benchmark')
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4      
    - name: Run benchmark
      run: |
        python3 gen_random_result.py | tee ${GITHUB_WORKSPACE}/output.json
    - name: Download previous benchmark data
      uses: actions/cache@v4
      with:
        path: ./cache
        key: ${{ runner.os }}-benchmark

    - name: Store new result
      uses: benchmark-action/github-action-benchmark@v1
      with:
        tool: customSmallerIsBetter
        output-file-path: output.json
        external-data-json-path: ./cache/benchmark-data.json
        github-token: ${{ secrets.GITHUB_TOKEN }}
        summary-always: true
        comment-always: true

The gen_random_result.py script does exactly what its name says, it just generates some random data of the form

[
 {
    "name": "Test benchmark",
    "unit": "Seconds",
    "value": "0.4937825918725717"
 }
]

The action runs as expected but it doesn't generate a comment on the PR with the results.
Is there something I'm missing?

@nilsfriess
Copy link
Author

I think I found out what the problem is: Since I trigger the workflow on issue_comment, the "parent context" (don't know what to call it) is not a PR, so in this section here

return await (pr?.number
? leavePRComment(repoMetadata.owner.login, repoMetadata.name, pr.number, body, commentId, token)
: leaveCommitComment(repoMetadata.owner.login, repoMetadata.name, commitId, body, commentId, token));

the function leaveCommitComment will be called. Don't know how to fix it yet, but it shouldn't be too hard to get the parent PR from a comment.

WorldSEnder added a commit to WorldSEnder/yew that referenced this issue Aug 23, 2024
it's apparently not possible to also provide a PR number for the comment
to target, since that is automically determined by the action (and wrong
for workflow_run workflows)

See also: benchmark-action/github-action-benchmark#250
WorldSEnder added a commit to yewstack/yew that referenced this issue Aug 23, 2024
…3716)

* provide reference ref for benchmark action

it's apparently not possible to also provide a PR number for the comment
to target, since that is automically determined by the action (and wrong
for workflow_run workflows)

See also: benchmark-action/github-action-benchmark#250

* guard benchmark action with performance label again

This check was removed in #2774 for simplicity, bring it back to spam less
@WorldSEnder
Copy link

Over at yew, we also have a setup which currently only comments on the commits themselves, not the PR.

The benchmarking is run on pull_request in this workflow. Important for this discussion is that we then use the generated artifacts in a workflow_run dependent workflow. This avoids giving out permissions and running the benchmarking workflow in the context of the pull request itself, instead using the second benchmark from the main branch to perform the tasks of reacting to and posting the results.

We thus have a similar issue. While it's possible to guide benchmark-action/github-action-benchmark to the correct commit with the ref option, there is no way to guide it to the correct issue number (although we already recover that as part of the workflow).

@gaby
Copy link

gaby commented Sep 5, 2024

@nilsfriess You're missing permissions in your workflow:

permissions:
  # deployments permission to deploy GitHub pages website
  deployments: write
  # contents permission to update benchmark contents in gh-pages branch
  contents: write
  # allow posting comments to pull request
  pull-requests: write

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

No branches or pull requests

3 participants