Attach image to comment
Comment with image is a GitHub Action that takes a list of images, uploads them to an Image Upload Service and comments the screenshots on the pull request that triggered the action.
It was adapted from https://github.com/saadmk11/comment-webpage-screenshot, mostly to strip down the screenshot feature.
Note: This Action Only Works on Pull Requests.
Example Workflow
name: Comment Webpage Screenshot
on:
pull_request:
types: [opened, reopened, synchronize]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Some step that generates image.png and actions.gif under ./artifacts
run: ...
- name: Comment Webpage Screenshot
uses: opengisch/comment-pr-with-images@upload_only
with:
# required: Comma seperated list of files to upload.
images: "tests_artifacts/**/*.gif, tests_artifacts/**/*.png"
# optional: The action will create a new branch and
# upload the screenshots to that branch.
upload_to: github_branch # Or, imgur
# optional (defaults to the text used in this example): The message to use in the comment
custom_attachment_msg: "Screenshot for commit..."
# optional (defaults to `true`): Whether the previous comment should be edited with
# a deprecation warning along with a reference to the last comment
edit_previous_comment: true
# optional: If not defined, the token autogenerated
# by the running action will be used
github_token: {{ secrets.MY_GITHUB_TOKEN }}
Available Image Upload Services
As GitHub Does not allow us to upload images to a comment using the API we need to rely on other services to host the screenshots.
These are the currently available image upload services.
Imgur
If the value of upload_to
input is imgur
then the screenshots will be uploaded to Imgur.
Keep in mind that the uploaded screenshots will be public and anyone can see them.
Imgur also has a rate limit of how many images can be uploaded per hour.
Refer to Imgur's Rate Limits Docs for more details.
This is suitable for small open source repositories.
Please refer to Imgur terms of service here
GitHub Branch (Default)
If the value of upload_to
input is github_branch
then the screenshots will be pushed
to a GitHub branch created by the action on your repository.
The screenshots on the comments will reference the Images pushed to this branch.
This is suitable for open source and private repositories.
If you want to add/use a different image upload service, feel free create a new issue/pull request.
License
The code in this project is released under the GNU GENERAL PUBLIC LICENSE Version 3.