lighthouse-check-action: PR commenting not working for me (Help?)
My Github workflow looks like this:
name: Lighthouse Check
on:
deployment_status:
branches:
- '*'
jobs:
lighthouse-check:
runs-on: ubuntu-latest
if: github.event.deployment_status.state == 'success'
steps:
- uses: actions/checkout@master
- run: mkdir /tmp/artifacts
- name: Run Lighthouse
uses: foo-software/lighthouse-check-action@master
with:
accessToken: ${{ secrets.LIGHTHOUSE_CHECK_GITHUB_ACCESS_TOKEN }}
outputDirectory: /tmp/artifacts
urls: '${{ github.event.deployment_status.target_url }}'
- name: Upload artifacts
uses: actions/upload-artifact@master
with:
name: Lighthouse reports
path: /tmp/artifacts
Here I have added LIGHTHOUSE_CHECK_GITHUB_ACCESS_TOKEN
as my Github personal access token.
But for some reason, it is still not commenting the lighthouse results on any PRs.
Check this PR for example.
Also, can I use the secrets.GITHUB_TOKEN
(default that github provides with every repo) instead of secrets.LIGHTHOUSE_CHECK_GITHUB_ACCESS_TOKEN
?
PS: I have also asked this question to a wider audience on stackoverflow here.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 21
No problem @bhatvikrant - glad I could kinda help at least. I did some research and it seems like using a comment URL to be associated with commit is the only straightforward option (for now at least) when using the
deployment_status
event. The reason is that thedeployment_status
event doesn’t associate a PR. With that said, I’ll need to close this and hopefully the concluding thoughts below can help others.Conclusion
When using the
deployment_status
event to trigger a workflow, Lighthouse Check Action PR comments will not work out of the box because under the hood we construct usegithub.context.payload.pull_request.url
to post comments unless specified by the user.deployment_status
event doesn’t provide pull request data.Solution with Caveat
In order to enable comments, you would need to populate
commentUrl
, similar to our example, to comment on the associated commit. There is a caveat to this in that if you have an open PR, you will have a new comment with Lighthouse results for every commit, which can get noisy. This is different from using thepull_request
event, which by default only posts one comment and updates it for each new commit after.Possible Hacky Solutions for PR Comments
commentsUrl
with it.No problem - and thanks for reporting this one.
Oh shoot, midnight hours got me hallucinating that I couldn’t even see this blunder. Thank you once again @adamhenson.
Hey @bhatvikrant - but if you’re using a different repo than before then why do you still have
bhatvikrant/prep-station
as part of thecommentUrl
. Maybe you should just change it to this:Yep, okay looks like it will just keep creating new comments. So, this method will work, but your PR will get flooded.
If you were to do this on a PR triggered action, then only one comment would show and it would keep editing it.
I don’t know if there is a better solution at this time, but I’ll take some more time on it and get back to you.
So, it created a new commit
Great, no prob - I just want to see if the 2nd gets edited or if a new comment is created 🤞
Okay, awesome - looks like it worked @bhatvikrant
Can you do 2 more things.
In theory there should only be one comment that is edited when additional commits are pushed. I want to see if this works as expected.
Interestingly, that does seem to work!
Alrighty, I ve added that.
Thanks @bhatvikrant. Regarding the docs, that’s something we’ll have to do because it will require in-depth knowledge of this project. It’s on the roadmap though… we’ll get there.
Okay, well that’s interesting. I think this is a clever way of populating the URLs and I’m not so sure how we can get this to work.
I wonder if you do the following - it will show up on PRs 🤔 . Want to give it a shot?
Hi @bhatvikrant. Sorry for the troubles and thanks for providing all those details. Our documentation isn’t that great, especially on this subject. There are plans to improve. The intention of this feature was to comment on PRs, however I feel this may need to be revisited to be more robust.
My theory is that because you are not triggering this on
pull_request
it isn’t working correctly (even though you have a PR open). Unless you explicitly specifycommentUrl
, then this GitHub Action will usecontext.payload.pull_request.url
, which I’m guessing will be empty if not triggered by apull_request
. Your example is triggered bydeployment_status
.To test my theory, could you make this change? Yes, we’re hard-coding the PR, but this will at least isolate the issue (hopefully), and then we can brainstorm on next steps.