Skip to content

Create Comment

Create Comment #8518

# This exists as a seperate workflow because pull_request workflows dont have permission to write comments
# How to use:
# 1. Add the name of the workflow that needs to leave a comment under on -> workflow_run -> workflows
# 2. In the main workflow always upload an artifact folder named comment_info
# 3. If a comment should be written then:
# 1. include issue_number.txt in the artifact folder containing the issue_number
# 2. include message.txt in the artifact folder containing the message of the comment
name: Create Comment
on:
workflow_run:
workflows: [ "Benchmarks" ]
# Cancel already running jobs
concurrency:
group: create_comment_${{ github.head_ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
upload:
runs-on: ubuntu-latest
if: >
${{ github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success' }}
steps:
- name: 'Download results'
uses: actions/download-artifact@v4
with:
name: 'comment-info'
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}
- run: unzip comment_info.zip
- name: 'Comment on PR'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
var fs = require('fs');
if (fs.existsSync('./issue_number.txt')) {
var issue_number = Number(fs.readFileSync('./issue_number.txt'));
var message = fs.readFileSync('./message.txt', 'utf8');
await github.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: message,
});
}