Skip to content

PR Comment Bot

PR Comment Bot #26788

name: PR Comment Bot
on:
workflow_run:
workflows: [PR Build]
jobs:
pr-comment-bot:
name: PR Comment Bot
runs-on: ubuntu-latest
steps:
- name: Check For Artifacts
id: check-for-artifacts
uses: actions/github-script@v6
with:
script: |
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: '${{github.repository_owner}}',
repo: '${{ github.event.repository.name }}',
run_id: '${{github.event.workflow_run.id}}',
});
const hasDocs = !!artifacts.data.artifacts.find(artifact => artifact.name === 'docs');
const hasWebsite = !!artifacts.data.artifacts.find(artifact => artifact.name === 'website');
core.setOutput('has_docs', hasDocs);
core.setOutput('has_website', hasWebsite);
- name: Get PR Event
id: get-pr-event
uses: potiuk/get-workflow-origin@v1_5
with:
token: ${{secrets.GITHUB_TOKEN}}
sourceRunId: ${{github.event.workflow_run.id}}
- name: Find Comment
id: find-comment
uses: peter-evans/find-comment@v2
with:
issue-number: ${{steps.get-pr-event.outputs.pullRequestNumber}}
comment-author: 'github-actions[bot]'
body-includes: 🤖 Clarity Release Bot
- name: Build Started PR Comment
if: ${{github.event.action == 'requested'}}
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{steps.find-comment.outputs.comment-id}}
issue-number: ${{steps.get-pr-event.outputs.pullRequestNumber}}
body: |
👋 @${{github.event.sender.login}},
* 🙏 The Clarity team thanks you for opening a pull request
* ⏳ The build for this PR has started
* 🍿 In the meantime, explore it in [StackBlitz](https://stackblitz.com/~/github.com/${{github.repository}}/pull/${{steps.get-pr-event.outputs.pullRequestNumber}})
* 📫 I'll update this comment when the build has finished
Thank you,
🤖 Clarity Release Bot
edit-mode: replace
- name: Build Succeeded PR Comment
if: ${{github.event.workflow_run.conclusion == 'success'}}
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{steps.find-comment.outputs.comment-id}}
issue-number: ${{steps.get-pr-event.outputs.pullRequestNumber}}
body: |
👋 @${{github.event.sender.login}},
* 🙏 The Clarity team thanks you for opening a pull request
* 🎉 The build for this PR has succeeded
* 🔍 The PR is now ready for review
* 🍿 Preview: [Storybook](https://${{steps.get-pr-event.outputs.pullRequestNumber}}--${{secrets.NETLIFY_SITE_NAME}}.netlify.app) | [Website](https://${{steps.get-pr-event.outputs.pullRequestNumber}}--${{secrets.NETLIFY_WEBSITE_SITE_NAME}}.netlify.app) | [StackBlitz](https://stackblitz.com/~/github.com/${{github.repository}}/pull/${{steps.get-pr-event.outputs.pullRequestNumber}})
Thank you,
🤖 Clarity Release Bot
edit-mode: replace
- name: Build Failed with Artifacts PR Comment
if: ${{github.event.workflow_run.conclusion == 'failure' && (steps.check-for-artifacts.outputs.has_docs == 'true' || steps.check-for-artifacts.outputs.has_website == 'true')}}
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{steps.find-comment.outputs.comment-id}}
issue-number: ${{steps.get-pr-event.outputs.pullRequestNumber}}
body: |
👋 @${{github.event.sender.login}},
* 😭 The build for this PR has failed
* 🗒 Please check out the [build log](${{github.event.workflow_run.html_url}})
* 🍿 Although the build failed, you can still view a preview: [Storybook](https://${{steps.get-pr-event.outputs.pullRequestNumber}}--${{secrets.NETLIFY_SITE_NAME}}.netlify.app) | [Website](https://${{steps.get-pr-event.outputs.pullRequestNumber}}--${{secrets.NETLIFY_WEBSITE_SITE_NAME}}.netlify.app) | [StackBlitz](https://stackblitz.com/~/github.com/${{github.repository}}/pull/${{steps.get-pr-event.outputs.pullRequestNumber}})
Thank you,
🤖 Clarity Release Bot
edit-mode: replace
- name: Build Failed without Artifacts PR Comment
if: ${{github.event.workflow_run.conclusion == 'failure' && steps.check-for-artifacts.outputs.has_docs != 'true' && steps.check-for-artifacts.outputs.has_website != 'true'}}
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{steps.find-comment.outputs.comment-id}}
issue-number: ${{steps.get-pr-event.outputs.pullRequestNumber}}
body: |
👋 @${{github.event.sender.login}},
* 😭 The build for this PR has failed
* 🗒 Please check the [build log](${{github.event.workflow_run.html_url}})
* 🍿 In the meantime, explore it in [StackBlitz](https://stackblitz.com/~/github.com/${{github.repository}}/pull/${{steps.get-pr-event.outputs.pullRequestNumber}})
Thank you,
🤖 Clarity Release Bot
edit-mode: replace