name: Create or Update Comment
on:
push:
branches:
- main
jobs:
comment:
runs-on: ubuntu-latest
steps:
- name: Setup repo
uses: actions/checkout@v3
- name: Create comment
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: 1
body: |
This is a multi-line test comment
- With GitHub **Markdown** ✨
- Created by [create-or-update-comment][1]
reactions: '+1'
- name: Update comment
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: 557858210
body: |
**Edit:** Some additional info
reactions: eyes
- name: Add reactions
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: 557858210
reactions: |
heart
hooray
laugh
Create or Update Comment
A GitHub Action to create or update an issue or pull request comment.
What is Create or Update Comment GitHub Action?
This GitHub Action allows you to automate the process of creating or updating comments in GitHub issues or pull requests. It also supports adding reactions and managing comments efficiently.
How to Create a Comment
To create a new comment in an issue or pull request, use the issue-number
and body
inputs.
with:
issue-number: 1
body: |
This is a multi-line test comment
- With GitHub **Markdown** ✨
How to Update a Comment
To update an existing comment, use the comment-id
input along with the new comment content.
with:
comment-id: 557858210
body: |
**Edit:** Some additional info
How to Add Comment Reactions
You can add reactions to an existing comment by providing the comment-id
and a list of reactions.
with:
comment-id: 557858210
reactions: |
heart
hooray
laugh
How to Configure Action Inputs
Token
A GITHUB_TOKEN
or a repo-scoped PAT is required for authentication to write comments or pull requests.
with:
token: ${{ secrets.GITHUB_TOKEN }}
Comment Body
To set the content of the comment, use the body
input.
with:
body: |
My comment text here.
Reaction List
To add reactions to a comment, use a comma or newline-separated list of reactions.
with:
reactions: |
heart
rocket
laugh
How to Work with Comment Outputs
You can capture the comment-id
of the created comment for further usage in later steps.
- name: Create comment
uses: peter-evans/create-or-update-comment@v4
id: couc
with:
issue-number: 1
body: |
My comment
- name: Check outputs
run: |
echo "Comment ID - ${{ steps.couc.outputs.comment-id }}"
How to Find a Comment ID
To find the ID of an existing comment, use the GitHub context during the issue_comment
event.
on:
issue_comment:
types: [created]
jobs:
commentCreated:
runs-on: ubuntu-latest
steps:
- name: Add reaction
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ github.event.comment.id }}
reactions: eyes
How to Search for Comments
The find-comment
action can search for comments by content or author and return the comment-id
.
- name: Find Comment
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Build output
- name: Create or update comment
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
Build output
${{ steps.build.outputs.build-log }}
edit-mode: replace
Monitoring GitHub Actions Workflows
CICube is a GitHub Actions monitoring tool that provides you with detailed insights into your workflows to further optimize your CI/CD pipeline. With CICube, you will be able to track your workflow runs, understand where the bottlenecks are, and tease out the best from your build times. Go to cicube.io now and create a free account to better optimize your GitHub Actions workflows!