When managing a GitHub Pull Request (PR) workflow, numerous continuous integration (CI) checks typically run to ensure code quality, functionality, and compliance with project standards. Keeping track of these checks and providing timely, consistent feedback to contributors can be challenging.
In this blog post, I’ll show how to enhance your PR process by adding automated comments using GitHub Actions. This technique can be invaluable for including outputs from CI checks, reporting their status, and highlighting any errors – ultimately making your development process smoother and more efficient.
Additional benefits of using GitHub Actions to add comments to your PRs
- Automated feedback: As mentioned initially, the automated feedback that is possible – results of CI checks, mentioning potential issues or errors
- Potential for enhanced collaboration: All CI check statuses in one area, rather than a collaborator having to move between various tabs
- Adding actionable instructions: Can provide specific instructions or reminders based on the changes made in the PR, ensuring that all necessary steps are taken for a successful merge or can even remind reviewers of pending pull requests after a certain period
- Triggering further actions: Automated comments can be part of a larger workflow. For example, commenting on a pull request can trigger notifications to specific team members, start additional automated processes, or integrate with other tools and services
- Efficiency and time saving: Reviewing pull requests and manually adding comments about CI status or other checks can be time-consuming. Automation comments frees up valuable time for reviewers, allowing them to focus on more critical aspects of the code review, such as logic, design, and implementation.
Setting up the GitHub Action
Adding comments to your PR as part of your workflow we will use action/github-script and GitHub Rest API
Configuring Job
In this example, I will be using 3 steps in my job:
- Checkout my code from GitHub repository
- Set an example variable, this is to showcase the potential of a script output
- Add a comment to GitHub PR with variable taken from above step
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set variable_example
run: echo "variable_example=thomasthornton.cloud" >> $GITHUB_ENV
- name: Add comment to PR
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.createComment({
owner: context.repo.owner,
issue_number: context.issue.number,
repo: context.repo.repo,
body: process.env.variable_example
})
Full GitHub Action Workflow
Taken above steps into the full workflow:
- Only runs on a pull request to
mainbranch
name: Add comment to PR example
on:
pull_request:
branches:
- main
jobs:
add-comment-to-pr:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set variable_example
run: echo "variable_example=thomasthornton.cloud" >> $GITHUB_ENV
- name: Add comment to PR
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.createComment({
owner: context.repo.owner,
issue_number: context.issue.number,
repo: context.repo.repo,
body: process.env.variable_example
})
Time to test
Running the above workflow successfully , it will add a comment thomasthornton.cloud to the pull request

Awesome! Can you think of a use case to add this within your GitHub Action workflows? 🙂
Finishing up
By implementing the steps outlined, you can streamline your workflow by automating the addition of comments to your pull requests. This not only enhances efficiency but also ensures consistent communication across your project. GitHub Actions offers a robust platform for customising and automating various aspects of your development process, with the capability to add comments to pull requests representing just one of the myriad ways to harness this tool’s potential.
GitHub Repository containing example workflow from this blog post